Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit 69dc216

Browse files
committed
cicd: adminui prod
1 parent ab0111d commit 69dc216

File tree

1 file changed

+91
-18
lines changed

1 file changed

+91
-18
lines changed

.github/workflows/web-admin.yaml

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,69 @@
11
name: web-admin ui
22
on:
33
push:
4+
branches:
5+
- main
6+
- master
7+
- develop
8+
- cicd/adminui-prod
9+
10+
pull_request:
11+
types:
12+
- open
13+
- synchronized
14+
15+
release:
16+
types:
17+
- published
18+
419

520
jobs:
6-
adminui:
21+
whatisthecontext:
722
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
node-version: [12.x]
11-
name: build & deploy adminui
12-
23+
name: display the current build & deploy CI context and export useful values
24+
outputs:
25+
sha: ${{ steps.contextvals.outputs.sha }}
26+
built_at: ${{ steps.contextvals.outputs.built_at }}
27+
is_dev_deploy: ${{ github.ref == 'master' }}
28+
api_url: ${{ steps.contextvals.outputs.api_url }}
29+
target_bucket: ${{ steps.contextvals.outputs.target_bucket }}
30+
is_github_release: ${{ github.event_name == 'release' }}
1331
steps:
14-
- name: Context
15-
uses: docker://busybox
16-
- name: export context values
32+
- name: Export values
1733
id: contextvals
1834
run: |
1935
SHA=${{ github.sha }}
20-
BUILT_AT=$(date +%Y-%m-%dT%H:%M:%S%z)
36+
BUILT_AT=$(date "+%Y-%m-%d %H:%M:%S%z")
37+
if [ ${{ github.event_name == 'release' }} ]; then
38+
API_URL=https://api.dev.ballotnav.org
39+
TARGET_BUCKET=admin.ballotnav.org
40+
else
41+
API_URL=https://api.ballotnav.org
42+
TARGET_BUCKET=admin.dev.ballotnav.org
43+
fi
44+
45+
# print these to the console for sanity checking
46+
printf "%s\n" "SHA: ${SHA:0:8}"
47+
printf "%s\n" "Target bucket ${TARGET_BUCKET}"
48+
printf "%s\n" "API url ${API_URL}"
49+
printf "%s\n" "Built at ${BUILT_AT}"
50+
51+
# export them to github action outputs
2152
echo ::set-output name=sha::${SHA:0:8}
2253
echo ::set-output name=artifactbucket::ballotnav-dev-adminui-dev-logs
23-
echo ::set-output name=targetbucket::admin.dev.ballotnav.org
24-
echo ::set-output name=apiurl::https://api.dev.ballotnav.org
54+
echo ::set-output name=targetbucket::${TARGET_BUCKET}
55+
echo ::set-output name=apiurl::${API_URL}
2556
echo ::set-output name=built_at::${BUILT_AT}
2657
58+
adminui:
59+
runs-on: ubuntu-latest
60+
needs: [whatisthecontext]
61+
strategy:
62+
matrix:
63+
node-version: [12.x]
64+
name: build & deploy adminui to dev
65+
66+
steps:
2767
- uses: actions/checkout@v2
2868
- name: Setup node
2969
uses: actions/setup-node@v1
@@ -34,18 +74,21 @@ jobs:
3474
run: npm ci
3575

3676
- name: Build the app
77+
# we do not build the app again on release, instead we will unpack the already built artifact saved with the git SHA
78+
if: ${{ needs.whatisthecontext.outputs.is_github_release != true }}
3779
working-directory: ./client/web-admin
3880
run: |
39-
REACT_APP_API_URL=${{ steps.contextvals.outputs.apiurl }} npm run build
40-
printf "%s\n" '{"version": "${{ steps.contextvals.outputs.sha }}", "built_at" : "${{ steps.contextvals.outputs.built_at }}" }' > build/version.json
81+
REACT_APP_API_URL=${{ needs.whatisthecontext.outputs.apiurl }} npm run build
82+
printf "%s\n" '{"version": "${{ needs.whatisthecontext.outputs.sha }}", "built_at" : "${{ needs.whatisthecontext.outputs.built_at }}" }' > build/version.json
4183
4284
- name: Create artifact
85+
if: ${{ needs.whatisthecontext.outputs.is_github_release != true }}
4386
uses: docker://busybox
4487
- name: tarball
4588
if: ${{ github.ref == 'refs/heads/master' }}
4689
working-directory: ./client/web-admin
4790
run: |
48-
tar -czf adminui-${{ steps.contextvals.outputs.sha }}.tar.gz build
91+
tar -czf adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz build
4992
5093
- name: Configure AWS credentials
5194
uses: aws-actions/configure-aws-credentials@v1
@@ -58,12 +101,42 @@ jobs:
58101
if: ${{ github.ref == 'refs/heads/master' }}
59102
working-directory: ./client/web-admin
60103
run: |
61-
aws s3 cp adminui-${{ steps.contextvals.outputs.sha }}.tar.gz s3://${{ steps.contextvals.outputs.artifactbucket }}/artifacts/
104+
aws s3 cp adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz s3://${{ needs.whatisthecontext.outputs.artifactbucket }}/artifacts/
62105
63-
- name: Deploy to the web admin app
106+
- name: Deploy to the web admin app to dev
64107
if: ${{ github.ref == 'refs/heads/master' }}
65108
working-directory: ./client/web-admin
66109
run: |
67-
aws s3 sync build s3://${{ steps.contextvals.outputs.targetbucket }}
110+
aws s3 sync build s3://${{ needs.whatisthecontext.outputs.targetbucket }}
111+
aws s3 cp build/index.html s3://${{ needs.whatisthecontext.outputs.targetbucket }}/ --cache-control no-cache
112+
aws s3 cp build/version.json s3://${{ needs.whatisthecontext.outputs.targetbucket }}/ --cache-control no-cache
113+
114+
deploy_prd:
115+
name: deploy to the production environment
116+
runs-on: ubuntu-latest
117+
needs: [whatisthecontext]
118+
if: ${{ needs.whatisthecontext.outputs.is_github_release == true }}
119+
steps:
120+
- name: Configure AWS credentials
121+
uses: aws-actions/configure-aws-credentials@v1
122+
with:
123+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
124+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
125+
aws-region: us-west-2
126+
127+
- name: Pull down the built artifact
128+
working-directory: ./client/web-admin
129+
run: |
130+
aws s3 cp s3://${{ needs.whatisthecontext.outputs.artifactbucket }}/adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz .
131+
132+
- name: unpack the tarball
133+
working-directory: ./client/web-admin
134+
run: |
135+
tar -xzf adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz .
136+
137+
- name: Deploy to the web admin app to prod
138+
working-directory: ./client/web-admin
139+
run: |
140+
aws s3 sync build s3://${{ needs.whatisthecontext.outputs.targetbucket }}
68141
aws s3 cp build/index.html s3://${{ steps.contextvals.outputs.targetbucket }}/ --cache-control no-cache
69142
aws s3 cp build/version.json s3://${{ steps.contextvals.outputs.targetbucket }}/ --cache-control no-cache

0 commit comments

Comments
 (0)