-
Notifications
You must be signed in to change notification settings - Fork 4
259 lines (224 loc) · 7.58 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: CI
on:
release:
types: [published, prereleased, edited]
push:
branches:
- master
paths-ignore:
- '**.md'
pull_request:
types:
- opened
- synchronize
paths-ignore:
- '**.md'
jobs:
build-docker:
name: Build Dockerfile-controller
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile-controller
tags: equinor/gordo-controller:latest
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: equinor/gordo-controller:latest
format: 'table'
exit-code: '10'
ignore-unfixed: true
hide-progress: true
severity: 'CRITICAL,HIGH'
timeout: '5m'
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
fmt:
name: Check format ${{ matrix.rust }}
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- name: cargo fmt
run: |
cargo fmt --check
test:
name: Test ${{ matrix.rust }} on ${{ matrix.os }}
needs: build-docker
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [stable]
env:
KUBERNETES_VERSION: v1.23.15
MINIKUBE_VERSION: v1.27.1
MINIKUBE_SHA256: "159bc79f3914dadb7c9f56b6e9d5b73a1c54acb26dca8f1ea84b99ff5da42620"
MINIKUBE_HOME: /home/runner
KUBECONFIG: /home/runner/.kube/config
CHANGE_MINIKUBE_NONE_USER: "true"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- name: Cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ runner.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile-controller
tags: ${{ steps.prep.outputs.base_image }}
load: true
cache-from: type=local,src=/tmp/.buildx-cache
- name: Install kubectl
run: |
sudo curl -L -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl
sudo chmod +x /usr/bin/kubectl
- name: Install kustomize
run: |
sudo curl -L -o /usr/bin/kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
sudo chmod +x /usr/bin/kustomize
- name: Build all kustomize overlays
run: |
sudo kustomize build k8s/production
sudo kustomize build k8s/minikube
- name: Install minikube
run: |
set -e
sudo apt-get update
sudo apt-get install -y conntrack
sudo curl -L -o /usr/bin/minikube https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-linux-amd64
echo "${MINIKUBE_SHA256} /usr/bin/minikube" | sha256sum -c --status
sudo chmod +x /usr/bin/minikube
- name: Start minikube
run: |
sudo -E /usr/bin/minikube start --kubernetes-version=${KUBERNETES_VERSION} --vm-driver=none --container-runtime=docker || journalctl -xeu kubelet
sudo chown -R $USER $HOME/.minikube $HOME/.kube
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile-controller
tags: equinor/gordo-controller:latest
load: true
cache-from: type=local,src=/tmp/.buildx-cache-new
- name: Run gordo-controller on minikube
run: |
kubectl apply -k k8s/minikube -n default || echo "Skipping on Istio error"
bash scripts/wait_gordo_controller.sh
- name: Test CRDs
run: |
kubectl get gordos > /dev/null
kubectl get models > /dev/null
- name: Unit tests
env:
KUBERNETES_SERVICE_HOST: localhost
KUBERNETES_SERVICE_PORT: 8443
RUST_BACKTRACE: 1
run:
cargo test --tests -- --test-threads=1
- name: Integration Tests
env:
DEPLOY_IMAGE: "gordo-infrastructure/gordo-deploy"
DOCKER_REGISTRY: "docker.io"
run: |
bash scripts/integration_tests.sh
push-image:
name: Push docker images
needs: build-docker
runs-on: ubuntu-latest
permissions:
packages: write
env:
IMAGE_LICENSE: AGPL-3.0
IMAGE_HOME_URL: https://github.com/equinor/gordo-controller
DOCKER_REGISTRY: ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Prepare variables
id: prep
run: |
python3 scripts/github_docker.py -r equinor -i gordo-controller
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to CR
uses: docker/login-action@v2
if: ${{ steps.prep.outputs.login_cr }}
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
if: ${{ steps.prep.outputs.push_image }}
with:
push: true
context: .
file: ./Dockerfile-controller
tags: ${{ steps.prep.outputs.tags_gordo_base }}
cache-from: type=local,src=/tmp/.buildx-cache
labels: |
org.opencontainers.image.title=gordo-controller
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.source=${{ env.IMAGE_HOME_URL }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ env.IMAGE_LICENSE }}