Skip to content

Commit 41d2e9b

Browse files
authored
Update to Latest Monochart (#10)
* comment out unused features * push to dockerhub * use helm2 * use helm3 * push to dockerhub * use dockerhub * fix typo * deprecate deploy ctl * deprecate deploy ctl * fix yaml * add missing quote * set default color * fix annotation * upgrade monochart * set to real color * Deploy t staging sequentially * rename pull-request to preview * rename pull-request to preview * downgrade helm * downgrade helm * fix command * change format * comment like crazy * update context * update descriptions * wording * fix timestamp * fix date time * clean up format * wording * remove $ * remove quotes * add destroy action * remove quotes * format time * restore + * fix timestamp * positive reward * repo pinning * use helmfile to destroy * Release pipeline * Add deployment pipelines * fix yaml * fix env * fix push * braces * do not detach * fix pipeline * add chart name * fix pipeline * deploy pipeline fixes * Set release name * fix working directory * create namespace and use iamge for destroy * cannot create namespace with helm 3.1.3 * destroy tweaks * pass more args * set color for destroy * fix deployment notificaiton * git commit message
1 parent ee01d0e commit 41d2e9b

File tree

12 files changed

+176
-166
lines changed

12 files changed

+176
-166
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:alpine3.8 AS builder
1+
FROM golang:alpine3.11 AS builder
22

33
# Copy source into builder
44
ADD . /src
@@ -8,12 +8,11 @@ RUN cd /src && \
88
go build -o example-app
99

1010
# Build the final image
11-
FROM alpine:3.8 as final
11+
FROM alpine:3.11 as final
1212

1313
# Install the cloudposse alpine repository
1414
ADD https://apk.cloudposse.com/ops@cloudposse.com.rsa.pub /etc/apk/keys/
15-
RUN echo "@cloudposse https://apk.cloudposse.com/3.8/vendor" >> /etc/apk/repositories
16-
RUN apk add --update bash variant@cloudposse
15+
RUN echo "@cloudposse https://apk.cloudposse.com/3.11/vendor" >> /etc/apk/repositories
1716

1817
# Expose port of the app
1918
EXPOSE 8080

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Example application for Codefresh CI/CD demonstrations.
66

77
### Codefresh Pipelines
88

9-
1. Unlimited Staging Pipelines (pull-request, destroy)
9+
1. Unlimited Staging Pipelines (preview, destroy)
1010
2. Release Pipeline
1111
3. Deploy Pipeline
1212

codefresh/build.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ stages:
44
- Prepare
55
- Build
66
- Push
7+
- Deploy
78

89
steps:
910
main_clone:
@@ -20,13 +21,27 @@ steps:
2021
stage: Build
2122
type: build
2223
description: Build image
23-
image_name: ${{CF_REPO_NAME}}
24+
image_name: ${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
2425
dockerfile: Dockerfile
2526

2627
push_image_commit:
2728
title: Push image with commit tag
2829
stage: Push
2930
type: push
3031
candidate: ${{build_image}}
32+
registry: dockerhub
3133
tags:
32-
- "${{CF_REVISION}}"
34+
- "${{CF_REVISION}}"
35+
36+
deploy_master:
37+
title: Deploying to Master
38+
stage: "Deploy"
39+
image: 'codefresh/cli:latest'
40+
environment:
41+
STAGE: master
42+
commands:
43+
- codefresh run ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/deploy-${{STAGE}} -d -b=${{CF_BRANCH}} -v CF_RELEASE_TAG=${{CF_REVISION}} -v CF_PRERELEASE_FLAG=${{CF_PRERELEASE_FLAG}} -v STAGE=${{STAGE}}
44+
when:
45+
branch:
46+
only:
47+
- master

codefresh/deploy.yaml

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ steps:
1313
- cf_export NAMESPACE=${{STAGE}}
1414
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
1515
- cf_export IMAGE_TAG=${{CF_RELEASE_TAG}}
16-
- cf_export GATEWAY_HOST=example.${{BASE_HOST}}
17-
18-
ask_for_permission:
19-
type: pending-approval
20-
title: Deploy release?
21-
stage: Prepare
16+
- cf_export APP_SCHEME=http
17+
- cf_export APP_HOST=${{STAGE}}.${{CF_REPO_NAME}}.${{BASE_HOST}}
18+
- cf_export COLOR=blue
19+
- cf_export CF_BUILD_DATE_TIME=$(date +"%Y-%m-%d/%H:%M:%S" -d @$((${{CF_BUILD_TIMESTAMP}}/1000)))
2220

2321
wait:
2422
title: Wait
@@ -34,18 +32,17 @@ steps:
3432
deploy_helmfile:
3533
title: "Deploy with helmfile"
3634
stage: "Deploy"
37-
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
35+
image: "${{IMAGE_NAME}}:${{IMAGE_TAG}}"
3836
working_directory: /deploy/
37+
environment:
38+
- RELEASE_NAME=${{CF_REPO_NAME}}
3939
commands:
4040
# Announce the release version
41-
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
42-
# Deploy chart to cluster
43-
- "/deploy/ctl --namespace=${{NAMESPACE}} blue-green"
44-
when:
45-
steps:
46-
- name: ask_for_permission
47-
on:
48-
- approved
41+
- "echo 'Preparing to deploy ${{IMAGE_NAME}}:${{IMAGE_TAG}}'"
42+
- "apk add --update curl make bash git kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
43+
- "kubectl config use-context ${{KUBE_CONTEXT}}"
44+
# Deploy chart to cluster in a dedicated namespace
45+
- "helmfile --namespace ${{NAMESPACE}} --selector preview=true sync"
4946

5047
send_slack_notification:
5148
title: Send notification to Slack channel
@@ -54,6 +51,38 @@ steps:
5451
working_directory: /build-harness
5552
environment:
5653
- PIPELINE_ENV=${{STAGE}}
54+
- CHART_NAME=monochart
55+
- GIT_COMMIT_SHORT=${{CF_SHORT_REVISION}}
56+
- GIT_COMMIT_URL=${{CF_COMMIT_URL}}
57+
- GIT_COMMIT_MESSAGE=${{CF_COMMIT_MESSAGE}}
58+
- GIT_COMMIT_AUTHOR=${{CF_COMMIT_AUTHOR}}
59+
- GIT_BRANCH_TAG=${{CF_BRANCH_TAG_NORMALIZED}}
5760
commands:
58-
- make codefresh/notify/slack/deploy/webapp
61+
- make codefresh/notify/slack/deploy/webapp GIT_COMMIT_TIMESTAMP=$((${{CF_BUILD_TIMESTAMP}}/1000))
62+
63+
set_github_deployment_status_to_success:
64+
title: Set GitHub deployment status to "success"
65+
stage: Deploy
66+
image: cloudposse/github-status-updater
67+
environment:
68+
- GITHUB_ACTION=update_state
69+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
70+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
71+
- GITHUB_REPO=${{CF_REPO_NAME}}
72+
- GITHUB_REF=${{CF_REVISION}}
73+
- GITHUB_CONTEXT=${{STAGE}}/env
74+
- GITHUB_STATE=success
75+
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} by @${{CF_BUILD_INITIATOR}}
76+
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}/dashboard
5977

