-
Notifications
You must be signed in to change notification settings - Fork 2
145 lines (127 loc) · 4.31 KB
/
Copy pathdevelop.yml
File metadata and controls
145 lines (127 loc) · 4.31 KB
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
name: Build & Deploy das-web-react (develop)
on:
push:
branches:
- develop
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
actions: read
contents: read
id-token: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version-file: '.node-version'
- name: Install dependencies
run: yarn install --immutable
- name: Run tests
run: yarn test-ci
config:
runs-on: ubuntu-latest
outputs:
build-args: ${{ steps.env-vars.outputs.build-args }}
image-tag: ${{ steps.tag.outputs.value }}
steps:
- uses: actions/checkout@v7
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: '.node-version'
- run: |
npm pkg set "buildbranch"="${{ github.ref_name }}"
npm pkg set "buildnum"="${{ github.run_number }}"
- name: Select env file for build
id: env-vars
run: echo "build-args=ENV_FILE=.env.development" >> $GITHUB_OUTPUT
- name: Generate image tag
id: tag
run: |
SHORT_SHA="${GITHUB_SHA:0:7}"
BRANCH_SAFE=$(echo "${GITHUB_REF_NAME}" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
echo "value=${BRANCH_SAFE}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v7
with:
name: npm-config
path: package.json
build:
needs: config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: npm-config
path: .
- name: GCP Auth
id: auth
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
- name: Configure Docker
run: gcloud auth configure-docker europe-west3-docker.pkg.dev
- uses: docker/setup-buildx-action@v4
with:
driver-opts: |
image=europe-west3-docker.pkg.dev/serca-artifact-registry/virtual-docker/moby/buildkit:buildx-stable-1
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
europe-west3-docker.pkg.dev/serca-artifact-registry/earthranger/das-web-react
tags: |
type=raw,value=${{ needs.config.outputs.image-tag }}
# Artifact Registry has tag immutability enabled: re-pushing an existing
# {branch}-{sha} tag fails. The tag is keyed on the commit SHA, so an
# existing image is the same source; skip the rebuild and let the deploy
# jobs reuse it.
- name: Check if image already exists
id: image-check
run: |
IMAGE="europe-west3-docker.pkg.dev/serca-artifact-registry/earthranger/das-web-react:${{ needs.config.outputs.image-tag }}"
if gcloud artifacts docker images describe "${IMAGE}" --quiet; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Image does not exist yet; proceeding with build."
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Read node version
id: node-ver
run: echo "value=$(cat .node-version)" >> $GITHUB_OUTPUT
- name: Build and push
if: steps.image-check.outputs.exists != 'true'
uses: docker/build-push-action@v7
with:
push: true
context: .
file: Dockerfile.mt
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
${{ needs.config.outputs.build-args }}
NODE_VERSION=${{ steps.node-ver.outputs.value }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-dev:
needs: [config, build, test]
uses: ./.github/workflows/_update-argo.yml
with:
app-name: das-web-react
app-subdir: earthranger
environment: er-dev
image-tag: ${{ needs.config.outputs.image-tag }}
secrets:
ARGOCD_APPS_SSH_KEY: ${{ secrets.ARGOCD_APPS_SSH_KEY }}
sync-dev:
needs: [config, deploy-dev]
uses: ./.github/workflows/_sync-argo.yml
with:
app-name: das-web-react-er-dev
secrets:
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_AUTH_TOKEN }}