-
-
Notifications
You must be signed in to change notification settings - Fork 68
205 lines (202 loc) · 7.13 KB
/
build.yml
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Build
on:
workflow_call:
inputs:
tags:
type: string
description: The Docker Tags (see docker/metadata-action@v4 for available values)
required: true
push:
default: true
type: boolean
description: Push the Docker Images?
required: false
gke-cluster:
type: string
description: Google Kubernetes Engine Cluster
required: true
gke-zone:
type: string
description: Google Kubernetes Engine Zone
required: true
secrets:
gke-credentials:
description: Google Kubernetes Engine Credentials as JSON
required: true
gke-project:
description: Google Kubernetes Engine Project
required: true
gh-key:
description: GitHub Key
required: true
outputs:
version:
description: The Docker Image Version
value: ${{ jobs.php.outputs.version }}
jobs:
php:
name: PHP
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
# gcloud does not work with Python 3.10 because collections.Mappings was removed in Python 3.10.
- uses: actions/setup-python@v4
with:
python-version: 3.9.15
- name: Auth gcloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.gke-credentials }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.gke-project }}
- name: Configure gcloud
run: |
gcloud --quiet auth configure-docker
gcloud container clusters get-credentials ${{ inputs.gke-cluster }} --zone ${{ inputs.gke-zone }}
- name: Docker metadata
id: docker-metadata
uses: docker/metadata-action@v4
with:
images: eu.gcr.io/${{ secrets.gke-project }}/website/php
tags: |
type=raw,value=${{ github.sha }},priority=9999
${{ inputs.tags }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./api
target: php_prod
pull: true
push: ${{ inputs.push }}
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
cache-from: |
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/caddy:latest
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/php:latest
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/caddy:${{ github.sha }}
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/php:${{ github.sha }}
cache-to: type=inline
outputs:
version: ${{ github.sha }}
caddy:
name: Caddy
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
# gcloud does not work with Python 3.10 because collections.Mappings was removed in Python 3.10.
- uses: actions/setup-python@v4
with:
python-version: 3.9.15
- name: Auth gcloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.gke-credentials }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.gke-project }}
- name: Configure gcloud
run: |
gcloud --quiet auth configure-docker
gcloud container clusters get-credentials ${{ inputs.gke-cluster }} --zone ${{ inputs.gke-zone }}
- name: Docker metadata
id: docker-metadata
uses: docker/metadata-action@v4
with:
images: eu.gcr.io/${{ secrets.gke-project }}/website/caddy
tags: |
type=raw,value=${{ github.sha }},priority=9999
${{ inputs.tags }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./api
target: caddy_prod
pull: true
push: ${{ inputs.push }}
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
cache-from: |
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/caddy:latest
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/php:latest
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/caddy:${{ github.sha }}
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/php:${{ github.sha }}
cache-to: type=inline
outputs:
version: ${{ github.sha }}
pwa:
name: PWA
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
# gcloud does not work with Python 3.10 because collections.Mappings was removed in Python 3.10.
- uses: actions/setup-python@v4
with:
python-version: 3.9.15
- name: Auth gcloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.gke-credentials }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.gke-project }}
- name: Configure gcloud
run: |
gcloud --quiet auth configure-docker
gcloud container clusters get-credentials ${{ inputs.gke-cluster }} --zone ${{ inputs.gke-zone }}
- name: Docker metadata
id: docker-metadata
uses: docker/metadata-action@v4
with:
images: eu.gcr.io/${{ secrets.gke-project }}/website/pwa
tags: |
type=raw,value=${{ github.sha }},priority=9999
${{ inputs.tags }}
- name: Define URL
run: |
set -o pipefail
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
echo "URL=api-platform.com" >> "$GITHUB_ENV"
else
CONTEXT=nonprod
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
export RELEASE_NAME=pr-$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
else
export RELEASE_NAME=${{ github.ref_name }}
fi
echo "URL=$RELEASE_NAME.apip.preprod-tilleuls.ovh" >> "$GITHUB_ENV"
fi
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./pwa
target: prod
pull: true
push: ${{ inputs.push }}
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
build-args: |
NEXT_ROOT_URL=${{ env.URL }}
cache-from: |
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/pwa:latest
type=registry,ref=eu.gcr.io/${{ secrets.gke-project }}/website/pwa:${{ github.sha }}
cache-to: type=inline
secrets: |
"GITHUB_KEY=${{ secrets.gh-key }}"
outputs:
version: ${{ github.sha }}