-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (142 loc) · 4.64 KB
/
build-and-deploy.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
name: Build & Deploy
on:
push:
branches:
- main
pull_request:
concurrency: ${{ github.ref }}
jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup-environment
id: setup
- name: Lint
run: yarn lint
- name: Prettier
run: yarn prettier
- name: Generate Prisma Schema
run: yarn prisma:generate
- name: Build
run: yarn build
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Dependencies Docker image
uses: docker/build-push-action@v5
if: steps.setup.outputs.cache-hit != 'true'
with:
context: .
file: docker/Dockerfile
push: true
tags: |
ghcr.io/tun-judge/dependencies:${{ hashFiles('yarn.lock') }}
ghcr.io/tun-judge/dependencies:latest
- name: Run docker compose up
if: false
run: |
docker compose -f docker-compose.test.yaml up -d app
sleep 30s
env:
DEPENDENCIES_TAG: ${{ hashFiles('yarn.lock') }}
- name: Run E2E tests
if: false
shell: bash
run: yarn e2e
- name: Run docker compose down
if: false
run: |
docker compose -f docker-compose.test.yaml logs
docker compose -f docker-compose.test.yaml down
- name: Save Build Output
uses: actions/cache/save@v4
with:
path: dist/apps
key: apps-${{ steps.setup.outputs.version }}
deploy:
runs-on: ubuntu-latest
permissions: write-all
if: startsWith(github.event.head_commit.message, 'release')
needs: build
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup-environment
id: setup
with:
skip-install: 'true'
- name: Restore Build Output
uses: actions/cache/restore@v4
with:
path: dist/apps
key: apps-${{ steps.setup.outputs.version }}
fail-on-cache-miss: true
- name: Google Auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.WIF_SERVICE_ACCOUNT }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Auth
id: docker-auth
uses: docker/login-action@v3
with:
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
registry: europe-west1-docker.pkg.dev
- name: Build and push Server Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/server/Dockerfile
push: true
tags: |
ghcr.io/tunjudge/server:${{ steps.setup.outputs.version }}
europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }}
build-args: |
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }}
- name: Build and push Judge Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/judge/Dockerfile
push: true
tags: ghcr.io/tunjudge/judge:${{ steps.setup.outputs.version }}
build-args: |
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
image: europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }}
service: tun-judge
region: europe-west1
env_vars: |
GOOGLE_PROJECT_ID=tun-judge-dev
GOOGLE_STORAGE_ENABLED=true
GOOGLE_STORAGE_BUCKET_NAME=tun-judge-files
secrets: |
SESSION_SECRET=SESSION_SECRET:latest
DATABASE_URL=TUN_JUDGE_DATABASE_URL:latest
DATABASE_DIRECT_URL=TUN_JUDGE_DATABASE_DIRECT_URL:latest
REDIS_URL=TUN_JUDGE_REDIS_URL:latest
- name: Show Output
shell: bash
run: echo ${{ steps.deploy.outputs.url }}