From 9cd8d9024cd8204bd562b7b88078bb2b9aff33d2 Mon Sep 17 00:00:00 2001 From: Jane Alesi Date: Sat, 21 Jun 2025 19:03:13 +0200 Subject: [PATCH] Add automated preview deployment configuration Optional automated deployment job for preview environments. Requires SSH access to satware.ai server for direct deployment. --- deploy-preview-automated.yml | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 deploy-preview-automated.yml diff --git a/deploy-preview-automated.yml b/deploy-preview-automated.yml new file mode 100644 index 0000000..ed6023c --- /dev/null +++ b/deploy-preview-automated.yml @@ -0,0 +1,65 @@ +# ๐Ÿš€ Automated Preview Deployment (Optional) +# Add this job to your .gitlab-ci.yml if you want automated preview deployment + +deploy_preview_automated: + stage: deploy + image: alpine:latest + rules: + - if: $CI_COMMIT_REF_NAME =~ /^(feature|fix|blog|test|preview)\/.*/ + before_script: + # Install SSH and rsync + - apk add --no-cache openssh-client rsync + + # Setup SSH key + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan -H $DEPLOY_SERVER >> ~/.ssh/known_hosts + + script: + # Extract clean branch name + - BRANCH_PATH=$(echo "${CI_COMMIT_REF_NAME}" | sed 's|feature/||g' | sed 's|fix/||g' | sed 's|blog/||g' | sed 's|[^a-zA-Z0-9-]|-|g' | tr '[:upper:]' '[:lower:]') + - PREVIEW_URL="${PREVIEW_BASE_URL}/${BRANCH_PATH}/" + + # Deploy to server + - echo "๐Ÿš€ Deploying preview to ${DEPLOY_SERVER}:${DEPLOY_PATH}/${BRANCH_PATH}/" + - rsync -avz --delete site/ ${DEPLOY_USER}@${DEPLOY_SERVER}:${DEPLOY_PATH}/${BRANCH_PATH}/ + + # Verify deployment + - echo "โœ… Preview deployed successfully!" + - echo "๐Ÿ“ URL: ${PREVIEW_URL}" + + # Optional: Send notification + - | + curl -X POST -H 'Content-type: application/json' \ + --data "{\"text\":\"๐Ÿ” Preview deployed: ${PREVIEW_URL}\"}" \ + "$SLACK_WEBHOOK_URL" || true + + environment: + name: preview/${CI_COMMIT_REF_SLUG} + url: ${PREVIEW_BASE_URL}/${BRANCH_PATH}/ + on_stop: cleanup_preview_automated + +# ๐Ÿงน Automated Preview Cleanup +cleanup_preview_automated: + stage: cleanup + image: alpine:latest + rules: + - if: $CI_COMMIT_REF_NAME =~ /^(feature|fix|blog|test|preview)\/.*/ + when: manual + before_script: + - apk add --no-cache openssh-client + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan -H $DEPLOY_SERVER >> ~/.ssh/known_hosts + script: + - BRANCH_PATH=$(echo "${CI_COMMIT_REF_NAME}" | sed 's|feature/||g' | sed 's|fix/||g' | sed 's|blog/||g' | sed 's|[^a-zA-Z0-9-]|-|g' | tr '[:upper:]' '[:lower:]') + - echo "๐Ÿงน Cleaning up preview: ${DEPLOY_PATH}/${BRANCH_PATH}/" + - ssh ${DEPLOY_USER}@${DEPLOY_SERVER} "rm -rf ${DEPLOY_PATH}/${BRANCH_PATH}/" + - echo "โœ… Preview cleanup completed" + environment: + name: preview/${CI_COMMIT_REF_SLUG} + action: stop \ No newline at end of file