Skip to content

Commit 455b3a0

Browse files
authored
Add helm charts & build publish workflows (#6)
* Add helm charts * Rename management service helm chart values * Add build and publish steps * Rename CI workflow file * Temporarily remove publish step * Fix CI build-publish workflows * Add dependencies to build stage workflow * Update golangci-lint * Fix go vendoring step * Download UI cache * Rename treatment service api container * Add helm chart publish workflow * Update README.md with replace directive instructions * Cleanup docs * Test binary artifact upload and download * Combine build publish steps * Rename release CI step
1 parent ac1e68a commit 455b3a0

30 files changed

+1600
-14
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Rules Checker
2+
description: Determines release type based on the git ref and provided rules
3+
4+
inputs:
5+
release_tag_regex:
6+
required: false
7+
description: 'Regex to match the git tag to determine if this a release run of the workflow'
8+
default: 'v[0-9]+(\.[0-9]+){0,2}'
9+
prerelease_tag_regex:
10+
required: false
11+
description: 'Regex to match the git tag to determine if this a pre-release run of the workflow'
12+
default: 'v[0-9]+(\.[0-9]+){0,2}(-([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?'
13+
prefix:
14+
required: false
15+
description: "(Optional) prefix of git tags to use. Example: 'sdk/'"
16+
default: ''
17+
outputs:
18+
release-type:
19+
description: 'Type of the release. One of: [dev, pre-release, release]'
20+
value: ${{ steps.tag-check.outputs.release-type }}
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- run: |
26+
release_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.release_tag_regex }}$'
27+
prerelease_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.prerelease_tag_regex }}$'
28+
if [[ '${{ github.event.ref }}' =~ ${release_regex} ]]; then
29+
echo '::set-output name=release-type::release'
30+
elif [[ '${{ github.event.ref }}' =~ ${prerelease_regex} ]]; then
31+
echo '::set-output name=release-type::pre-release'
32+
else
33+
echo '::set-output name=release-type::dev'
34+
fi
35+
id: tag-check
36+
shell: bash

.github/workflows/helm-chart.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: helm-chart
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/workflows/helm-chart.yml"
7+
- "infra/charts/**"
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
inputs:
12+
owner:
13+
description: The GitHub user or org that owns this repository
14+
type: string
15+
required: true
16+
repository:
17+
description: The GitHub repository
18+
type: string
19+
required: true
20+
default: "charts"
21+
22+
jobs:
23+
release:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Run chart-releaser
28+
uses: stefanprodan/helm-gh-pages@v1.4.1
29+
with:
30+
token: "${{ secrets.GH_PAGES_TOKEN }}"
31+
charts_dir: infra/charts
32+
owner: "${{ github.event.inputs.owner || 'turing-ml' }}"
33+
repository: "${{ github.event.inputs.repository || 'charts' }}"
34+
commit_username: ${{ github.actor }}
35+
commit_email: "${{ github.actor }}@users.noreply.github.com"

