-
Notifications
You must be signed in to change notification settings - Fork 3
177 lines (171 loc) · 6.42 KB
/
backend-build-test-release.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Backend - Build-Test-Release
## workflow will trigger on below condition,
## except image release that have jobs condition to trigger only on tagging
on:
pull_request:
branches:
- main
- dev
push:
branches:
- main
- dev
tags:
- 'v*.*.*'
env:
GCP_REGISTRY_ARTIFACT_PATH: us-docker.pkg.dev/world-engine-test/agar-shooter
GCP_PROJECT_ID: world-engine-test
CARDINAL_REGISTRY_PATH: agar-shooter/cardinal
NAKAMA_REGISTRY_PATH: agar-shooter/nakama
jobs:
backend-build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
env:
GOPRIVATE: github.com/argus-labs
strategy:
matrix:
go-version: [1.20.x]
backend-dir:
- cardinal
- nakama
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: |
${{ secrets.CARDINAL_AGAR_SHOOTER_DEPLOY_KEY }}
- name: Use git SSH Deploy Key
run: git config --global --add url."git@github.com:".insteadOf "https://github.com/"
- 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 }}
- name: Prepare Go Build
run: |
cd ${{ matrix.backend-dir }}
go mod tidy
go mod vendor
- name: Docker Build
run: |
cd ${{ matrix.backend-dir }}
docker build -t agar-shooter-${{ matrix.backend-dir }}:latest .
docker save agar-shooter-${{ matrix.backend-dir }}:latest > /tmp/agar-shooter-${{ matrix.backend-dir }}-latest.tar
- name: Upload local build images to temporary artifact
uses: actions/upload-artifact@v3
with:
name: buildimage
path: /tmp/agar-shooter-${{ matrix.backend-dir }}-latest.tar
backend-test:
runs-on: ubuntu-latest
needs: backend-build
defaults:
run:
shell: bash
env:
GOPRIVATE: github.com/argus-labs
strategy:
matrix:
go-version: [1.20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use git SSH Deploy Key
run: git config --global --add url."git@github.com:".insteadOf "https://github.com/"
- 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/agar-shooter-nakama-latest.tar
docker load --input /tmp/agar-shooter-cardinal-latest.tar
docker image ls -a | grep agar-shooter
- name: Docker Compose Up
run: |
docker compose up --detach --wait --wait-timeout 60
- name: Docker compose logs last status
if: success() || failure()
run: |
docker compose logs
- name: Verify running container
run: |
docker compose ps
>/dev/tcp/127.0.0.1/7350
- name: Docker Compose Down
run: |
docker compose down
backend-release:
runs-on: ubuntu-latest
needs: backend-test
if: startsWith(github.ref, 'refs/tags/v')
# Add "id-token" with the intended google-github-actions/auth permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- 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/agar-shooter-nakama-latest.tar
docker load --input /tmp/agar-shooter-cardinal-latest.tar
docker image ls -a | grep agar-shooter
- 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: ${{ env.GCP_PROJECT_ID }}
- name: Docker - auth to artifact registry
run: |
gcloud auth configure-docker us-docker.pkg.dev
- name: Set RELEASE_VERSION value (branch main / tag v.*)
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Docker - tag and push container
run: |
docker tag agar-shooter-cardinal:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker tag agar-shooter-nakama:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker tag agar-shooter-cardinal:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:latest"
docker tag agar-shooter-nakama:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:latest"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:latest"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:latest"
- name: Dark Forest - Docker Image Released
run: |
echo "----------------------------------------------"
echo "🎉 Agar Shooter container images released [${{ env.RELEASE_VERSION }}]"
echo " Cardinal : ${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
echo " Nakama : ${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
echo "----------------------------------------------"
backend-cleanup:
runs-on: ubuntu-latest
needs: [
backend-build,
backend-test,
backend-release
]
if: always()
steps:
- name: Remove local build image artifact
uses: geekyeggo/delete-artifact@v2
with:
name: buildimage