diff --git a/README.md b/README.md index 6bea3b9..21c636f 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,4 @@ Example application for Codefresh CI/CD demonstrations. Contact + diff --git a/codefresh/destroy.yaml b/codefresh/destroy.yaml index 532f008..ce6d558 100644 --- a/codefresh/destroy.yaml +++ b/codefresh/destroy.yaml @@ -5,8 +5,20 @@ stages: steps: main_clone: - type: pending-approval - title: Destory staging environment? + title: Wait + stage: Destroy + image: codefresh/cli:latest + commands: + - codefresh get builds --pipeline=destroy --pipeline=pull-request --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id' + retry: + maxAttempts: 10 + delay: 20 + exponentialFactor: 1.1 + when: + condition: + any: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false" + validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'" destroy: title: Destroy namespace @@ -16,11 +28,13 @@ steps: environment: - NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}} commands: + - "apk add kubectl" - "kubectl config use-context ${{KUBE_CONTEXT}}" - "make helm/delete/namespace" - "make helm/delete/namespace/empty" when: - steps: - - name: main_clone - on: - - approved \ No newline at end of file + condition: + any: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false" + validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'" + diff --git a/codefresh/pull-request.yaml b/codefresh/pull-request.yaml index dd3f1a6..080d1f9 100644 --- a/codefresh/pull-request.yaml +++ b/codefresh/pull-request.yaml @@ -98,6 +98,7 @@ steps: when: condition: all: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true" githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'" push_image_commit: @@ -108,6 +109,21 @@ steps: tags: - "${{CF_REVISION}}" + wait: + title: Wait + stage: Deploy + image: codefresh/cli:latest + commands: + - codefresh get builds --pipeline=destroy --pipeline=pull-request --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id' + retry: + maxAttempts: 10 + delay: 20 + exponentialFactor: 1.1 + when: + condition: + any: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true" + deploy_helmfile: title: Deploy with helmfile stage: Deploy @@ -118,6 +134,10 @@ steps: - "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'" # Deploy chart to cluster in a dedicated namespace - "/deploy/ctl --namespace=${{NAMESPACE}} rolling" + when: + condition: + any: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true" set_github_deployment_status_to_success: title: Set GitHub deployment status to "success" @@ -136,6 +156,7 @@ steps: when: condition: all: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true" githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'" send_slack_notification: @@ -151,4 +172,8 @@ steps: - GIT_BRANCH_TAG=${{CF_BRANCH_TAG_NORMALIZED}} commands: - make codefresh/notify/slack/deploy/webapp GIT_COMMIT_TIMESTAMP=$((${{CF_BUILD_TIMESTAMP}}/1000)) + when: + condition: + any: + deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"