-
Notifications
You must be signed in to change notification settings - Fork 9
237 lines (213 loc) · 7.39 KB
/
ci.yaml
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
name: CI
on:
push:
branches: [main]
pull_request:
release:
types: [published]
jobs:
# Run black linting
# https://github.com/psf/black
lint-black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-black-${{ hashFiles('test-requirements.txt', 'pyproject.toml', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run black formatting
run: |
echo "::add-matcher::.github/matchers/black.json"
tox -e black
# Run pylint static code analysis
# https://www.pylint.org/
lint-pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-pylint-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run pylint
run: |
echo "::add-matcher::.github/matchers/pylint.json"
tox -e pylint
# Run python unit tests
# https://docs.python.org/3/library/unittest.html
tests-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-pylint-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run unit tests
run: |
tox -e unit
# Build and Push the base Docker image with no plugins
build-base-image:
runs-on: ubuntu-latest
needs:
- lint-black
- lint-pylint
- tests-unit
steps:
-
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Tag the base image
id: meta
uses: docker/metadata-action@v4
with:
images: |
bitovi/bitops
# disable automatic 'latest' tag generation
flavor: latest=false
# https://bitops.sh/versioning/
tags: |
# On 'main' branch update push 'dev-base' Docker tag
type=raw,value=dev-base,enable=${{ github.ref_name == 'main' }}
# On release push versioned '1.2.3-base' Docker tag
type=semver,pattern={{version}}-base,enable=${{ github.event_name == 'release' }}
# On release update additional 'base' Docker tag to refer to the latest stable base
type=raw,value=base,enable=${{ github.event_name == 'release' }}
-
name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Build base Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
-
# TODO: Save the image as a GitHub artifact on a PR
# See: https://github.com/docker/build-push-action/issues/225#issuecomment-727639184
name: Push base Docker image
uses: docker/build-push-action@v4
if: ${{ (github.ref_name == 'main') || (github.event_name == 'release') }}
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
push: true
# Build and Push the predefined BitOps Docker image(s)
build-prebuilt-images:
runs-on: ubuntu-latest
needs:
- build-base-image
strategy:
fail-fast: false
matrix:
target:
- aws-ansible
- aws-helm
- aws-terraform
- omnibus
steps:
-
uses: actions/checkout@v3
-
name: Build FROM 'dev-base' Dockerfile
uses: cuchi/jinja2-action@v1.2.0
if: ${{ (github.ref_name == 'main') || (github.event_name == 'pull_request') }}
with:
template: prebuilt-config/dockerfile.template
output_file: ./Dockerfile
variables: tag=dev-base
-
name: Build FROM '1.2.3-base' Dockerfile
uses: cuchi/jinja2-action@v1.2.0
if: github.event_name == 'release'
with:
template: prebuilt-config/dockerfile.template
output_file: ./Dockerfile
# tag=v1.2.3-base -> tag=1.2.3-base is converted in the Dockerfile.template Jinja
variables: tag=${{ github.event.release.tag_name }}-base
-
name: Use ${{ matrix.target }} bitops.config.yaml
run: cp ./prebuilt-config/${{ matrix.target }}/bitops.config.yaml ./bitops.config.yaml
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Tag the Docker image
id: meta
uses: docker/metadata-action@v4
with:
images: |
bitovi/bitops
# disable automatic 'latest' tag generation
flavor: latest=false
# https://bitops.sh/versioning/
tags: |
# DEVELOPMENT
# On 'main' branch push, - build 'omnibus' image and publish it as 'dev' Docker tag
type=raw,value=dev,enable=${{ (github.ref_name == 'main') && (matrix.target == 'omnibus') }}
# RELEASE
# On a versioned release push '2.0.0-omnibus', '2.0.0-aws-ansible', etc Docker tags
type=semver,pattern={{version}}-${{ matrix.target }},enable=${{ github.event_name == 'release' }}
# If omnibus release, push additional versioned '1.2.3' Docker tag
type=semver,pattern={{version}},enable=${{ (github.event_name == 'release') && (matrix.target == 'omnibus') }}
# On release update additional 'latest' Docker tag for Omnibus image
type=raw,value=latest,enable=${{ (github.event_name == 'release') && (matrix.target == 'omnibus') }}
-
name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
-
name: Push Docker image
uses: docker/build-push-action@v4
if: ${{ (github.ref_name == 'main') && (matrix.target == 'omnibus') || (github.event_name == 'release') }}
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
push: true