-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (166 loc) · 5.51 KB
/
pr-open-build-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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: PR Open
on:
# used on push for testing / development
# ---------------------------------------------------------
# push:
# branches: ['master', 'main', 'feat/5-deploy-frontend']
pull_request:
# debug: remove the dev,putting build action on non existent branches for debug
branches: ['main']
types: ['opened', 'reopened', 'edited', 'synchronize']
paths-ignore:
- .vscode/**
- .gitignore
- LICENSE
- readme.md
- code_of_conduct.md
- cicd/**
- scripts/**
- .flake8
- COMPLIANCE.yaml
workflow_dispatch:
jobs:
# calculate the image tag / used to tag image and then for the
# deployment
CalculateImageTags:
defaults:
run:
shell: bash
name: calculateImageTag
runs-on: ubuntu-24.04
outputs:
imagetag: ${{ steps.CalculateImageTagstep.outputs.IMAGE_TAG}}
steps:
- name: Calculate Image Tag
id: CalculateImageTagstep
shell: bash
run: |
DATESTAMP=$(date +%Y%m%d-%H%M)
echo datestamp is $DATESTAMP
echo event number: ${{ github.event.number }}
# TEMP_IMAGE_TAG=20230425-2337
# echo hard coding image tag as $TEMP_IMAGE_TAG
# echo "IMAGE_TAG=${TEMP_IMAGE_TAG}" >> "$GITHUB_OUTPUT"
echo "IMAGE_TAG=${DATESTAMP}" >> "$GITHUB_OUTPUT"
TestGetImageTag:
# test output of image tag, and verify its been calculated correctly
defaults:
run:
shell: bash
needs: CalculateImageTags
runs-on: ubuntu-24.04
steps:
- name: GET Image Tag
id: getImageTag
shell: bash
env:
IMAGE_TAG: ${{ needs.CalculateImageTags.outputs.imagetag }}
run: |
echo image tag is: $IMAGE_TAG
echo event number is: ${{ github.event.number }}
BuildContainerImage:
defaults:
run:
shell: bash
needs: CalculateImageTags
name: 'Build Streamlit Container Image'
runs-on: ubuntu-24.04
env:
DEBUG_DEPLOY: false
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
id: checkout
# with:
# fetch-depth: 0
- name: Verify tag
id: CalculateImageTagstep
shell: bash
env:
IMAGE_TAG: ${{ needs.CalculateImageTags.outputs.imagetag }}
run: |
echo image tag is $IMAGE_TAG ${{ env.IMAGE_TAG }}
echo event number is: ${{ github.event.number }}
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Client Docker Image
uses: docker/build-push-action@v6
env:
IMAGE_TAG: ${{ needs.CalculateImageTags.outputs.imagetag }}
with:
push: true # Will only build if this is not here
tags: |
ghcr.io/${{ github.repository_owner }}/streamlit_frontend:latest
ghcr.io/${{ github.repository_owner }}/streamlit_frontend:${{ env.IMAGE_TAG }}
ghcr.io/${{ github.repository_owner }}/streamlit_frontend:pr-${{ github.event.number }}
# This workflow contains a single job called "build"
DeployJob:
defaults:
run:
shell: bash
needs: [CalculateImageTags, BuildContainerImage]
name: 'Deploy Streamlit Image'
runs-on: ubuntu-24.04
environment: dev
steps:
- uses: actions/checkout@v4
id: checkout
with:
# fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
# TODO: fix once complete
# ref: ${{ github.event.push.head.sha }}
- name: Log in and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ vars.OC_SERVER }}
openshift_token: ${{ secrets.OC_TOKEN }}
namespace: ${{ vars.OC_NAMESPACE }}
- name: Calculate Zone
id: calculateZone
shell: bash
run: |
event_num=${{ github.event.number }}
if [[ -z "${event_num// }" ]]; then
zone=pr-testing
else
zone=pr-$event_num
fi
echo zone: $zone
echo "ZONE=$zone" >> $GITHUB_ENV
- name: Run Helm Chart
id: runHelmChart
shell: bash
env:
IMAGE_TAG: ${{ needs.CalculateImageTags.outputs.imagetag }}
run: |
cd cicd
ls -la
helm upgrade --install snowpack-frontend-${{ env.ZONE }} snowpack-frontend \
--set ostore_secrets.bucket=${{ vars.OBJ_STORE_BUCKET }} \
--set ostore_secrets.secret=${{ secrets.OBJ_STORE_SECRET }} \
--set ostore_secrets.user=${{ secrets.OBJ_STORE_USER }} \
--set ostore_secrets.host=${{ vars.OBJ_STORE_HOST }} \
--set image.image_tag=${{ env.IMAGE_TAG }} \
--set image.promote=bcgov/streamlit_frontend:${{ env.IMAGE_TAG }} \
--set app.zone=${{ env.ZONE }}
- name: Get Route URL
id: getRouteUrl
shell: bash
run: |
# retrieve the route url
# ---------------------------------------------------------
app_name=$(cat ./cicd/snowpack-frontend/values.yaml | yq e '.app.name')
app_comp=$(cat ./cicd/snowpack-frontend/values.yaml | yq e '.app.component')
route_name=$app_name-${{ env.ZONE }}-$app_comp
route_path=$(oc get route $route_name -o json | jq .spec.host | tr -d '"' )
echo "OC_ROUTE=https://$route_path" >> $GITHUB_ENV
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Route to deployed app is: ${{ env.OC_ROUTE }}