Skip to content

Commit 60509e6

Browse files
utsavanand2alexellis
authored andcommitted
Address improvements mentioned in #193
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>
1 parent 99106f6 commit 60509e6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

_posts/2020-10-08-openfaas-functions-with-github-actions.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ A workflow can be composed of multiple steps, each executing a particular action
8282
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.
8383

8484
Our workflow is a simple linear process:
85-
`Checkout` -> `Pull Templates` -> `Shrink-wrap a Docker context` -> `OpenFaaS Login` -> `Docker Login` -> `Docker Buildx Setup` -> `Build & Push Function` -> `Deploy to OpenFaaS`
86-
85+
![flow](/images/2020-10-github-actions/flow.jpg)
8786
In the root directory of the project run:
8887

8988
```sh
@@ -107,6 +106,10 @@ jobs:
107106
-
108107
name: Checkout
109108
uses: actions/checkout@v2
109+
-
110+
name: Define ENV VARS
111+
id: define_env
112+
run: echo "::set-output name=github-sha-short::$(echo $GITHUB_SHA | cut -c 1-7)"
110113
-
111114
name: Pull template
112115
uses: docker://openfaas/faas-cli:latest-root
@@ -121,7 +124,8 @@ jobs:
121124
name: Login to OpenFaaS Gateway
122125
uses: docker://openfaas/faas-cli:latest-root
123126
with:
124-
args: login -p {% raw %}${{ secrets.OPENFAAS_GATEWAY_PASSWD }}{% endraw %} -g {% raw %}${{ secrets.OPENFAAS_GATEWAY }}{% endraw %}
127+
args: login -p {% raw %}${{ secrets.OPENFAAS_GATEWAY_PASSWD }}{% endraw %} \
128+
-g {% raw %}${{ secrets.OPENFAAS_GATEWAY }}{% endraw %}
125129
-
126130
name: Login to DockerHub
127131
if: success()
@@ -139,12 +143,12 @@ jobs:
139143
context: ./build/hello/
140144
file: ./build/hello/Dockerfile
141145
push: true
142-
tags: utsavanand2/hello:latest
146+
tags: utsavanand2/hello:latest-{% raw %}${{ steps.define_env.outputs.github-sha-short }}{% endraw %}
143147
-
144-
name: Deploying the OpenFaaS function
148+
name: Deploy the function
145149
uses: docker://openfaas/faas-cli:latest-root
146150
with:
147-
args: deploy -f hello.yml
151+
args: deploy -f hello.yml --tag sha
148152
```
149153
150154
> 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
154158
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.
155159
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`.
156160

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+
157165
### Add secrets to your GitHub repo for the build
158166

159167
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://
207215
file: ./build/hello/Dockerfile
208216
push: true
209217
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 %}
211219
```
212220

213221
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):
45.2 KB
Loading

0 commit comments

Comments
 (0)