78+
add_url_to_comment_on_commit:
79+
title: Comment on commit with the deployed URL
80+
stage: Deploy
81+
image: cloudposse/github-commenter
82+
environment:
83+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
84+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
85+
- GITHUB_REPO=${{CF_REPO_NAME}}
86+
- GITHUB_COMMENT_TYPE=commit
87+
- GITHUB_COMMIT_SHA=${{CF_SHORT_REVISION}}
88+
- 'GITHUB_COMMENT=Version ${{CF_SHORT_REVISION}} deployed by @${{CF_BUILD_INITIATOR}} to the [`${{NAMESPACE}}`](${{APP_SCHEME}}://${{APP_HOST}}/dashboard) namespace on `${{STAGE}}` at ${{CF_BUILD_DATE_TIME}}'

codefresh/destroy.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ steps:
99
stage: Destroy
1010
image: codefresh/cli:latest
1111
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'
12+
- codefresh get builds --pipeline=destroy --pipeline=preview --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
1313
retry:
1414
maxAttempts: 10
1515
delay: 20
@@ -21,20 +21,40 @@ steps:
2121
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"
2222

2323
destroy:
24-
title: Destroy namespace
24+
title: Destroy Preview Environment
2525
stage: Destroy
26-
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
27-
working_directory: /build-harness/
26+
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
27+
working_directory: /deploy/
2828
environment:
2929
- NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
30+
- RELEASE_NAME=${{CF_REPO_NAME}}
31+
- COLOR=blue
3032
commands:
31-
- "apk add kubectl"
33+
- "apk add kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
3234
- "kubectl config use-context ${{KUBE_CONTEXT}}"
33-
- "make helm/delete/namespace"
34-
- "make helm/delete/namespace/empty"
35+
- "helmfile --namespace ${NAMESPACE} --selector preview=true destroy"
3536
when:
3637
condition:
3738
any:
3839
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
3940
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"
4041

42+
set_github_destroy_status_to_success:
43+
title: Set GitHub destroy status to "success"
44+
stage: Destroy
45+
image: cloudposse/github-status-updater
46+
environment:
47+
- GITHUB_ACTION=update_state
48+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
49+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
50+
- GITHUB_REPO=${{CF_REPO_NAME}}
51+
- GITHUB_REF=${{CF_REVISION}}
52+
- GITHUB_CONTEXT=preview/env
53+
- GITHUB_STATE=success
54+
- GITHUB_DESCRIPTION=Destroyed by @${{CF_BUILD_INITIATOR}}
55+
- GITHUB_TARGET_URL=${{CF_BUILD_URL}}
56+
when:
57+
condition:
58+
any:
59+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
60+
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"

