Skip to content

Commit 5764644

Browse files
authored
Add examples for CodeFresh CI/CD Pipelines integration (#5)
* Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `README` * Update `main.go`
1 parent 52cfac4 commit 5764644

9 files changed

Lines changed: 179 additions & 10 deletions

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ Command line utility for updating GitHub commit statuses and enabling required s
66
* https://developer.github.com/v3/repos/statuses
77
* https://help.github.com/articles/enabling-required-status-checks
88

9+
Useful for CI environments to set more specific commit and build statuses, including setting the target URL
10+
(the URL of the page representing the build status, or the URL of the deployed application).
911

10-
![GitHub Status Checks](images/github-status-check-success.png)
11-
###
1212

13+
![GitHub Status Checks](images/codefresh-deployment-status-success.png)
14+
###
1315

14-
Useful for CI environments to set more specific commit and build statuses, including setting the target URL (the URL of the page representing the status).
1516

16-
__NOTE__: Create a [GitHub token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) with `repo:status` and `public_repo` scopes
17+
__NOTE__: Create a [GitHub token](https://help.github.com/articles/creating-an-access-token-for-command-line-use) with `repo:status` and `public_repo` scopes
1718

1819
__NOTE__: The icons in the image above are the avatars of the users for which the GitHub access tokens are issued
1920

2021

2122

2223
## Usage
2324

24-
__NOTE__: The module accepts parameters as command-line arguments or as ENV variables (or any combination of command-line arguments and ENV vars)
25+
__NOTE__: The module accepts parameters as command-line arguments or as ENV variables
26+
(or any combination of command-line arguments and ENV vars).
27+
Command-line arguments take precedence over ENV vars.
2528

2629

2730
| Command-line argument | ENV var | Description |
@@ -155,7 +158,8 @@ docker run -i --rm --env-file ./example.env github-status-updater
155158
```
156159

157160

158-
##
161+
###
162+
###
159163
## GitHub Required Status Checks
160164

161165

@@ -171,8 +175,6 @@ First, repository administrators need to enforce the branch protection and requi
171175
![GitHub Branch Protection Settings](images/github-branch-protection-settings.png)
172176

173177

174-
175-
176178
Then, to add `my-ci` as a status check for branch `test` of the `github-status-updater` repo, execute the `update_branch_protection` action locally
177179

178180
```ssh
@@ -269,6 +271,29 @@ When the build succeeds, `my-ci` updates the build status to `success`
269271
###
270272

271273

274+
###
275+
## Integrating with [CodeFresh](https://codefresh.io) CI/CD Pipelines
276+
277+
`github-status-updater` can be easily integrated into CI/CD pipelines, especially those that use containers for build steps.
278+
279+
[codefresh.yml](examples/codefresh.yml) shows a complete example of a [CodeFresh](https://docs.codefresh.io/docs/introduction-to-codefresh-pipelines) pipeline which performs the following steps:
280+
281+
* Builds a Docker image for the application
282+
* Builds a [Helm](https://github.com/kubernetes/helm) [chart](https://github.com/kubernetes/charts)
283+
* Pushes the Docker images (for commits, branches and tags) to CodeFresh repository
284+
* Executes `update_branch_protection` action on `github-status-updater` [Docker container](https://hub.docker.com/r/cloudposse/github-status-updater) to add `Staging Environment` as a required status check
285+
* Executes `update_state` action on `github-status-updater` [Docker container](https://hub.docker.com/r/cloudposse/github-status-updater) to update `Staging Environment` deployment status to `pending`
286+
* Deploys the Helm chart to a [Kubernetes](https://kubernetes.io) cluster
287+
* Executes `update_state` action on `github-status-updater` [Docker container](https://hub.docker.com/r/cloudposse/github-status-updater) to update `Staging Environment` deployment status to `success`
288+
289+
290+
![GitHub Status Checks](images/codefresh-deployment-status-pending.png)
291+
###
292+
293+
![GitHub Status Checks](images/codefresh-deployment-status-success.png)
294+
###
295+
296+
272297

273298
## References
274299
* https://github.com/google/go-github
@@ -279,6 +304,10 @@ When the build succeeds, `my-ci` updates the build status to `success`
279304
* https://docs.docker.com/develop/develop-images/dockerfile_best-practices
280305
* https://docs.docker.com/engine/reference/commandline/build
281306
* https://docs.docker.com/engine/reference/commandline/run
307+
* https://codefresh.io
308+
* https://docs.codefresh.io/docs/introduction-to-codefresh-pipelines
309+
* https://github.com/kubernetes/helm
310+
* https://github.com/kubernetes/charts
282311

283312

284313

examples/codefresh.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
version: '1.0'
2+
3+
steps:
4+
init-variables:
5+
title: Init variables
6+
image: alpine
7+
commands:
8+
- cf_export BUILD_HARNESS_VERSION=feature-helm-chart-ops
9+
- cf_export GIT_BRANCH=${{CF_BRANCH}}
10+
11+
build-image:
12+
title: Build image
13+
type: build
14+
description: Build catalogue
15+
image-name: cloudpossedemo/catalogue
16+
dockerfile: Dockerfile
17+
18+
semver:
19+
title: Export semantic version
20+
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
21+
working_directory: ${{build-image}}
22+
commands:
23+
- make git:show
24+
- make semver:show
25+
- make semver:export >> ${{CF_VOLUME_PATH}}/env_vars_to_export
26+
- make stages:export
27+
- make stages:export >> ${{CF_VOLUME_PATH}}/env_vars_to_export
28+
29+
build-chart:
30+
title: Build Charts
31+
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
32+
working_directory: ${{build-image}}
33+
commands:
34+
- REPO_NAME=cloudpossedemo REPO_ENDPOINT=${{REPO_ENDPOINT}} make helm:repo:add
35+
- make helm:repo:add-remote
36+
- make helm:chart:clean
37+
- make helm:chart:build-all
38+
- make helm:chart:publish
39+
40+
push-image-commit:
41+
title: Push image with commit based semver tags
42+
type: push
43+
candidate: ${{build-image}}
44+
tags:
45+
- "${{SEMVERSION_COMMIT_SHORT}}"
46+
- "${{SEMVERSION_COMMIT}}"
47+
48+
push-image-branch:
49+
title: Push image with branch based semver tags
50+
type: push
51+
candidate: ${{build-image}}
52+
tags:
53+
- "${{SEMVERSION_BRANCH}}"
54+
- "${{SEMVERSION_BRANCH_COMMIT_SHORT}}"
55+
- "${{SEMVERSION_BRANCH_COMMIT}}"
56+
when:
57+
condition:
58+
all:
59+
executeForBranch: "'${{SEMVERSION_BRANCH}}' != ''"
60+
61+
push-image-tag:
62+
title: Push image with tag based semver tags
63+
type: push
64+
candidate: ${{build-image}}
65+
tag: "${{SEMVERSION_TAG}}"
66+
when:
67+
condition:
68+
all:
69+
executeForTag: "'${{SEMVERSION_TAG}}' != ''"
70+
71+
push-image-latest:
72+
title: Push image with latest tag
73+
type: push
74+
candidate: ${{build-image}}
75+
tag: latest
76+
when:
77+
condition:
78+
all:
79+
executeForMasterBranch: "'${{CF_BRANCH}}' == 'master'"
80+
81+
update-branch-protection:
82+
title: Add "Staging Environment" status check to the branch
83+
image: cloudposse/github-status-updater
84+
environment:
85+
- GITHUB_ACTION=update_branch_protection
86+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
87+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
88+
- GITHUB_REPO=${{CF_REPO_NAME}}
89+
- GITHUB_REF=${{CF_BRANCH}}
90+
- GITHUB_CONTEXT=Staging Environment
91+
when:
92+
condition:
93+
all:
94+
executeForBranch: "'${{SEMVERSION_BRANCH}}' != ''"
95+
96+
set-deployment-status-to-pending:
97+
title: Set "Staging Environment" deployment status to "pending"
98+
image: cloudposse/github-status-updater
99+
environment:
100+
- GITHUB_ACTION=update_state
101+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
102+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
103+
- GITHUB_REPO=${{CF_REPO_NAME}}
104+
- GITHUB_REF=${{CF_REVISION}}
105+
- GITHUB_CONTEXT=Staging Environment
106+
- GITHUB_STATE=pending
107+
- GITHUB_DESCRIPTION=Deploying changes to ${{FEATURE}} namespace
108+
- GITHUB_TARGET_URL=http://master.demo.cloudposse.org
109+
110+
deploy-helm:
111+
title: Deploy Helm chart
112+
image: cloudposse/cf-plugin-helm:0.2.0-fix-working-with-repo
113+
environment:
114+
- CHART_NAME=catalogue
115+
- RELEASE_NAME=catalogue-${{CF_BRANCH_TAG_NORMALIZED}}
116+
- KUBE_CONTEXT=cluster-4
117+
- NAMESPACE=${{NAMESPACE}}
118+
- CHART_VERSION=${{SEMVERSION_BRANCH}}
119+
- CHART_REPO_URL=${{REPO_ENDPOINT}}
120+
- WAIT=false
121+
- TIMEOUT=1200
122+
- custom_fullnameOverride=catalogue
123+
124+
set-deployment-status-to-success:
125+
title: Set "Staging Environment" deployment status to "success"
126+
image: cloudposse/github-status-updater
127+
environment:
128+
- GITHUB_ACTION=update_state
129+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
130+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
131+
- GITHUB_REPO=${{CF_REPO_NAME}}
132+
- GITHUB_REF=${{CF_REVISION}}
133+
- GITHUB_CONTEXT=Staging Environment
134+
- GITHUB_STATE=success
135+
- GITHUB_DESCRIPTION=Deployed to ${{FEATURE}} namespace
136+
- GITHUB_TARGET_URL=http://master.demo.cloudposse.org

glide.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package: github.com/cloudposse/github-status-updater
2+
import:
3+
- package: github.com/google/go-github/github
4+
- package: golang.org/x/net/context
185 KB
Loading
186 KB
Loading
169 KB
Loading
181 KB
Loading

images/github-branch-status.png

170 KB
Loading

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func main() {
128128
log.Fatal(err)
129129
}
130130

131-
fmt.Println("Updated status", *repoStatus.ID)
131+
fmt.Println("github-status-updater: Updated status", *repoStatus.ID)
132132

133133
} else if *action == "update_branch_protection" {
134134
if *ref == "" {
@@ -196,6 +196,6 @@ func main() {
196196
log.Fatal(err)
197197
}
198198

199-
fmt.Println("Updated branch protection")
199+
fmt.Println("github-status-updater: Updated branch protection")
200200
}
201201
}

0 commit comments

Comments
 (0)