-
Notifications
You must be signed in to change notification settings - Fork 7
143 lines (135 loc) · 5.26 KB
/
backend-mage-pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: template-mage-pipeline
## workflow will trigger on below condition,
## except image release that have jobs condition to trigger only on tagging
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*.*.*'
env:
REGISTRY_URL: us-docker.pkg.dev
jobs:
mage-build-test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
strategy:
matrix:
go-version: [1.20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Mage - check
uses: magefile/mage-action@v2
with:
version: latest
args: check
- name: Mage - build & test
uses: magefile/mage-action@v2
with:
version: latest
args: test
- name: Docker show build images
run: |
docker image ls -a | grep starter-game-template
- name: Docker save local build images
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
run: |
docker save ${{ github.event.repository.name }}-nakama:latest | gzip > /tmp/${{ github.event.repository.name }}-nakama-latest.tar.gz
docker save ${{ github.event.repository.name }}-cardinal:latest | gzip > /tmp/${{ github.event.repository.name }}-cardinal-latest.tar.gz
docker save ${{ github.event.repository.name }}-testsuite:latest | gzip > /tmp/${{ github.event.repository.name }}-testsuite-latest.tar.gz
- name: Upload local build images to temporary artifact
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: buildimage
path: /tmp/starter-game-template-*.tar.gz
images-release:
runs-on: ubuntu-latest
needs: mage-build-test
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
defaults:
run:
shell: bash
# Add "id-token" with the intended permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download local build images artifact
uses: actions/download-artifact@v3
with:
name: buildimage
path: /tmp/
- name: Load image and show build images
run: |
docker load --input /tmp/${{ github.event.repository.name }}-nakama-latest.tar.gz
docker load --input /tmp/${{ github.event.repository.name }}-cardinal-latest.tar.gz
docker load --input /tmp/${{ github.event.repository.name }}-testsuite-latest.tar.gz
docker image ls -a | grep starter-game-template
- name: GCP auth
id: auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_WIF_SERVICE_ACCOUNT }}
- name: GCP - Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Docker - auth to artifact registry
run: |
gcloud auth configure-docker ${{ env.REGISTRY_URL }}
- name: Push image
run: |
IMAGE_ID_NAKAMA=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/nakama
IMAGE_ID_NAKAMA=$(echo $IMAGE_ID_NAKAMA | tr '[A-Z]' '[a-z]')
IMAGE_ID_CARDINAL=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/cardinal
IMAGE_ID_CARDINAL=$(echo $IMAGE_ID_CARDINAL | tr '[A-Z]' '[a-z]')
IMAGE_ID_TESTSUITE=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/testsuite
IMAGE_ID_TESTSUITE=$(echo $IMAGE_ID_TESTSUITE | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
[ "$VERSION" == "merge" ] && VERSION=latest
docker tag ${{ github.event.repository.name }}-nakama:latest $IMAGE_ID_NAKAMA:$VERSION
docker tag ${{ github.event.repository.name }}-cardinal:latest $IMAGE_ID_CARDINAL:$VERSION
docker tag ${{ github.event.repository.name }}-testsuite:latest $IMAGE_ID_TESTSUITE:$VERSION
docker push $IMAGE_ID_NAKAMA:$VERSION
docker push $IMAGE_ID_CARDINAL:$VERSION
docker push $IMAGE_ID_TESTSUITE:$VERSION
artifact-cleanup:
runs-on: ubuntu-latest
needs: [
mage-build-test,
images-release
]
if: always()
steps:
- name: Remove local build image artifact
uses: geekyeggo/delete-artifact@v2
with:
name: buildimage