Skip to content

Commit d10ec02

Browse files
feat: add github action deployment pipeline (#28)
1 parent 56b9ce5 commit d10ec02

File tree

5 files changed

+83
-40
lines changed

5 files changed

+83
-40
lines changed

.github/actions/cloud-platform-deploy/action.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ runs:
2929
steps:
3030
- uses: actions/checkout@v3
3131

32+
- name: Get environment details
33+
uses: ./.github/actions/get-env-details
34+
id: env
35+
with:
36+
environment: ${{ inputs.environment }}
37+
3238
- name: Authenticate
3339
uses: ./.github/actions/cloud-platform-auth
3440
with:
@@ -43,10 +49,9 @@ runs:
4349
run: |
4450
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
4551
brew install helm
46-
cd helm_deploy/${{ github.event.repository.name }}
47-
yq -i ".appVersion = \"${{ inputs.version }}\"" "Chart.yaml"
48-
helm dependency update .
49-
exec helm upgrade '${{ github.event.repository.name }}' . \
52+
yq -i ".appVersion = \"${{ inputs.version }}\"" "helm_deploy/${{ github.event.repository.name }}/Chart.yaml"
53+
helm dependency update "helm_deploy/${{ github.event.repository.name }}"
54+
exec helm upgrade '${{ github.event.repository.name }}' 'helm_deploy/${{ github.event.repository.name }}' \
5055
--atomic \
5156
--history-max 10 \
5257
--force \
@@ -55,5 +60,5 @@ runs:
5560
--set 'generic-service.image.tag=${{ inputs.version }}' \
5661
--set 'version=${{ inputs.version }}' \
5762
--timeout 10m \
58-
--values '${{ steps.env.outputs.values-file }}' \
63+
--values 'helm_deploy/${{ steps.env.outputs.values-file }}' \
5964
--wait
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Get environment details
2+
description: Map the GitHub environment name to the corresponding Namespace environment details
3+
4+
inputs:
5+
environment:
6+
description: GitHub environment name
7+
required: true
8+
9+
outputs:
10+
values-file:
11+
description: The filename for the values file containing environment configuration
12+
value: ${{ steps.cloud-platform.outputs.values-file }}
13+
cloud-platform-namespace:
14+
description: The name of the corresponding Cloud Platform namespace
15+
value: ${{ steps.cloud-platform.outputs.namespace }}
16+
17+
runs:
18+
using: "composite"
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Map GitHub environment to Cloud Platform namespace
23+
id: cloud-platform
24+
shell: bash
25+
run: |
26+
if [ '${{ inputs.environment }}' == 'development' ]; then namespace='dev'; fi
27+
if [ '${{ inputs.environment }}' == 'production' ]; then namespace='prod'; fi
28+
echo "namespace=${namespace}" | tee -a "$GITHUB_OUTPUT"
29+
echo "values-file=values-${namespace}.yaml" | tee -a "$GITHUB_OUTPUT"

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name: Build
22

3-
permissions:
4-
packages: write
5-
contents: read
6-
73
on:
84
workflow_call:
95
inputs:

.github/workflows/deploy.yml

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ name: Deploy
22

33
on:
44
workflow_call:
5-
inputs:
6-
github_environment:
7-
description: The name of the github environment for deployment secrets
8-
type: string
9-
required: true
5+
inputs:
106
environment:
11-
description: The name of the environment to deploy to
7+
description: The name of the environment to deploy to (dev/prod)
128
type: string
139
required: true
1410
version:
@@ -18,19 +14,13 @@ on:
1814

1915
workflow_dispatch:
2016
inputs:
21-
github_environment:
22-
description: The name of the github environment for deployment secrets
23-
type: choice
24-
required: true
25-
options:
26-
- development
27-
- production
2817
environment:
2918
description: Environment
3019
type: choice
3120
required: true
3221
options:
33-
- dev
22+
- development
23+
- production
3424
version:
3525
description: Image version
3626
type: string
@@ -41,18 +31,23 @@ jobs:
4131
runs-on: ubuntu-latest
4232
strategy:
4333
fail-fast: false
34+
4435
environment:
45-
name: ${{ inputs.github_environment }}
36+
name: ${{ inputs.environment }}
4637
steps:
47-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@v4
39+
- uses: ./.github/actions/get-env-details
40+
id: env
41+
with:
42+
environment: ${{ inputs.environment }}
4843

49-
- name: Deploy to Cloud Platform
44+
- name: Deploy to Platform
5045
uses: ./.github/actions/cloud-platform-deploy
5146
with:
5247
environment: ${{ inputs.environment }}
5348
version: ${{ inputs.version }}
54-
api: https://${{ secrets.DEVELOPMENT_KUBE_CLUSTER }}
55-
cert: ${{ secrets.DEVELOPMENT_KUBE_CERT }}
56-
cluster: ${{ secrets.DEVELOPMENT_KUBE_CLUSTER }}
57-
namespace: ${{ secrets.DEVELOPMENT_KUBE_NAMESPACE }}
58-
token: ${{ secrets.DEVELOPMENT_KUBE_TOKEN }}
49+
api: https://${{ secrets.KUBE_CLUSTER }}
50+
cert: ${{ secrets.KUBE_CERT }}
51+
cluster: ${{ secrets.KUBE_CLUSTER }}
52+
namespace: ${{ secrets.KUBE_NAMESPACE }}
53+
token: ${{ secrets.KUBE_TOKEN }}

.github/workflows/pipeline.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
name: Pipeline
22

3-
permissions:
4-
packages: write
5-
contents: read
6-
73
on:
84
push:
95
branches:
106
- main
11-
workflow_dispatch: # Can be triggered manually from a branch
7+
8+
workflow_dispatch:
9+
inputs:
10+
environment:
11+
description: Environment
12+
type: choice
13+
required: true
14+
options:
15+
- development
16+
- production
17+
version:
18+
description: Image version
19+
type: string
20+
required: true
1221

1322
jobs:
1423
build:
@@ -17,13 +26,22 @@ jobs:
1726
with:
1827
push: true
1928
secrets: inherit
20-
21-
deploy-to-dev:
29+
30+
deploy_to_dev:
2231
name: Deploy to dev
2332
uses: ./.github/workflows/deploy.yml
2433
needs: build
2534
with:
26-
github_environment: development
27-
environment: dev
35+
environment: development
36+
version: ${{ needs.build.outputs.version }}
37+
secrets: inherit
38+
39+
deploy_to_prod:
40+
name: Deploy to prod
41+
uses: ./.github/workflows/deploy.yml
42+
needs:
43+
- deploy_to_dev # wait for the deploy_to_dev job to complete
44+
with:
45+
environment: production
2846
version: ${{ needs.build.outputs.version }}
2947
secrets: inherit

0 commit comments

Comments
 (0)