Skip to content

Commit 17726f7

Browse files
committed
added new workflows
1 parent 01836f5 commit 17726f7

File tree

2 files changed

+350
-0
lines changed

2 files changed

+350
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: VUE3 Build & Deploy Backend-DEV
2+
3+
env:
4+
# 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context.
5+
# See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values.
6+
# To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions
7+
OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }}
8+
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
9+
# 🖊️ EDIT to set the kube context's namespace after login. Leave blank to use your user's default namespace.
10+
OPENSHIFT_NAMESPACE: ${{GRAD_NAMESPACE_NO_ENV}}-dev
11+
12+
# 🖊️ EDIT to change the image registry settings.
13+
# Registries such as GHCR, Quay.io, and Docker Hub are supported.
14+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
15+
IMAGE_REGISTRY_USER: ${{ github.actor }}
16+
IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
17+
18+
IMAGE_NAME: educ-grad-admin-backend
19+
DOCKER_ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca/docker-remote
20+
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
21+
22+
APP_NAME: "educ-grad-admin"
23+
REPO_NAME: "educ-grad-admin"
24+
BRANCH: "vue3"
25+
APP_NAME_BACKEND: "educ-grad-admin-backend"
26+
NAMESPACE: ${{secrets.GRAD_NAMESPACE_NO_ENV}}
27+
NAMESPACE_TOOLS: ${{secrets.GRAD_NAMESPACE_NO_ENV}}-tools
28+
COMMON_NAMESPACE: ${{secrets.COMMON_NAMESPACE_NO_ENV}}
29+
TAG: "latest-vue3"
30+
TARGET_ENV: "dev"
31+
32+
MIN_CPU: "50m"
33+
MAX_CPU: "100m"
34+
MIN_MEM: "200Mi"
35+
MAX_MEM: "250Mi"
36+
MIN_REPLICAS: "1"
37+
MAX_REPLICAS: "1"
38+
39+
# SITE_URL should have no scheme or port. It will be prepended with https://
40+
HOST_ROUTE: ${{ secrets.SITE_URL }}
41+
42+
on:
43+
workflow_dispatch:
44+
45+
jobs:
46+
openshift-ci-cd:
47+
name: VUE3 Build & Deploy Backend to DEV
48+
# ubuntu-latest can also be used.
49+
runs-on: ubuntu-20.04
50+
environment: vue3-dev
51+
52+
outputs:
53+
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
54+
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
55+
56+
steps:
57+
- name: Check for required secrets
58+
uses: actions/github-script@v4
59+
with:
60+
script: |
61+
const secrets = {
62+
OPENSHIFT_SERVER: `${{ secrets.OPENSHIFT_SERVER }}`,
63+
OPENSHIFT_TOKEN: `${{ secrets.OPENSHIFT_TOKEN }}`,
64+
};
65+
66+
const GHCR = "ghcr.io";
67+
if (`${{ env.IMAGE_REGISTRY }}`.startsWith(GHCR)) {
68+
core.info(`Image registry is ${GHCR} - no registry password required`);
69+
}
70+
else {
71+
core.info("A registry password is required");
72+
secrets["IMAGE_REGISTRY_PASSWORD"] = `${{ secrets.IMAGE_REGISTRY_PASSWORD }}`;
73+
}
74+
75+
const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => {
76+
if (value.length === 0) {
77+
core.error(`Secret "${name}" is not set`);
78+
return true;
79+
}
80+
core.info(`✔️ Secret "${name}" is set`);
81+
return false;
82+
});
83+
84+
if (missingSecrets.length > 0) {
85+
core.setFailed(`❌ At least one required secret is not set in the repository. \n` +
86+
"You can add it using:\n" +
87+
"GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" +
88+
"GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" +
89+
"Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example");
90+
}
91+
else {
92+
core.info(`✅ All the required secrets are set`);
93+
}
94+
95+
- name: Check out repository
96+
uses: actions/checkout@v2
97+
98+
- name: Determine app name
99+
if: env.APP_NAME_BACKEND == ''
100+
run: |
101+
echo "APP_NAME_BACKEND=$(basename $PWD)" | tee -a $GITHUB_ENV
102+
103+
- name: Login to Docker Hub
104+
uses: docker/login-action@v2
105+
with:
106+
registry: ${{ env.DOCKER_ARTIFACTORY_REPO }}
107+
username: ${{ secrets.DOCKER_ARTIFACTORY_USERNAME }}
108+
password: ${{ secrets.DOCKER_ARTIFACTORY_ACCESS_TOKEN }}
109+
110+
# https://github.com/redhat-actions/buildah-build#readme
111+
- name: Build backend from Dockerfile
112+
id: build-image-backend
113+
uses: redhat-actions/buildah-build@v2
114+
with:
115+
image: ${{ env.APP_NAME_BACKEND }}
116+
tags: "latest-vue3"
117+
118+
# If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs
119+
# Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build
120+
# Otherwise, point this to your Dockerfile/Containerfile relative to the repository root.
121+
dockerfiles: |
122+
./backend/Dockerfile
123+
context: ./backend
124+
125+
# https://github.com/redhat-actions/push-to-registry#readme
126+
- name: Push backend to registry
127+
id: push-image-backend
128+
uses: redhat-actions/push-to-registry@v2
129+
with:
130+
image: ${{ steps.build-image-backend.outputs.image }}
131+
tags: ${{ steps.build-image-backend.outputs.tags }}
132+
registry: ${{ env.IMAGE_REGISTRY }}
133+
username: ${{ env.IMAGE_REGISTRY_USER }}
134+
password: ${{ env.IMAGE_REGISTRY_PASSWORD }}
135+
136+
- name: Install oc
137+
uses: redhat-actions/openshift-tools-installer@v1
138+
with:
139+
oc: 4
140+
141+
# https://github.com/redhat-actions/oc-login#readme
142+
- uses: actions/checkout@v2
143+
- name: Deploy
144+
run: |
145+
set -eux
146+
# Login to OpenShift and select project
147+
oc login --token=${{ env.OPENSHIFT_TOKEN }} --server=${{ env.OPENSHIFT_SERVER }}
148+
oc project ${{ env.OPENSHIFT_NAMESPACE }}
149+
# Cancel any rollouts in progress
150+
oc rollout cancel dc/${{ env.IMAGE_NAME }}-dc 2> /dev/null \
151+
|| true && echo "No rollout in progress"
152+
153+
oc project ${{ env.OPENSHIFT_NAMESPACE }}
154+
155+
# Create the image stream if it doesn't exist
156+
oc create imagestream ${{ env.REPO_NAME }}-backend 2> /dev/null || true && echo "Backend image stream in place"
157+
158+
oc tag ${{ steps.push-image-backend.outputs.registry-path }} ${{ env.REPO_NAME }}-backend:${{ env.TAG }}
159+
160+
# Process and apply deployment template
161+
oc process -f tools/openshift/backend-dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=educ-grad-admin -p HOST_ROUTE=educ-grad-admin-${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev.apps.silver.devops.gov.bc.ca -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} | oc apply -n ${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev -f -
162+
163+
# Start rollout (if necessary) and follow it
164+
oc rollout latest-vue3 dc/${{ env.IMAGE_NAME }}-dc 2> /dev/null \
165+
|| true && echo "Rollout in progress"
166+
167+
oc logs -f dc/${{ env.IMAGE_NAME }}-dc
168+
# Get status, returns 0 if rollout is successful
169+
oc rollout status dc/${{ env.IMAGE_NAME }}-dc
170+
171+
- name: ZAP Scan
172+
uses: zaproxy/action-full-scan@v0.3.0
173+
with:
174+
target: "https://educ-grad-admin-${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev.apps.silver.devops.gov.bc.ca"
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: VUE3 Build & Deploy Frontend-DEV
2+
3+
env:
4+
# 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context.
5+
# See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values.
6+
# To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions
7+
OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }}
8+
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
9+
# 🖊️ EDIT to set the kube context's namespace after login. Leave blank to use your user's default namespace.
10+
OPENSHIFT_NAMESPACE: ${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev
11+
12+
# 🖊️ EDIT to change the image registry settings.
13+
# Registries such as GHCR, Quay.io, and Docker Hub are supported.
14+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
15+
IMAGE_REGISTRY_USER: ${{ github.actor }}
16+
IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
17+
18+
IMAGE_NAME: educ-grad-admin-frontend
19+
DOCKER_ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca/docker-remote
20+
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
21+
22+
APP_NAME: "educ-grad-admin"
23+
REPO_NAME: "educ-grad-admin"
24+
BRANCH: "main"
25+
APP_NAME_FRONTEND: "educ-grad-admin-frontend"
26+
NAMESPACE: ${{secrets.GRAD_NAMESPACE_NO_ENV}}
27+
NAMESPACE_TOOLS: ${{secrets.GRAD_NAMESPACE_NO_ENV}}-tools
28+
COMMON_NAMESPACE: 75e61b
29+
TAG: "latest-vue3"
30+
TARGET_ENV: "dev"
31+
32+
# SITE_URL should have no scheme or port. It will be prepended with https://
33+
HOST_ROUTE: ${{ secrets.SITE_URL }}
34+
35+
on:
36+
workflow_dispatch:
37+
38+
jobs:
39+
openshift-ci-cd:
40+
name: Build & Deploy Frontend to DEV
41+
# ubuntu-latest can also be used.
42+
runs-on: ubuntu-20.04
43+
environment: dev
44+
45+
outputs:
46+
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
47+
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
48+
49+
steps:
50+
- name: Check for required secrets
51+
uses: actions/github-script@v4
52+
with:
53+
script: |
54+
const secrets = {
55+
OPENSHIFT_SERVER: `${{ secrets.OPENSHIFT_SERVER }}`,
56+
OPENSHIFT_TOKEN: `${{ secrets.OPENSHIFT_TOKEN }}`,
57+
};
58+
59+
const GHCR = "ghcr.io";
60+
if (`${{ env.IMAGE_REGISTRY }}`.startsWith(GHCR)) {
61+
core.info(`Image registry is ${GHCR} - no registry password required`);
62+
}
63+
else {
64+
core.info("A registry password is required");
65+
secrets["IMAGE_REGISTRY_PASSWORD"] = `${{ secrets.IMAGE_REGISTRY_PASSWORD }}`;
66+
}
67+
68+
const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => {
69+
if (value.length === 0) {
70+
core.error(`Secret "${name}" is not set`);
71+
return true;
72+
}
73+
core.info(`✔️ Secret "${name}" is set`);
74+
return false;
75+
});
76+
77+
if (missingSecrets.length > 0) {
78+
core.setFailed(`❌ At least one required secret is not set in the repository. \n` +
79+
"You can add it using:\n" +
80+
"GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" +
81+
"GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" +
82+
"Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example");
83+
}
84+
else {
85+
core.info(`✅ All the required secrets are set`);
86+
}
87+
88+
- name: Check out repository
89+
uses: actions/checkout@v2
90+
91+
- name: Determine app name
92+
if: env.APP_NAME_FRONTEND == ''
93+
run: |
94+
echo "APP_NAME_FRONTEND=$(basename $PWD)" | tee -a $GITHUB_ENV
95+
96+
- name: Login to Docker Hub
97+
uses: docker/login-action@v2
98+
with:
99+
registry: ${{ env.DOCKER_ARTIFACTORY_REPO }}
100+
username: ${{ secrets.DOCKER_ARTIFACTORY_USERNAME }}
101+
password: ${{ secrets.DOCKER_ARTIFACTORY_ACCESS_TOKEN }}
102+
103+
# https://github.com/redhat-actions/buildah-build#readme
104+
- name: Build frontend from Dockerfile
105+
id: build-image-frontend
106+
uses: redhat-actions/buildah-build@v2
107+
with:
108+
image: ${{ env.APP_NAME_FRONTEND }}
109+
tags: "latest-vue3"
110+
111+
# If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs
112+
# Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build
113+
# Otherwise, point this to your Dockerfile/Containerfile relative to the repository root.
114+
dockerfiles: |
115+
./frontend/Dockerfile
116+
context: ./frontend
117+
118+
# https://github.com/redhat-actions/push-to-registry#readme
119+
- name: Push frontend to registry
120+
id: push-image-frontend
121+
uses: redhat-actions/push-to-registry@v2
122+
with:
123+
image: ${{ steps.build-image-frontend.outputs.image }}
124+
tags: ${{ steps.build-image-frontend.outputs.tags }}
125+
registry: ${{ env.IMAGE_REGISTRY }}
126+
username: ${{ env.IMAGE_REGISTRY_USER }}
127+
password: ${{ env.IMAGE_REGISTRY_PASSWORD }}
128+
129+
- name: Install oc
130+
uses: redhat-actions/openshift-tools-installer@v1
131+
with:
132+
oc: 4
133+
134+
# https://github.com/redhat-actions/oc-login#readme
135+
- uses: actions/checkout@v2
136+
- name: Build frontend static
137+
id: build-image-frontend-static
138+
run: |
139+
set -eux
140+
# Login to OpenShift and select project
141+
oc login --token=${{ env.OPENSHIFT_TOKEN }} --server=${{ env.OPENSHIFT_SERVER }}
142+
oc project ${{ env.OPENSHIFT_NAMESPACE }}
143+
144+
# Create the image stream if it doesn't exist
145+
oc create imagestream ${{ env.REPO_NAME }}-frontend 2> /dev/null || true && echo "Frontend image stream in place"
146+
oc tag ${{ steps.push-image-frontend.outputs.registry-path }} ${{ env.REPO_NAME }}-frontend:${{ env.TAG }}
147+
148+
# https://github.com/redhat-actions/oc-login#readme
149+
- uses: actions/checkout@v2
150+
- name: Deploy
151+
run: |
152+
set -eux
153+
# Login to OpenShift and select project
154+
oc login --token=${{ env.OPENSHIFT_TOKEN }} --server=${{ env.OPENSHIFT_SERVER }}
155+
oc project ${{ env.OPENSHIFT_NAMESPACE }}
156+
157+
# Cancel any rollouts in progress
158+
oc rollout cancel dc/${{ env.IMAGE_NAME }}-dc 2> /dev/null \
159+
|| true && echo "No rollout in progress"
160+
161+
# Process and apply deployment template
162+
oc process -f tools/openshift/frontend-dc.yaml -p REPO_NAME=educ-grad-admin \
163+
-p HOST_ROUTE=educ-grad-admin-${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev.apps.silver.devops.gov.bc.ca -p NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} \
164+
-p APP_NAME=educ-grad-admin -p TAG=latest-vue3 -p MIN_REPLICAS=2 -p MAX_REPLICAS=3 -p MIN_CPU=50m -p MAX_CPU=100m \
165+
-p MIN_MEM=200Mi -p MAX_MEM=250Mi | oc apply -n ${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev -f -
166+
167+
# Start rollout (if necessary) and follow it
168+
oc rollout latest-vue3 dc/${{ env.IMAGE_NAME }}-dc 2> /dev/null \
169+
|| true && echo "Rollout in progress"
170+
oc logs -f dc/${{ env.IMAGE_NAME }}-dc
171+
# Get status, returns 0 if rollout is successful
172+
oc rollout status dc/${{ env.IMAGE_NAME }}-dc
173+
- name: ZAP Scan
174+
uses: zaproxy/action-full-scan@v0.3.0
175+
with:
176+
target: "https://educ-grad-admin-${{secrets.GRAD_NAMESPACE_NO_ENV}}-dev.apps.silver.devops.gov.bc.ca"

0 commit comments

Comments
 (0)