-
Notifications
You must be signed in to change notification settings - Fork 6
217 lines (208 loc) · 7.64 KB
/
build.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
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
206
207
208
209
210
211
212
213
214
215
216
name: Build and Deploy
on:
push:
branches: ["main"]
tags: ["v1.[0-9]+.[0-9]+.[0-9]+"]
pull_request:
types: [opened, synchronize, reopened]
jobs:
eslint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
cache-dependency-path: yarn.lock
- name: Install dependencies
run: yarn install --immutable
- name: Run eslint
run: yarn lint
- name: Test build
run: yarn build
build:
name: Build
runs-on: ubuntu-latest
needs: eslint
strategy:
matrix:
facility: [zdv, zan, hcf, zlc, zfw]
include:
- facility: hcf
name: HCF
secret: ADH_PIPELINE_PAT
repo: vphzh/gitops
frontend: adhp/hcf-frontend
- facility: zan
name: PAZA
secret: ADH_PIPELINE_PAT
repo: vpaza/gitops
frontend: adhp/zan-frontend
- facility: zdv
name: KZDV
secret: GH_PIPELINE_PAT
repo: kzdv/gitops
frontend: adhp/zdv-frontend
- facility: zfw
name: KZFW
secret: ADH_PIPELINE_PAT
repo: kzfw/gitops
frontend: adhp/frontend
- facility: zlc
name: KZLC
secret: KZLC_GITOPS_TOKEN
repo: kzlc/gitops
frontend: adhp/zlc-frontend
steps:
- uses: actions/checkout@v3
name: Checkout repo
- name: Set sha_short
id: vars
run: |-
echo "sha_short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
# Set default branch name for PRs, as we still want to test build an image on PRs
# but we have no branch to set a tag for.
branch="test"
if [[ "$GITHUB_REF" == "refs/heads/"* ]]; then
branch="${GITHUB_REF#refs/heads/}"
fi
echo "branch=${branch}" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install cosign
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'
- name: Create .env
run: |
SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-7)
cat <<EOF > .env
VITE_GIT_HASH="$SHA_SHORT"
EOF
- name: Set base version from .version
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: |
VERSION=$(cat .version | tr -d '\n')
echo "VITE_VERSION_BASE=$VERSION" >> .env
- name: Set version as tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "VITE_VERSION_BASE=$GITHUB_REF_NAME" >> .env
- name: Setup Facility file
run: |
cp src/facility-${{ matrix.facility }}.ts src/facility.ts
- name: Build Image
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ github.ref_name }}-${{ env.sha_short }} -t ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ github.ref_name }} .
# If dev branch, we want to target the dev API... so we do this through an ARG that sets the mode to staging.
- name: Build Staging Image
if: ${{ env.branch == 'main' }}
run: |
docker build --build-arg build_cmd="build-dev" -t ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ env.branch }}-${{ env.sha_short }} -t ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ env.branch }} .
- name: Build test image
if: ${{ github.event_name == 'pull_request' }}
run: |
docker build --build-arg build_cmd="build-dev" -t ${{ secrets.DOCKER_USERNAME }}/frontend:trash .
- name: Push Image
if: ${{ github.event_name == 'push' }}
run: |
docker push --all-tags ${{ secrets.DOCKER_USERNAME }}/frontend
- name: Sign image
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PRIVATE_KEY_PASSWORD }}
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
run: |
image_digest_sha=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ github.ref_name }}-${{ env.sha_short }})
image_digest_branch=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ secrets.DOCKER_USERNAME }}/frontend:${{ matrix.facility }}-${{ github.ref_name }})
cosign sign --key env://COSIGN_PRIVATE_KEY $image_digest_sha $image_digest_branch
###########################################################################################################
deploy:
name: Update ${{ matrix.facility.name }} GitOps Repo
strategy:
matrix:
facility: [zdv, zan, hcf, zlc, zfw]
include:
- facility: hcf
name: HCF
secret: ADH_PIPELINE_PAT
repo: vphzh/gitops
frontend: adhp/hcf-frontend
- facility: zan
name: PAZA
secret: ADH_PIPELINE_PAT
repo: vpaza/gitops
frontend: adhp/zan-frontend
- facility: zdv
name: KZDV
secret: GH_PIPELINE_PAT
repo: kzdv/gitops
frontend: adhp/zdv-frontend
- facility: zfw
name: KZFW
secret: ADH_PIPELINE_PAT
repo: kzfw/gitops
frontend: adhp/frontend
- facility: zlc
name: KZLC
secret: KZLC_GITOPS_TOKEN
repo: kzlc/gitops
frontend: adhp/zlc-frontend
runs-on: ubuntu-latest
needs: build
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/main')) }}
steps:
- name: Set sha_short
id: vars
run: |-
echo "sha_short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
# Set default branch name for PRs, as we still want to test build an image on PRs
# but we have no branch to set a tag for.
branch="test"
if [[ "$GITHUB_REF" == "refs/heads/"* ]]; then
branch="${GITHUB_REF#refs/heads/}"
fi
echo "branch=${branch}" >> $GITHUB_ENV
- name: Checkout ${{ matrix.name }} Gitops Repo
uses: actions/checkout@v3
with:
token: ${{ secrets[matrix.secret] }}
repository: ${{ matrix.repo }}
path: gitops
- name: Configure git
run: |-
cd $GITHUB_WORKSPACE/gitops
git config user.name "adh-pipeline"
git config user.email "[email protected]"
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v2
with:
kustomize-version: "5.2.1"
- name: Update dev overlay
if: ${{ github.ref == 'refs/heads/main' }}
run: |
cd $GITHUB_WORKSPACE/gitops/overlays/dev
kustomize edit set image ${{ matrix.frontend }}=adhp/frontend:${{ matrix.facility }}-${{ env.branch }}-${{ env.sha_short }}
- name: Update prod overlay
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
cd $GITHUB_WORKSPACE/gitops/overlays/prod
kustomize edit set image ${{ matrix.frontend }}=adhp/frontend:${{ matrix.facility }}-${{ github.ref_name }}-${{ env.sha_short }}
- name: Commit manifests
run: |
cd $GITHUB_WORKSPACE/gitops
git add .
git commit -m "Update manifests for frontend"
- name: Push to gitops repo
run: |
cd $GITHUB_WORKSPACE/gitops
git push origin main