Skip to content

Commit 946628e

Browse files
authored
Merge pull request #55 from jujaga/feature/ga-pr-pipeline
CI/CD: Implement Github Actions Pull Request flow support
2 parents f71cdb7 + e663f9f commit 946628e

File tree

17 files changed

+197
-539
lines changed

17 files changed

+197
-539
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These users will be the default owners for everything in the repo.
2+
# Unless a later match takes precedence, the following users will be
3+
# requested for review when someone opens a pull request.
4+
* @jujaga @kamorel @TimCsaky

.github/actions/build-push-container/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
using: composite
2525
steps:
2626
- name: Checkout repository
27-
uses: actions/checkout@v2
27+
uses: actions/checkout@v3
2828

2929
- name: Login to Container Registry
3030
uses: docker/login-action@v1

.github/actions/deploy-to-environment/action.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
acronym:
88
description: Application acronym
99
required: true
10+
environment:
11+
description: Logical Github Environment
12+
required: true
1013
job_name:
1114
description: Job/Instance name
1215
required: true
@@ -27,7 +30,7 @@ runs:
2730
using: composite
2831
steps:
2932
- name: Checkout repository
30-
uses: actions/checkout@v2
33+
uses: actions/checkout@v3
3134

3235
- name: Login to OpenShift Cluster
3336
uses: redhat-actions/oc-login@v1
@@ -43,8 +46,10 @@ runs:
4346
helm upgrade --install --atomic ${{ inputs.job_name }} ${{ inputs.app_name }}
4447
--namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }}
4548
--repo https://bcgov.github.io/common-object-management-service
46-
--values ./.github/environments/values.${{ inputs.namespace_environment }}.yaml
49+
--values ./.github/environments/values.${{ inputs.environment }}.yaml
4750
--set image.repository=ghcr.io/${{ github.repository_owner }}
4851
--set image.tag=sha-$(git rev-parse --short HEAD)
4952
--set route.host=${{ inputs.acronym }}-${{ inputs.namespace_environment }}-${{ inputs.job_name }}.apps.silver.devops.gov.bc.ca
5053
--set config.configMap.OBJECTSTORAGE_KEY=${{ inputs.acronym }}/${{ inputs.namespace_environment }}
54+
--timeout 10m
55+
--wait

.github/actions/push-to-registry/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ runs:
2828
using: composite
2929
steps:
3030
- name: Checkout repository
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232

3333
- name: Login to Source Container Registry
3434
if: inputs.source_username != ''

.github/environments/values.pr.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
features:
3+
basicAuth: true
4+
oidcAuth: true
5+
6+
patroni:
7+
enabled: true
8+
replicaCount: 2
9+
resources:
10+
limits:
11+
cpu: 250m
12+
memory: 384Mi
13+
requests:
14+
cpu: 50m
15+
memory: 192Mi
16+
persistentVolume:
17+
enabled: false

.github/workflows/charts-release.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,13 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3
16-
with:
17-
fetch-depth: 0
1816

1917
- name: Configure Git
2018
run: |
2119
git config user.name "$GITHUB_ACTOR"
2220
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
2321
24-
- name: Install Helm
25-
uses: azure/setup-helm@v1
26-
with:
27-
version: v3.8.2
28-
2922
- name: Run chart-releaser
30-
uses: helm/chart-releaser-action@v1.4.0
23+
uses: helm/chart-releaser-action@v1
3124
env:
3225
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/codeql-analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
steps:
4444
- name: Checkout repository
45-
uses: actions/checkout@v2
45+
uses: actions/checkout@v3
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL

