forked from kapicorp/kapitan
-
Notifications
You must be signed in to change notification settings - Fork 1
239 lines (216 loc) · 7.63 KB
/
test-build-publish.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
---
name: Test, Build and Publish docker image
run-name: Docker Build for ${{ github.actor }} on branch ${{ github.ref_name }}
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
on:
push:
branches:
- master
- main
- test/*
paths-ignore:
- 'docs/**'
- '.github/worklows/documentation.yml'
- 'requirements.docs.txt'
- 'mkdocs.yml'
- 'CNAME'
- 'Dockerfile.docs'
release:
types: [created]
pull_request:
paths-ignore:
- 'docs/**'
- '.github/worklows/documentation.yml'
- 'requirements.docs.txt'
- 'mkdocs.yml'
- 'CNAME'
- 'Dockerfile.docs'
jobs:
lint:
name: linter
runs-on: ubuntu-latest
if: success() || failure() # Continue running if other jobs fail
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- uses: psf/black@main
test:
name: python ${{ matrix.python-version }} tests
runs-on: ubuntu-latest
if: success() || failure() # Continue running if other jobs fail
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
cache: 'pip'
python-version: ${{ matrix.python-version }}
- name: Install testing dependencies
run: |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 762E3157
sudo apt-get -qq update
sudo apt-get install -y gnupg2 git curl
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
sudo ./get_helm.sh
pip3 install --editable ".[test]"
pip3 install coverage black
- name: Run tests
run: |-
# includes make test
make test_coverage
build:
name: build ${{ matrix.platform }} image
if: success() || failure() # Continue running if other jobs fail
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
# Setup QEMU and Buildx to build multi-platform image
# This was inspired by this example : https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Builds docker image and allow scoped caching
- name: build Kapitan Image
uses: docker/build-push-action@v5
with:
push: False
platforms: ${{ matrix.platform }}
load: True
file: Dockerfile
tags: local-test-${{ matrix.platform }}
cache-from: type=gha,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
- name: Test Kapitan for ${{ matrix.platform }}
run: |
docker run -t --rm local-test-${{ matrix.platform }} --version
publish:
name: publish platform images
# Only starts if everything else is successful
needs: [lint, test, build]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
# Setup QEMU and Buildx to build multi-platform image
# This was inspired by this example : https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
with:
# list of Docker images to use as base name for tags
images: |
name=${{ vars.DOCKERHUB_REPOSITORY }}/kapitan
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
suffix=-${{ matrix.platform }}
- name: Build and push by digest
id: push-digest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{steps.meta.output.labels}}
cache-from: type=gha,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
build-multi-architecture:
name: combine platform images
needs:
- publish
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# Setup QEMU and Buildx to build multi-platform image
# This was inspired by this example : https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
with:
# list of Docker images to use as base name for tags
images: |
name=${{ vars.DOCKERHUB_REPOSITORY }}/kapitan
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- uses: int128/docker-manifest-create-action@v1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
tags: ${{ steps.meta.outputs.tags }}
builder: buildx
suffixes: |
-linux-amd64
-linux-arm64