-
Notifications
You must be signed in to change notification settings - Fork 5
177 lines (155 loc) · 5.79 KB
/
main.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
name: Build and Deploy Audit Image
# ToDo:
# - Limit workflow runs to the main repo so it does not try to run on someone else's fork.
on:
workflow_dispatch:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
if: github.repository == 'bcgov/von-bc-regestries-audit' || github.event_name == 'workflow_dispatch'
name: Build Image
permissions:
packages: write
runs-on: ubuntu-latest
outputs:
image_digest: ${{steps.docker_build.outputs.digest}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# - name: Define image tags
# shell: bash
# id: lowercase
# run: |
# TAGS=$( echo "ghcr.io/${{ github.repository }}/audit:latest" | tr '[:upper:]' '[:lower:]' )
# echo "tags=${TAGS}" >> $GITHUB_OUTPUT
# ToDo:
# - Add the Docker meta step back in for defining the tags and labels
# - Add additional tags. `latest` for example.
# This is here as a starter, not as the actual implementation
# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
# with:
# images: ghcr.io/bcgov/von-bc-registries-audit/audit
# tags: |
# <to be defined>
# define as latest, SHA, dev . It should not be hard coded.
- name: Prepare docker tags for image
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/bcgov/von-bc-registries-audit/audit
flavor: |
latest=true
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,value=latest
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }} # add additional tags
labels: ${{ steps.meta.outputs.labels }} # add Docker meta step back in
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Display image results
id: lowercase
run: |
echo 'imageid=${{ steps.docker_build.outputs.imageid }}'
echo 'digest=${{ steps.docker_build.outputs.digest }}'
# ToDo:
# - Define these jobs as a reusable workflow, since the steps are identical.
deploy2dev:
needs: build
permissions:
packages: write
runs-on: ubuntu-latest
environment: dev
# ToDo:
# - Define the 'environment' using an environment variable so it can also be used to define the tags.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: deploy to dev
uses: ./.github/workflows/actions/deploy
with:
secrets: inherit
environment: dev
openshift_server_url: ${{ vars.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
image_digest: ${{ needs.build.outputs.image_digest }}
namespace: ca7f8f-dev
rocketchat_webhook: ${{ secrets.ROCKETCHAT_WEBHOOK }}
rocketchat_token: ${{ inputs.rocketchat_token }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_image_name: ghcr.io/bcgov/von-bc-registries-audit/audit
openshift_image_name: image-registry.apps.silver.devops.gov.bc.ca/ca7f8f-tools/audit
deploy2test:
needs: [build, deploy2dev]
permissions:
packages: write
runs-on: ubuntu-latest
environment: test
# ToDo:
# - Define the 'environment' using an environment variable so it can also be used to define the tags.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: deploy to test
uses: ./.github/workflows/actions/deploy
with:
secrets: inherit
environment: test
password: ${{ secrets.GITHUB_TOKEN }}
openshift_server_url: ${{ vars.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
image_digest: ${{ needs.build.outputs.image_digest }}
namespace: ca7f8f-test
rocketchat_webhook: ${{ secrets.ROCKETCHAT_WEBHOOK }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_image_name: ghcr.io/bcgov/von-bc-registries-audit/audit
openshift_image_name: image-registry.apps.silver.devops.gov.bc.ca/ca7f8f-tools/audit
deploy2prod:
needs: [build, deploy2dev, deploy2test]
permissions:
packages: write
runs-on: ubuntu-latest
environment: prod
# ToDo:
# - Define the 'environment' using an environment variable so it can also be used to define the tags.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: deploy to prod
uses: ./.github/workflows/actions/deploy
with:
secrets: inherit
environment: prod
password: ${{ secrets.GITHUB_TOKEN }}
openshift_server_url: ${{ vars.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
image_digest: ${{ needs.build.outputs.image_digest }}
namespace: ca7f8f-prod
rocketchat_webhook: ${{ secrets.ROCKETCHAT_WEBHOOK }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_image_name: ghcr.io/bcgov/von-bc-registries-audit/audit
openshift_image_name: image-registry.apps.silver.devops.gov.bc.ca/ca7f8f-tools/audit