Skip to content

Commit b3e319f

Browse files
committed
Modernise examples
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent ce5588e commit b3e319f

1 file changed

Lines changed: 58 additions & 10 deletions

File tree

docs/reference/cicd/github-actions.md

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,54 @@ You can use GitHub Actions to build or publish container images for your OpenFaa
44

55
If you'd like to deploy the function, check out a more comprehensive example of how to log in and deploy in [Serverless For Everyone Else](https://store.openfaas.com/l/serverless-for-everyone-else).
66

7+
## A build to validate functions before merge
8+
9+
```yaml
10+
name: build
11+
12+
on:
13+
push:
14+
branches:
15+
- '*'
16+
pull_request:
17+
branches:
18+
- '*'
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@master
25+
with:
26+
fetch-depth: 1
27+
- name: Get faas-cli
28+
uses: alexellis/arkade-get@master
29+
with:
30+
faas-cli: latest
31+
- name: Pull custom templates from stack.yml
32+
run: faas-cli template pull stack
33+
- name: Set up QEMU
34+
uses: docker/setup-qemu-action@v3
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
- name: Get Repo Owner
38+
id: get_repo_owner
39+
run: >
40+
echo "repo_owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
41+
- name: Build functions
42+
run: >
43+
OWNER="${{ steps.get_repo_owner.outputs.repo_owner }}"
44+
TAG="latest"
45+
SERVER="ghcr.io"
46+
faas-cli build
47+
--build-arg GO111MODULE=on
48+
--filter release-promoter
49+
```
50+
51+
The `--filter release-promoter` line can be removed to build all functions in the stack.yml.
52+
53+
When multiple functions are available in the stack.yaml file you can add `--parallel` to speed up the build by building multiple functions at once.
54+
755
## Publish multiple functions
856

957
We will deploy alexellis' repository called [alexellis/autoscaling-functions](https://github.com/alexellis/autoscaling-functions). It contains multiple functions which can be deployed as a group.
@@ -20,10 +68,7 @@ name: publish
2068
2169
on:
2270
push:
23-
branches:
24-
- '*'
25-
pull_request:
26-
branches:
71+
tags:
2772
- '*'
2873
2974
permissions:
@@ -40,7 +85,9 @@ jobs:
4085
with:
4186
fetch-depth: 1
4287
- name: Get faas-cli
43-
run: curl -sLSf https://cli.openfaas.com | sudo sh
88+
uses: alexellis/arkade-get@master
89+
with:
90+
faas-cli: latest
4491
- name: Pull custom templates from stack.yml
4592
run: faas-cli template pull stack
4693
- name: Set up QEMU
@@ -49,12 +96,11 @@ jobs:
4996
uses: docker/setup-buildx-action@v3
5097
- name: Get TAG
5198
id: get_tag
52-
run: echo ::set-output name=TAG::latest-dev
99+
run: echo "TAG=latest-dev" >> $GITHUB_OUTPUT
53100
- name: Get Repo Owner
54101
id: get_repo_owner
55102
run: >
56-
echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} |
57-
tr '[:upper:]' '[:lower:]')
103+
echo "repo_owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
58104
- name: Docker Login
59105
run: >
60106
echo ${{secrets.GITHUB_TOKEN}} |
@@ -65,11 +111,13 @@ jobs:
65111
run: >
66112
OWNER="${{ steps.get_repo_owner.outputs.repo_owner }}"
67113
TAG="latest"
114+
SERVER="ghcr.io"
68115
faas-cli publish
69116
--extra-tag ${{ github.sha }}
117+
--extra-tag ${{ steps.get_tag.outputs.TAG }}
70118
--build-arg GO111MODULE=on
71-
--platforms linux/amd64,linux/arm64,linux/arm/v7
72-
--filter bcrypt
119+
--platforms linux/amd64,linux/arm64
120+
--filter release-promoter
73121
```
74122

75123
The Publish functions step uses [environment substitution](/reference/yaml/#yaml-environment-variable-substitution) to set the owner and tag for the image.

0 commit comments

Comments
 (0)