.github/workflows/on-pr-closed.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Pull Request Closed
2+
3+
env:
4+
ACRONYM: coms
5+
APP_NAME: common-object-management-service
6+
NAMESPACE_PREFIX: bb17f9
7+
8+
on:
9+
pull_request:
10+
branches:
11+
- master
12+
types:
13+
- closed
14+
15+
jobs:
16+
remove-pr-dev:
17+
name: Remove PR build from dev namespace
18+
if: "! github.event.pull_request.head.repo.fork"
19+
environment:
20+
name: pr
21+
url: https://${{ env.ACRONYM }}-dev-pr-${{ github.event.number }}.apps.silver.devops.gov.bc.ca
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 12
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
- name: Login to OpenShift Cluster
28+
uses: redhat-actions/oc-login@v1
29+
with:
30+
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
31+
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
32+
insecure_skip_tls_verify: true
33+
namespace: ${{ env.NAMESPACE_PREFIX }}-dev
34+
- name: Remove PR Deployment
35+
shell: bash
36+
run: |
37+
helm uninstall --namespace ${{ env.NAMESPACE_PREFIX }}-dev pr-${{ github.event.number }} --timeout 10m --wait
38+
oc delete --namespace ${{ env.NAMESPACE_PREFIX }}-dev cm,secret --selector app.kubernetes.io/instance=pr-${{ github.event.number }}
39+
- name: Remove Release Comment on PR
40+
uses: marocchino/sticky-pull-request-comment@v2
41+
with:
42+
header: release
43+
delete: true
44+
- name: Remove Github Deployment Environment
45+
uses: strumwolf/delete-deployment-environment@v2
46+
with:
47+
environment: pr
48+
onlyRemoveDeployments: true
49+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/on-pr-opened.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Pull Request Opened
2+
3+
env:
4+
ACRONYM: coms
5+
APP_NAME: common-object-management-service
6+
NAMESPACE_PREFIX: bb17f9
7+
8+
on:
9+
pull_request:
10+
branches:
11+
- master
12+
types:
13+
- opened
14+
- reopened
15+
- synchronize
16+
17+
jobs:
18+
build:
19+
name: Build & Push to GHCR
20+
if: "! github.event.pull_request.head.repo.fork"
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 10
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
- name: Build & Push to GHCR
27+
uses: ./.github/actions/build-push-container
28+
with:
29+
context: .
30+
image_name: ${{ env.APP_NAME }}
31+
registry: ghcr.io
32+
username: ${{ github.repository_owner }}
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
35+
deploy-pr-dev:
36+
name: Deploy Pull Request to Dev
37+
environment:
38+
name: pr
39+
url: https://${{ env.ACRONYM }}-dev-pr-${{ github.event.number }}.apps.silver.devops.gov.bc.ca
40+
runs-on: ubuntu-latest
41+
needs: build
42+
timeout-minutes: 12
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v3
46+
- name: Deploy to Dev
47+
uses: ./.github/actions/deploy-to-environment
48+
with:
49+
app_name: ${{ env.APP_NAME }}
50+
acronym: ${{ env.ACRONYM }}
51+
environment: pr
52+
job_name: pr-${{ github.event.number }}
53+
namespace_prefix: ${{ env.NAMESPACE_PREFIX }}
54+
namespace_environment: dev
55+
openshift_server: ${{ secrets.OPENSHIFT_SERVER }}
56+
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
57+
- name: Release Comment on PR
58+
uses: marocchino/sticky-pull-request-comment@v2
59+
if: success()
60+
with:
61+
header: release
62+
message: |
63+
Release ${{ github.sha }} deployed at <https://${{ env.ACRONYM }}-dev-pr-${{ github.event.number }}.apps.silver.devops.gov.bc.ca>

.github/workflows/on-push.yaml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
timeout-minutes: 10
2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v2
24+
uses: actions/checkout@v3
2525
- name: Check Dockerhub Secrets
2626
id: check-secrets
2727
run: |
@@ -54,7 +54,7 @@ jobs:
5454
timeout-minutes: 10
5555
steps:
5656
- name: Checkout
57-
uses: actions/checkout@v2
57+
uses: actions/checkout@v3
5858
- name: Push to Registry
5959
uses: ./.github/actions/push-to-registry
6060
with:
@@ -68,18 +68,21 @@ jobs:
6868

6969
deploy-dev:
7070
name: Deploy to Dev
71-
environment: dev
71+
environment:
72+
name: dev
73+
url: https://${{ env.ACRONYM }}-dev-master.apps.silver.devops.gov.bc.ca
7274
runs-on: ubuntu-latest
7375
needs: build
74-
timeout-minutes: 10
76+
timeout-minutes: 12
7577
steps:
7678
- name: Checkout
77-
uses: actions/checkout@v2
79+
uses: actions/checkout@v3
7880
- name: Deploy to Dev
7981
uses: ./.github/actions/deploy-to-environment
8082
with:
8183
app_name: ${{ env.APP_NAME }}
8284
acronym: ${{ env.ACRONYM }}
85+
environment: dev
8386
job_name: master
8487
namespace_prefix: ${{ env.NAMESPACE_PREFIX }}
8588
namespace_environment: dev
@@ -88,20 +91,23 @@ jobs:
8891

8992
deploy-test:
9093
name: Deploy to Test
91-
environment: test
94+
environment:
95+
name: test
96+
url: https://${{ env.ACRONYM }}-test-master.apps.silver.devops.gov.bc.ca
9297
runs-on: ubuntu-latest
9398
needs:
9499
- build
95100
- deploy-dev
96-
timeout-minutes: 10
101+
timeout-minutes: 12
97102
steps:
98103
- name: Checkout
99-
uses: actions/checkout@v2
104+
uses: actions/checkout@v3
100105
- name: Deploy to Test
101106
uses: ./.github/actions/deploy-to-environment
102107
with:
103108
app_name: ${{ env.APP_NAME }}
104109
acronym: ${{ env.ACRONYM }}
110+
environment: test
105111
job_name: master
106112
namespace_prefix: ${{ env.NAMESPACE_PREFIX }}
107113
namespace_environment: test
@@ -110,21 +116,24 @@ jobs:
110116

111117
deploy-prod:
112118
name: Deploy to Prod
113-
environment: prod
119+
environment:
120+
name: prod
121+
url: https://${{ env.ACRONYM }}-prod-master.apps.silver.devops.gov.bc.ca
114122
runs-on: ubuntu-latest
115123
needs:
116124
- build
117125
- deploy-dev
118126
- deploy-test
119-
timeout-minutes: 10
127+
timeout-minutes: 12
120128
steps:
121129
- name: Checkout
122-
uses: actions/checkout@v2
130+
uses: actions/checkout@v3
123131
- name: Deploy to Prod
124132
uses: ./.github/actions/deploy-to-environment
125133
with:
126134
app_name: ${{ env.APP_NAME }}
127135
acronym: ${{ env.ACRONYM }}
136+
environment: prod
128137
job_name: master
129138
namespace_prefix: ${{ env.NAMESPACE_PREFIX }}
130139
namespace_environment: prod

0 commit comments

Comments
 (0)