You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a flowchart for the workflow of CI/CD with OpenFaaS
and Github Actions, and use commit SHA as build tags of images.
Signed-off-by: Utsav Anand <utsavanand2@gmail.com>
Copy file name to clipboardExpand all lines: _posts/2020-10-08-openfaas-functions-with-github-actions.md
+15-7Lines changed: 15 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -82,8 +82,7 @@ A workflow can be composed of multiple steps, each executing a particular action
82
82
There are many published [Actions](https://github.com/marketplace?type=actions) that provide nice wrappers for common actions and tools making them easier to use, but we can also use any published Docker image. The OpenFaaS team already publishes an image for `faas-cli` that is ready to use for any workflow.
-g {% raw %}${{ secrets.OPENFAAS_GATEWAY }}{% endraw %}
125
129
-
126
130
name: Login to DockerHub
127
131
if: success()
@@ -139,12 +143,12 @@ jobs:
139
143
context: ./build/hello/
140
144
file: ./build/hello/Dockerfile
141
145
push: true
142
-
tags: utsavanand2/hello:latest
146
+
tags: utsavanand2/hello:latest-{% raw %}${{ steps.define_env.outputs.github-sha-short }}{% endraw %}
143
147
-
144
-
name: Deploying the OpenFaaS function
148
+
name: Deploy the function
145
149
uses: docker://openfaas/faas-cli:latest-root
146
150
with:
147
-
args: deploy -f hello.yml
151
+
args: deploy -f hello.yml --tag sha
148
152
```
149
153
150
154
> Note: replace the `DOCKER_USERNAME` from the image tag name with your own.
@@ -154,6 +158,10 @@ Since GitHub Actions requires us to use a Docker image that has a root user invo
154
158
The faas-cli:latest-root image has the faas-cli installed as the entrypoint, so everything set in args is passed to the faas-cli.
155
159
This will work with any of the faas-cli root tags, you can pin to any specific version of faas-cli, for example: `openfaas/faas-cli:0.12.14-root`.
156
160
161
+
We're also using using the second step in the workflow to get a short seven characters long SHA of the git commit to tag our Docker image with in the `Build and Push the OpenFaaS function` step of the workflow.
162
+
In the last step of the build `Deploy the function` we're using the arg `--tag sha` which will call the OpenFaaS API Gateway for it to expect an image with the tag `latest-${7 char long commit SHA}`.
163
+
This explains the tag we're using in the `Build and Push the OpenFaaS function` step as well.
164
+
157
165
### Add secrets to your GitHub repo for the build
158
166
159
167
Add the following secrets and their values to the repo for GitHub Actions to build push and deploy your OpenFaaS functions. Make sure that the secret names correspond with the GitHub workflow YAML file as defined above in the previous section.
@@ -207,7 +215,7 @@ The two changes are to set up an emulation tool for Linux called [qemu](https://
207
215
file: ./build/hello/Dockerfile
208
216
push: true
209
217
platforms: linux/amd64,linux/arm64,linux/arm/v7
210
-
tags: utsavanand2/hello:latest
218
+
tags: utsavanand2/hello:latest-{% raw %}${{ steps.define_env.outputs.github-sha-short }}{% endraw %}
211
219
```
212
220
213
221
You can see the full workflow YAML file supporting multi-arch builds here: [main.yml](https://github.com/utsavanand2/hello/blob/multi-arch/.github/workflows/main.yml):
0 commit comments