-
Notifications
You must be signed in to change notification settings - Fork 2
166 lines (146 loc) · 6.94 KB
/
image-greyscale.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
# Documentation: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses
name: image-greyscale_workflow
run-name: image-greyscale workflow
# Allow one concurrent deployment
concurrency:
group: "image-greyscale"
cancel-in-progress: true
on:
push:
branches:
- main
- prod
paths:
- .github/actions/build-and-push-docker-image-to-github/action.yml
- .github/actions/execute-command-on-kubernetes-cluster/action.yml
- .github/actions/lint-python-app/action.yml
- .github/actions/test-python-app/action.yml
- .github/workflows/image-greyscale.yml
- common-code/**/*
- services/image-greyscale/**/*
pull_request:
paths:
- .github/actions/build-and-push-docker-image-to-github/action.yml
- .github/actions/execute-command-on-kubernetes-cluster/action.yml
- .github/actions/lint-python-app/action.yml
- .github/actions/test-python-app/action.yml
- .github/workflows/image-greyscale.yml
- common-code/**/*
- services/image-greyscale/**/*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Lint Python app
uses: ./.github/actions/lint-python-app
with:
python-app-path: ./services/image-greyscale
test:
needs: review
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Test Python app
uses: ./.github/actions/test-python-app
with:
python-app-path: ./services/image-greyscale
token: ${{ secrets.GITHUB_TOKEN }}
release:
needs: test
runs-on: ubuntu-latest
# Only run on main
if: success() && github.ref == 'refs/heads/main'
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Build and push Docker image to GitHub
id: build-and-push-docker-image-to-github
uses: ./.github/actions/build-and-push-docker-image-to-github
with:
docker-registry-username: ${{ github.actor }}
docker-registry-password: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: swiss-ai-center/image-greyscale
docker-image-context: ./services/image-greyscale
outputs:
docker-image-tags: ${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }}
deploy-dev:
needs: release
runs-on: ubuntu-latest
# Only run on main
if: success() && github.ref == 'refs/heads/main'
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Prepare configuration files
shell: bash
working-directory: services/image-greyscale/kubernetes
env:
ENVIRONMENT: production
LOG_LEVEL: info
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'"
SERVICE_URL: https://image-greyscale-swiss-ai-center.kube.isc.heia-fr.ch
run: |
# Set image-greyscale version
docker_image_tags=(${{ needs.release.outputs.docker-image-tags }})
docker_image_sha_tag="${docker_image_tags[1]}"
yq ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" image-greyscale.stateful.yml > new-image-greyscale.stateful.yml && mv new-image-greyscale.stateful.yml image-greyscale.stateful.yml
# Set image-greyscale configuration (ConfigMap)
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' image-greyscale.config-map.yml | envsubst > new-image-greyscale.config-map.yml && mv new-image-greyscale.config-map.yml image-greyscale.config-map.yml
# Set image-greyscale configuration (Ingress)
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" image-greyscale.ingress.yml > new-image-greyscale.ingress.yml && mv new-image-greyscale.ingress.yml image-greyscale.ingress.yml
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" image-greyscale.ingress.yml > new-image-greyscale.ingress.yml && mv new-image-greyscale.ingress.yml image-greyscale.ingress.yml
- name: Deploy image-greyscale on the Kubernetes cluster
uses: ./.github/actions/execute-command-on-kubernetes-cluster
with:
kube-config: ${{ secrets.KUBE_CONFIG_DEV }}
kube-namespace: swiss-ai-center-dev
kubectl-context: ./services/image-greyscale/kubernetes
kubectl-args: |
apply \
-f image-greyscale.config-map.yml \
-f image-greyscale.stateful.yml \
-f image-greyscale.service.yml \
-f image-greyscale.ingress.yml
deploy-prod:
needs: release
runs-on: ubuntu-latest
# Only run on prod
if: success() && github.ref == 'refs/heads/prod'
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Prepare configuration files
shell: bash
working-directory: services/image-greyscale/kubernetes
env:
ENVIRONMENT: production
LOG_LEVEL: info
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'"
SERVICE_URL: https://image-greyscale-swiss-ai-center.kube.isc.heia-fr.ch
run: |
# Set image-greyscale version
docker_image_tags=(${{ needs.release.outputs.docker-image-tags }})
docker_image_sha_tag="${docker_image_tags[1]}"
yq ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" image-greyscale.stateful.yml > new-image-greyscale.stateful.yml && mv new-image-greyscale.stateful.yml image-greyscale.stateful.yml
# Set image-greyscale configuration (ConfigMap)
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' image-greyscale.config-map.yml | envsubst > new-image-greyscale.config-map.yml && mv new-image-greyscale.config-map.yml image-greyscale.config-map.yml
# Set image-greyscale configuration (Ingress)
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" image-greyscale.ingress.yml > new-image-greyscale.ingress.yml && mv new-image-greyscale.ingress.yml image-greyscale.ingress.yml
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" image-greyscale.ingress.yml > new-image-greyscale.ingress.yml && mv new-image-greyscale.ingress.yml image-greyscale.ingress.yml
- name: Deploy image-greyscale on the Kubernetes cluster
uses: ./.github/actions/execute-command-on-kubernetes-cluster
with:
kube-config: ${{ secrets.KUBE_CONFIG_PROD }}
kube-namespace: swiss-ai-center-prod
kubectl-context: ./services/image-greyscale/kubernetes
kubectl-args: |
apply \
-f image-greyscale.config-map.yml \
-f image-greyscale.stateful.yml \
-f image-greyscale.service.yml \
-f image-greyscale.ingress.yml