-
Notifications
You must be signed in to change notification settings - Fork 7
207 lines (183 loc) · 7.37 KB
/
forms-flow-bpm-cd.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
206
207
name: forms-flow-bpm-deploy
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
default: 'dev'
type: choice
options:
- dev
- test
- production
push:
branches: [main]
paths:
- "forms-flow-bpm/**"
- "deployment/openshift/bpm_bc.yaml"
- "deployment/openshift/bpm_dc.yaml"
- ".github/workflows/forms-flow-bpm-cd.yml"
- "deployment/openshift/helm-camunda/**"
defaults:
run:
shell: bash
env:
BUILD_NAMESPACE: ${{ secrets.BUILD_NAMESPACE }}
OPENSHIFT_TOKEN: ${{ secrets.SA_TOKEN }}
OPENSHIFT_USERNAME: ${{ secrets.SA_USERNAME }}
OPENSHIFT_REGISTRY_TOKEN: ${{ secrets.SA_USERNAME_TOKEN }}
OPENSHIFT_SERVER_URL: ${{ secrets.OPENSHIFT_SERVER_URL }}
OPENSHIFT_IMAGE_REGISTRY_URL: ${{ secrets.OPENSHIFT_IMAGE_REGISTRY_URL }}
APP_NAME: forms-flow-bpm
ENVIRONMENT: ${{ !github.event.inputs.environment && 'dev' || github.event.inputs.environment }}
BRANCH: ${{ github.ref_name }}
DOCKER_FILE_NAME: Dockerfile.prod
# Namespace for the triggered environment, e.g., d89793-dev
NAMESPACE: ${{ secrets.NAMESPACE }}
WEBSOCKET_ENCRYPT_KEY: ${{ secrets.WEBSOCKET_ENCRYPT_KEY }}
WEBSOCKET_SECURITY_ORIGIN: ${{ secrets.WEBSOCKET_SECURITY_ORIGIN }}
# Camunda related config params
CAMUNDA_URL: ${{ secrets.CAMUNDA_URL }}
SMTP_SERVER: "apps.smtp.gov.bc.ca"
DATABASE_SERVICE_NAME: patroni
DATABASE_NAME: formsflow-bpm
jobs:
# Logs environment variables
Print-envs:
name: Print environment variables
runs-on: ubuntu-latest
steps:
- name: Print environment variables
run: |
echo BUILD_NAMESPACE: $BUILD_NAMESPACE
echo OPENSHIFT_TOKEN: $OPENSHIFT_TOKEN
echo OPENSHIFT_USERNAME: $OPENSHIFT_USERNAME
echo OPENSHIFT_REGISTRY_TOKEN: $OPENSHIFT_REGISTRY_TOKEN
echo OPENSHIFT_SERVER_URL: $OPENSHIFT_SERVER_URL
echo OPENSHIFT_IMAGE_REGISTRY_URL: $OPENSHIFT_IMAGE_REGISTRY_URL
echo APP_NAME: $APP_NAME
echo ENVIRONMENT: $ENVIRONMENT
echo branch: $BRANCH
echo docker file name: $DOCKER_FILE_NAME
echo namespace: $NAMESPACE
echo CAMUNDA_URL: $CAMUNDA_URL
##################################### Build and push Image #####################################
# Apply buildConfigs on Openshift
apply-openshift-buildConfigs:
name: Apply openshift buildConfigs
if: github.repository == 'bcgov/digital-journeys'
runs-on: ubuntu-latest
steps:
- name: Log in to OpenShift
run: |
oc login --token=${OPENSHIFT_TOKEN} --server=${OPENSHIFT_SERVER_URL}
- name: Checkout repository
uses: actions/checkout@v3
- name: apply openshift buildConfigs
working-directory: ./deployment/openshift
run: |
oc -n ${BUILD_NAMESPACE} process -f bpm_bc.yaml | oc -n ${BUILD_NAMESPACE} apply -f -
build-and-push-image:
name: Build the image and push it to the registry
if: github.repository == 'bcgov/digital-journeys'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs:
- apply-openshift-buildConfigs
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.OPENSHIFT_IMAGE_REGISTRY_URL }}/${{ env.BUILD_NAMESPACE }}/${{ env.APP_NAME }}
tags: ${{ env.ENVIRONMENT }}
- run: echo ${{ steps.meta.outputs.tags }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.OPENSHIFT_IMAGE_REGISTRY_URL }}/${{ env.BUILD_NAMESPACE }}
username: ${{ env.OPENSHIFT_USERNAME }}
password: ${{ env.OPENSHIFT_REGISTRY_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.APP_NAME }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.APP_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: ${{ env.APP_NAME }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ${{ env.APP_NAME }}/${{ env.DOCKER_FILE_NAME }}
# ##################################### Deployment #####################################
apply-deploymentConfigs:
name: Apply deploymentConfigs
if: github.repository == 'bcgov/digital-journeys'
environment: ${{ !github.event.inputs.environment && 'dev' || github.event.inputs.environment }}
runs-on: ubuntu-latest
needs:
- apply-openshift-buildConfigs
- build-and-push-image
steps:
- name: Checkout Target Branch
uses: actions/checkout@v3
- name: Log in to OpenShift
run: |
oc login --token=${OPENSHIFT_TOKEN} --server=${OPENSHIFT_SERVER_URL}
- name: apply deploymentConfig
working-directory: ./deployment/openshift
run: |
test -n "${NAMESPACE}"
test -n "${BUILD_NAMESPACE}"
test -n "${BRANCH}"
echo "Current ENV is ${ENVIRONMENT}"
oc project ${NAMESPACE}
echo "Current namespace is ${NAMESPACE}"
helm upgrade -i helm-forms-flow-bpm ./helm-camunda
# --set TOOLS_WORKSPACE=${BUILD_NAMESPACE} \
# --set SMTP_SERVER=${SMTP_SERVER} \
# --set DATABASE_SERVICE_NAME=${DATABASE_SERVICE_NAME} \
# --set DATABASE_NAME=${DATABASE_NAME} \
# --set IMAGE_TAG=${ENVIRONMENT} \
# --set CAMUNDA_URL="${CAMUNDA_URL}" \
# --set WEBSOCKET_ENCRYPT_KEY=${WEBSOCKET_ENCRYPT_KEY} \
# --set WEBSOCKET_SECURITY_ORIGIN="${WEBSOCKET_SECURITY_ORIGIN}" \
oc -n ${NAMESPACE} process helm-forms-flow-bpm \
-p TOOLS_WORKSPACE=${BUILD_NAMESPACE} \
-p SMTP_SERVER=${SMTP_SERVER} \
-p DATABASE_SERVICE_NAME=${DATABASE_SERVICE_NAME} \
-p DATABASE_NAME=${DATABASE_NAME} \
-p IMAGE_TAG=${ENVIRONMENT} \
-p CAMUNDA_URL="${CAMUNDA_URL}" \
-p WEBSOCKET_ENCRYPT_KEY=${WEBSOCKET_ENCRYPT_KEY} \
-p WEBSOCKET_SECURITY_ORIGIN="${WEBSOCKET_SECURITY_ORIGIN}" | \
oc -n ${NAMESPACE} apply -f -
- name: verify deploymentConfig
run: |
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
ROLLOUT_STATUS_CMD="oc rollout status dc/${APP_NAME} -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
oc project ${NAMESPACE}
echo "Listing pods.."
oc get pods|grep "${APP_NAME}"
export ROUTE="$(oc get route ${APP_NAME} -o jsonpath='{.spec.host}')"
echo "${APP_NAME} is exposed at 'https://'${ROUTE}"