Skip to content

Commit 00862b9

Browse files
authored
Label support (#8)
* add kubectl * Add label filters * fix wait condition
1 parent 7ea41b2 commit 00862b9

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
Example application for Codefresh CI/CD demonstrations.
44

55
Contact <hello@cloudposse.com>
6+

codefresh/destroy.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ stages:
55

66
steps:
77
main_clone:
8-
type: pending-approval
9-
title: Destory staging environment?
8+
title: Wait
9+
stage: Destroy
10+
image: codefresh/cli:latest
11+
commands:
12+
- 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'
13+
retry:
14+
maxAttempts: 10
15+
delay: 20
16+
exponentialFactor: 1.1
17+
when:
18+
condition:
19+
any:
20+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
21+
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"
1022

1123
destroy:
1224
title: Destroy namespace
@@ -16,11 +28,13 @@ steps:
1628
environment:
1729
- NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
1830
commands:
31+
- "apk add kubectl"
1932
- "kubectl config use-context ${{KUBE_CONTEXT}}"
2033
- "make helm/delete/namespace"
2134
- "make helm/delete/namespace/empty"
2235
when:
23-
steps:
24-
- name: main_clone
25-
on:
26-
- approved
36+
condition:
37+
any:
38+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
39+
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"
40+

codefresh/pull-request.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ steps:
9898
when:
9999
condition:
100100
all:
101+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
101102
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
102103

103104
push_image_commit:
@@ -108,6 +109,21 @@ steps:
108109
tags:
109110
- "${{CF_REVISION}}"
110111

112+
wait:
113+
title: Wait
114+
stage: Deploy
115+
image: codefresh/cli:latest
116+
commands:
117+
- 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'
118+
retry:
119+
maxAttempts: 10
120+
delay: 20
121+
exponentialFactor: 1.1
122+
when:
123+
condition:
124+
any:
125+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
126+
111127
deploy_helmfile:
112128
title: Deploy with helmfile
113129
stage: Deploy
@@ -118,6 +134,10 @@ steps:
118134
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
119135
# Deploy chart to cluster in a dedicated namespace
120136
- "/deploy/ctl --namespace=${{NAMESPACE}} rolling"
137+
when:
138+
condition:
139+
any:
140+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
121141

122142
set_github_deployment_status_to_success:
123143
title: Set GitHub deployment status to "success"
@@ -136,6 +156,7 @@ steps:
136156
when:
137157
condition:
138158
all:
159+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
139160
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
140161

141162
send_slack_notification:
@@ -151,4 +172,8 @@ steps:
151172
- GIT_BRANCH_TAG=${{CF_BRANCH_TAG_NORMALIZED}}
152173
commands:
153174
- make codefresh/notify/slack/deploy/webapp GIT_COMMIT_TIMESTAMP=$((${{CF_BUILD_TIMESTAMP}}/1000))
175+
when:
176+
condition:
177+
any:
178+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
154179

0 commit comments

Comments
 (0)