-
Notifications
You must be signed in to change notification settings - Fork 1
211 lines (187 loc) · 6.27 KB
/
ci-containers.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
---
name: Build containers and push a release on tag
on:
workflow_dispatch:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
build-container-images:
outputs:
digest: ${{ steps.outputs.outputs.digest }}
permissions:
contents: read
packages: write
name: Build container image
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata from Github
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
# Ensure we strip any 'v' prefix, provide a SHA and a latest tag only for default branch (master)
tags: |
type=semver,pattern={{version}},event=tag
type=sha,prefix=,suffix=,format=short
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
# defaults for others
type=schedule
type=ref,event=branch
type=ref,event=pr
- name: Build the vivo image
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: "vivo_base_path=/vivo"
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
push: true
load: false
target: production
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
shell: bash
- name: Set up outputs
id: outputs
run: |
echo "digest=${{ steps.docker_build.outputs.digest }}" >> $GITHUB_OUTPUT
shell: bash
test-container-images:
name: Test container images
needs:
- build-container-images
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind
config: ./kind/config.yaml
- name: Apply local service using image from this run
run: |
sed -i 's|image: calyptia/vivo|image: ghcr.io/chronosphereio/calyptia-vivo@${{ needs.build-container-images.outputs.digest }}|g' ./vivo-deployment.yaml
cat ./vivo-deployment.yaml
kubectl apply -f ./vivo-deployment.yaml
shell: bash
- name: Check it is running ok
timeout-minutes: 5
run: |
echo "Waiting for deployment to complete..."
until kubectl rollout status deployment calyptia-vivo --timeout=2s; do
kubectl describe deployment calyptia-vivo
sleep 2
done
echo
echo "Deployment completed successfully"
kubectl get all
shell: bash
- name: Inject HTTP traffic
timeout-minutes: 2
run: |
./kind/curl-port-forward.sh --fail -H 'Content-Type: application/json' -d '{"hello":"world!"}'
shell: bash
- name: Debug on failure
continue-on-error: true
if: failure()
run: |
kubectl cluster-info || true
kubectl get all || true
kubectl describe pod --selector=app.kubernetes.io/name=vivo || true
kubectl get events || true
kubectl get pods --all-namespaces -o wide --show-labels || true
kubectl logs "$(kubectl get pod --selector=app.kubernetes.io/name=vivo --output=jsonpath={.items..metadata.name})" || true
wget https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
/bin/bash ./kubetail --follow false --previous false --colored-output false --namespace default || true
/bin/bash ./kubetail --follow false --previous false --colored-output false --namespace kube-system || true
kubectl describe pods
kubectl describe services
shell: bash
release-container-images-on-tag:
if: startsWith(github.ref, 'refs/tags/')
name: Create release image for vivo
needs:
- build-container-images
- test-container-images
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- 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
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get Docker tags
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
calyptia/vivo
calyptiaci/vivo
tags: |
type=semver,pattern={{version}}
type=raw,value=latest
- name: Build the vivo image
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: "vivo_base_path=/vivo"
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
target: production
- name: Images digests
run: echo ${{ steps.docker_build.outputs.digest }}
shell: bash
- uses: sigstore/cosign-installer@main
- name: Sign Container Image
continue-on-error: true
run: |
cosign sign --recursive --yes calyptia/vivo@${{ steps.docker_build.outputs.digest }}
shell: bash
release-on-tag:
name: Create release
needs:
- release-container-images-on-tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Release on tag
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true