.github/workflows/release.yml

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: XP Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
container_registry:
7+
type: string
8+
required: false
9+
default: ghcr.io
10+
environment:
11+
type: string
12+
required: false
13+
secrets:
14+
ghcr_token:
15+
required: true
16+
17+
env:
18+
ARTIFACT_RETENTION_DAYS: 7
19+
20+
jobs:
21+
build-ui:
22+
runs-on: ubuntu-latest
23+
defaults:
24+
run:
25+
working-directory: ui
26+
steps:
27+
- name: Checkout to the target branch
28+
uses: actions/checkout@v3
29+
30+
- uses: actions/setup-node@v3
31+
with:
32+
node-version: 14
33+
34+
- name: Get yarn cache directory path
35+
id: yarn-cache-dir-path
36+
run: echo "::set-output name=dir::$(yarn cache dir)"
37+
38+
- name: Cache YARN
39+
uses: actions/cache@v3
40+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
41+
with:
42+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
43+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-yarn-
46+
47+
- name: Install
48+
run: yarn install --network-concurrency 1
49+
50+
- name: Lint code
51+
run: yarn lint
52+
53+
- name: Build UI
54+
env:
55+
NODE_OPTIONS: "--max_old_space_size=4096"
56+
run: yarn build
57+
58+
- name: Publish Artifact
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: xp-ui-dist
62+
path: ui/build/
63+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
64+
65+
build-management-service:
66+
runs-on: ubuntu-latest
67+
env:
68+
APP_NAME: xp-management
69+
needs:
70+
- build-ui
71+
outputs:
72+
api-version: ${{ steps.build-image.outputs.api-version }}
73+
steps:
74+
- name: Check out code
75+
uses: actions/checkout@v2
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Download UI Dist
80+
uses: actions/download-artifact@v2
81+
with:
82+
name: xp-ui-dist
83+
path: ui/build
84+
85+
- name: Download Management Service binary
86+
uses: actions/download-artifact@v2
87+
with:
88+
name: management-service-binary
89+
path: management-service/bin/
90+
91+
- name: Sync vendor directory
92+
working-directory: management-service
93+
run: |
94+
echo "Fetching dependencies..."
95+
go mod vendor
96+
97+
- name: Build Docker image
98+
id: build-image
99+
run: |
100+
set -o pipefail
101+
make BIN_NAME=$APP_NAME build-image | tee output.log
102+
echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)"
103+
104+
- name: Save Docker image
105+
run: |
106+
docker image save \
107+
--output xp-management.${{ steps.build-image.outputs.api-version }}.tar \
108+
xp-management:${{ steps.build-image.outputs.api-version }}
109+
110+
- name: Publish Artifact
111+
uses: actions/upload-artifact@v3
112+
with:
113+
name: xp-management.${{ steps.build-image.outputs.api-version }}.tar
114+
path: xp-management.${{ steps.build-image.outputs.api-version }}.tar
115+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
116+
117+
build-treatment-service:
118+
runs-on: ubuntu-latest
119+
env:
120+
APP_NAME: xp-treatment
121+
outputs:
122+
api-version: ${{ steps.build-image.outputs.api-version }}
123+
steps:
124+
- name: Check out code
125+
uses: actions/checkout@v2
126+
with:
127+
fetch-depth: 0
128+
129+
- name: Download Treatment Service binary
130+
uses: actions/download-artifact@v2
131+
with:
132+
name: treatment-service-binary
133+
path: treatment-service/bin/
134+
135+
- name: Build Docker image
136+
id: build-image
137+
working-directory: treatment-service
138+
run: |
139+
set -o pipefail
140+
make BIN_NAME=$APP_NAME build-image | tee output.log
141+
echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)"
142+
143+
- name: Save Docker image
144+
run: |
145+
docker image save \
146+
--output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \
147+
xp-treatment:${{ steps.build-image.outputs.api-version }}
148+
149+
- name: Publish Artifact
150+
uses: actions/upload-artifact@v3
151+
with:
152+
name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar
153+
path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar
154+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
155+
156+
publish-management-service:
157+
runs-on: ubuntu-latest
158+
environment: ${{ inputs.environment }}
159+
needs:
160+
- build-management-service
161+
steps:
162+
- name: Log in to the Container registry
163+
uses: docker/login-action@v1
164+
with:
165+
registry: ${{ inputs.container_registry }}
166+
username: ${{ github.actor }}
167+
password: ${{ secrets.ghcr_token }}
168+
169+
- name: Download Docker image tar
170+
uses: actions/download-artifact@v2
171+
with:
172+
name: xp-management.${{ needs.build-management-service.outputs.api-version }}.tar
173+
174+
- name: Publish Docker Image
175+
env:
176+
DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }}
177+
run: |
178+
docker image load --input xp-management.${{ needs.build-management-service.outputs.api-version }}.tar
179+
docker tag \
180+
xp-management:${{ needs.build-management-service.outputs.api-version }} \
181+
${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }}
182+
docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }}
183+
184+
publish-treatment-service:
185+
runs-on: ubuntu-latest
186+
environment: ${{ inputs.environment }}
187+
needs:
188+
- build-treatment-service
189+
steps:
190+
- name: Log in to the Container registry
191+
uses: docker/login-action@v1
192+
with:
193+
registry: ${{ inputs.container_registry }}
194+
username: ${{ github.actor }}
195+
password: ${{ secrets.ghcr_token }}
196+
197+
- name: Download Docker image tar
198+
uses: actions/download-artifact@v2
199+
with:
200+
name: xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar
201+
202+
- name: Publish Docker Image
203+
env:
204+
DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }}
205+
run: |
206+
docker image load --input xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar
207+
docker tag \
208+
xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} \
209+
${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }}
210+
docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }}

