-
Notifications
You must be signed in to change notification settings - Fork 0
252 lines (220 loc) · 7.69 KB
/
docker-build.yml
File metadata and controls
252 lines (220 loc) · 7.69 KB
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
# ABOUTME: GitHub Actions workflow for building and pushing OpenSPP Docker images
# ABOUTME: Builds multi-architecture images and pushes to ACN Nexus registry
name: Docker Build and Push
on:
push:
branches:
- main
- master
- develop
- 'release/**'
tags:
- 'v*'
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- main
- master
- develop
schedule:
# Run weekly on Mondays at 2 AM UTC
- cron: '0 2 * * 1'
workflow_dispatch:
inputs:
push_images:
description: 'Push images to registry'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
env:
REGISTRY: docker-push.acn.fr
PUBLIC_REGISTRY: docker.acn.fr
IMAGE_NAME: openspp/openspp
jobs:
build-ubuntu:
name: Build Ubuntu Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
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 Nexus Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=weekly,enable={{is_default_branch}}
type=sha,prefix={{branch}}-
- name: Build and push Ubuntu image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATE=${{ github.event.head_commit.timestamp }}
VCS_REF=${{ github.sha }}
VERSION=${{ steps.meta.outputs.version }}
build-slim:
name: Build Slim Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
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 Nexus Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,suffix=-slim
type=ref,event=pr,suffix=-slim
type=semver,pattern={{version}},suffix=-slim
type=semver,pattern={{major}}.{{minor}},suffix=-slim
type=raw,value=latest-slim,enable={{is_default_branch}}
type=raw,value=weekly-slim,enable={{is_default_branch}}
type=sha,prefix={{branch}}-,suffix=-slim
- name: Build and push Slim image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.slim
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATE=${{ github.event.head_commit.timestamp }}
VCS_REF=${{ github.sha }}
VERSION=${{ steps.meta.outputs.version }}
test-images:
name: Test Docker Images
needs: [build-ubuntu, build-slim]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image (Ubuntu)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
load: true
tags: openspp:test-ubuntu
cache-from: type=gha
- name: Build test image (Slim)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.slim
load: true
tags: openspp:test-slim
cache-from: type=gha
- name: Test Ubuntu image
run: |
echo "Testing Ubuntu image..."
docker run --rm openspp:test-ubuntu openspp-server --version
docker run --rm openspp:test-ubuntu openspp-server --help | grep -q "OpenSPP"
- name: Test Slim image
run: |
echo "Testing Slim image..."
docker run --rm openspp:test-slim openspp-server --version
docker run --rm openspp:test-slim openspp-server --help | grep -q "OpenSPP"
- name: Test health endpoint
run: |
echo "Starting container for health check..."
docker run -d --name openspp-test -p 8069:8069 openspp:test-ubuntu
sleep 60
curl -f http://localhost:8069/web/health || (docker logs openspp-test && exit 1)
docker stop openspp-test
docker rm openspp-test
update-manifests:
name: Update Kubernetes Manifests
needs: [build-ubuntu, build-slim]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update deployment manifests
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "Updating manifests for tag: $TAG"
# Update image tags in deployment files
find deployments -name "*.yaml" -type f -exec \
sed -i "s|image: .*openspp:.*|image: ${{ env.PUBLIC_REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}|g" {} \;
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add deployments/
git diff --staged --quiet || git commit -m "Update deployment manifests for ${GITHUB_REF#refs/tags/}"
git push
notify:
name: Send Notifications
needs: [build-ubuntu, build-slim]
runs-on: ubuntu-latest
if: always() && github.event_name != 'pull_request'
steps:
- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always()
continue-on-error: true
with:
status: ${{ job.status }}
text: |
OpenSPP Docker Build ${{ job.status }}
Branch: ${{ github.ref }}
Commit: ${{ github.sha }}
Images pushed to: ${{ env.PUBLIC_REGISTRY }}/${{ env.IMAGE_NAME }}
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}