codefresh/pull-request.yaml renamed to codefresh/preview.yaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ steps:
2121
stage: Prepare
2222
image: alpine
2323
commands:
24+
- cf_export COLOR=blue
25+
- cf_export STAGE=preview
2426
- cf_export GIT_BRANCH=${{CF_BRANCH}}
2527
- cf_export PROJECT=${{CF_REPO_NAME}}
2628
- cf_export APP_NAME=${{CF_REPO_NAME}}
2729
- cf_export CHART_NAME=monochart
2830
- cf_export PIPELINE_ENV=integration
2931
- cf_export NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
30-
- cf_export RELEASE_NAME=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
32+
- cf_export RELEASE_NAME=${{CF_REPO_NAME}}
33+
- cf_export APP_SCHEME=http
3134
- cf_export APP_HOST=pr-${{CF_PULL_REQUEST_NUMBER}}.${{CF_REPO_NAME}}.${{BASE_HOST}}
3235
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
3336
- cf_export IMAGE_TAG=${{CF_REVISION}}
37+
- cf_export CF_BUILD_DATE_TIME=$(date +"%Y-%m-%d/%H:%M:%S" -d @$((${{CF_BUILD_TIMESTAMP}}/1000)))
3438

3539
build:
3640
type: parallel
@@ -40,7 +44,7 @@ steps:
4044
title: Build image
4145
type: build
4246
description: Build app
43-
image_name: ${{CF_REPO_NAME}}
47+
image_name: ${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
4448
tag: ${{CF_SHORT_REVISION}}
4549
dockerfile: Dockerfile
4650
no_cache: false
@@ -91,10 +95,10 @@ steps:
9195
- GITHUB_OWNER=${{CF_REPO_OWNER}}
9296
- GITHUB_REPO=${{CF_REPO_NAME}}
9397
- GITHUB_REF=${{CF_REVISION}}
94-
- GITHUB_CONTEXT=Staging Environment
98+
- GITHUB_CONTEXT=${{STAGE}}/env
9599
- GITHUB_STATE=pending
96100
- GITHUB_DESCRIPTION=Deploying changes to ${{NAMESPACE}} namespace
97-
- GITHUB_TARGET_URL=http://${{APP_HOST}}
101+
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}
98102
when:
99103
condition:
100104
all:
@@ -105,6 +109,7 @@ steps:
105109
title: Push image with commit tag
106110
stage: Deploy
107111
type: push
112+
registry: dockerhub
108113
candidate: ${{build_image}}
109114
tags:
110115
- "${{CF_REVISION}}"
@@ -114,7 +119,7 @@ steps:
114119
stage: Deploy
115120
image: codefresh/cli:latest
116121
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'
122+
- codefresh get builds --pipeline=destroy --pipeline=preview --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
118123
retry:
119124
maxAttempts: 10
120125
delay: 20
@@ -132,8 +137,11 @@ steps:
132137
commands:
133138
# Announce the release version
134139
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
140+
# Downgrade to helm 3.1.3: https://github.com/helm/helm/issues/7956
141+
- "apk add --update curl make bash git kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
142+
- "kubectl config use-context ${{KUBE_CONTEXT}}"
135143
# Deploy chart to cluster in a dedicated namespace
136-
- "/deploy/ctl --namespace=${{NAMESPACE}} rolling"
144+
- "helmfile --namespace ${{NAMESPACE}} --selector preview=true sync"
137145
when:
138146
condition:
139147
any:
@@ -149,10 +157,10 @@ steps:
149157
- GITHUB_OWNER=${{CF_REPO_OWNER}}
150158
- GITHUB_REPO=${{CF_REPO_NAME}}
151159
- GITHUB_REF=${{CF_REVISION}}
152-
- GITHUB_CONTEXT=Staging Environment
160+
- GITHUB_CONTEXT=${{STAGE}}/env
153161
- GITHUB_STATE=success
154-
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} namespace
155-
- GITHUB_TARGET_URL=http://${{APP_HOST}}
162+
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} by @${{CF_BUILD_INITIATOR}}
163+
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}/dashboard
156164
when:
157165
condition:
158166
all:
@@ -177,3 +185,18 @@ steps:
177185
any:
178186
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
179187

188+
add_url_to_comment_on_commit:
189+
title: Comment on commit with the deployed URL
190+
stage: Deploy
191+
image: cloudposse/github-commenter
192+
environment:
193+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
194+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
195+
- GITHUB_REPO=${{CF_REPO_NAME}}
196+
- GITHUB_COMMENT_TYPE=commit
197+
- GITHUB_COMMIT_SHA=${{CF_SHORT_REVISION}}
198+
- 'GITHUB_COMMENT=Version ${{CF_SHORT_REVISION}} deployed by @${{CF_BUILD_INITIATOR}} to the [`${{NAMESPACE}}`](${{APP_SCHEME}}://${{APP_HOST}}/dashboard) namespace on `${{STAGE}}` at ${{CF_BUILD_DATE_TIME}}<details>![:thumbsup:](https://cloudposse.com/urand/familyguy.gif)</details>'
199+
when:
200+
condition:
201+
all:
202+
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"

0 commit comments

Comments
 (0)