.github/workflows/tests.yml .github/workflows/xp.yml

+64-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ on:
1313
pull_request:
1414
branches:
1515
- main
16+
17+
# To make it possible to trigger e2e CI workflow for any arbitrary git ref
18+
workflow_dispatch:
19+
20+
env:
21+
ARTIFACT_RETENTION_DAYS: 7
1622

1723
jobs:
1824
lint-python:
@@ -35,32 +41,33 @@ jobs:
3541
lint-go:
3642
runs-on: ubuntu-latest
3743
steps:
38-
- uses: actions/checkout@v2
3944
- name: Setup Go
4045
id: setup-go
41-
uses: actions/setup-go@v2
46+
uses: actions/setup-go@v3
4247
with:
43-
go-version: "1.16"
48+
go-version: 1.16
49+
- uses: actions/checkout@v3
4450
- name: Lint Common module
45-
uses: golangci/golangci-lint-action@v2
51+
uses: golangci/golangci-lint-action@v3
4652
with:
4753
version: v1.41.1
4854
working-directory: common
49-
skip-go-installation: true
5055
args: --timeout 3m --verbose
5156
- name: Lint Management Service module
52-
uses: golangci/golangci-lint-action@v2
57+
uses: golangci/golangci-lint-action@v3
5358
with:
5459
version: v1.41.1
5560
working-directory: management-service
56-
skip-go-installation: true
61+
skip-pkg-cache: true
62+
skip-build-cache: true
5763
args: --timeout 3m --verbose
5864
- name: Lint Treatment Service module
59-
uses: golangci/golangci-lint-action@v2
65+
uses: golangci/golangci-lint-action@v3
6066
with:
6167
version: v1.41.1
6268
working-directory: treatment-service
63-
skip-go-installation: true
69+
skip-pkg-cache: true
70+
skip-build-cache: true
6471
args: --timeout 3m --verbose
6572

6673
unit-tests-management:
@@ -173,10 +180,58 @@ jobs:
173180
- name: Build binaries
174181
run: make build
175182

183+
- name: Publish Management Service Artifact
184+
uses: actions/upload-artifact@v3
185+
with:
186+
name: management-service-binary
187+
path: management-service/bin/
188+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
189+
190+
- name: Publish Treatment Service Artifact
191+
uses: actions/upload-artifact@v3
192+
with:
193+
name: treatment-service-binary
194+
path: treatment-service/bin/
195+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
196+
176197
- name: Run E2E tests
177198
env:
178199
DATABASE_HOST: localhost
179200
DATABASE_NAME: xp
180201
DATABASE_USER: xp
181202
DATABASE_PASSWORD: xp
182203
run: make e2e-ci
204+
205+
release-rules:
206+
runs-on: ubuntu-latest
207+
outputs:
208+
release-type: ${{ steps.release-rules.outputs.release-type }}
209+
steps:
210+
- uses: actions/checkout@v2
211+
- id: release-rules
212+
uses: ./.github/actions/release-rules
213+
214+
# release:
215+
# # Automatically publish release and pre-release artifacts.
216+
# #
217+
# # As for dev releases, make it possible to publish artifacts
218+
# # manually by approving 'deployment' in the 'manual' environment.
219+
# #
220+
# # Dev build can be released either from the 'main' branch or
221+
# # by running this workflow manually with `workflow_dispatch` event.
222+
# if: >-
223+
# contains('release,pre-release', needs.release-rules.outputs.release-type)
224+
# || ( github.event_name != 'pull_request' )
225+
# || ( github.event.pull_request.head.repo.full_name == github.repository )
226+
# needs:
227+
# - lint-python
228+
# - lint-go
229+
# - unit-tests-management
230+
# - unit-tests-treatment
231+
# - e2e-tests
232+
# - release-rules
233+
# uses: gojek/xp/.github/workflows/release.yml@main
234+
# with:
235+
# environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }}
236+
# secrets:
237+
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)