-
Notifications
You must be signed in to change notification settings - Fork 0
321 lines (285 loc) · 13.6 KB
/
Copy pathrelease.yml
File metadata and controls
321 lines (285 loc) · 13.6 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# =============================================================================
# mqBase Release Workflow
# =============================================================================
# Triggers:
# - Tag push: v* (e.g., v0.13.0) on any branch
# - Manual: workflow_dispatch with version input
#
# Jobs:
# 1. build: Build and push Docker images to Docker Hub and GHCR
# 2. deploy: Deploy to production (requires environment approval)
#
# Setup:
# - Create "prod" environment in repo settings with required reviewers
# - Install self-hosted runner on production server (see docs)
# - Configure runner with labels: [self-hosted, linux, prod]
# =============================================================================
name: Release mqBase
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 0.13.0)'
required: true
deploy:
description: 'Deploy to production after build'
type: boolean
default: false
env:
DOCKERHUB_IMAGE: dotstartech/mqbase
GHCR_IMAGE: ghcr.io/dotstartech/mqbase
jobs:
# ===========================================================================
# Build Job - Runs on GitHub-hosted runner
# ===========================================================================
build:
name: Build Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.version.outputs.VERSION }}
steps:
- name: Extract version
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION="${{ inputs.version }}"
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU for multi-arch builds
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Minify app.js for production
run: |
npm install -g terser
ORIGINAL_SIZE=$(wc -c < admin/app.js)
terser admin/app.js --compress --mangle -o admin/app.js
MINIFIED_SIZE=$(wc -c < admin/app.js)
REDUCTION=$((100 - (MINIFIED_SIZE * 100 / ORIGINAL_SIZE)))
echo "app.js: ${ORIGINAL_SIZE} bytes -> ${MINIFIED_SIZE} bytes (${REDUCTION}% reduction)"
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# =========================================================================
# Standard image - AMD64
# =========================================================================
- name: Build and push standard AMD64 image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64
${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}
${{ env.DOCKERHUB_IMAGE }}:latest
${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64
${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}
${{ env.GHCR_IMAGE }}:latest
build-args: |
UID=1000
GID=1000
cache-from: type=gha,scope=standard-amd64
cache-to: type=gha,mode=max,scope=standard-amd64
# =========================================================================
# Standard image - ARM64
# =========================================================================
- name: Build and push standard ARM64 image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64
${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64
build-args: |
UID=1000
GID=1000
cache-from: type=gha,scope=standard-arm64
cache-to: type=gha,mode=max,scope=standard-arm64
# =========================================================================
# Distroless image - AMD64
# =========================================================================
- name: Build and push distroless AMD64 image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile.distroless
platforms: linux/amd64
push: true
tags: |
${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64-distroless
${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64-distroless
cache-from: type=gha,scope=distroless-amd64
cache-to: type=gha,mode=max,scope=distroless-amd64
# =========================================================================
# Distroless image - ARM64
# =========================================================================
- name: Build and push distroless ARM64 image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile.distroless
platforms: linux/arm64
push: true
tags: |
${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64-distroless
${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64-distroless
cache-from: type=gha,scope=distroless-arm64
cache-to: type=gha,mode=max,scope=distroless-arm64
- name: Build Summary
run: |
echo "## Images pushed successfully! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Version: ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Standard Images (debian:trixie-slim)" >> $GITHUB_STEP_SUMMARY
echo "| Architecture | Docker Hub | GitHub Container Registry |" >> $GITHUB_STEP_SUMMARY
echo "|--------------|------------|---------------------------|" >> $GITHUB_STEP_SUMMARY
echo "| AMD64 | \`${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64\` | \`${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64\` |" >> $GITHUB_STEP_SUMMARY
echo "| ARM64 | \`${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64\` | \`${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Distroless Images (gcr.io/distroless/base-debian13)" >> $GITHUB_STEP_SUMMARY
echo "| Architecture | Docker Hub | GitHub Container Registry |" >> $GITHUB_STEP_SUMMARY
echo "|--------------|------------|---------------------------|" >> $GITHUB_STEP_SUMMARY
echo "| AMD64 | \`${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64-distroless\` | \`${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-amd64-distroless\` |" >> $GITHUB_STEP_SUMMARY
echo "| ARM64 | \`${{ env.DOCKERHUB_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64-distroless\` | \`${{ env.GHCR_IMAGE }}:${{ steps.version.outputs.VERSION }}-arm64-distroless\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Latest Tag" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.DOCKERHUB_IMAGE }}:latest\` → AMD64 standard image" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.GHCR_IMAGE }}:latest\` → AMD64 standard image" >> $GITHUB_STEP_SUMMARY
# ===========================================================================
# Release Job - Create GitHub Release (only on tag push)
# ===========================================================================
release:
name: Create GitHub Release
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for release notes
- name: Generate release notes
id: notes
run: |
VERSION="${{ needs.build.outputs.version }}"
# Create release body
cat << EOF > release_notes.md
## Docker Images
### Standard Images (debian:trixie-slim)
| Architecture | Docker Hub | GitHub Container Registry |
|--------------|------------|---------------------------|
| AMD64 | \`dotstartech/mqbase:${VERSION}-amd64\` | \`ghcr.io/dotstartech/mqbase:${VERSION}-amd64\` |
| ARM64 | \`dotstartech/mqbase:${VERSION}-arm64\` | \`ghcr.io/dotstartech/mqbase:${VERSION}-arm64\` |
### Distroless Images (minimal, no shell)
| Architecture | Docker Hub | GitHub Container Registry |
|--------------|------------|---------------------------|
| AMD64 | \`dotstartech/mqbase:${VERSION}-amd64-distroless\` | \`ghcr.io/dotstartech/mqbase:${VERSION}-amd64-distroless\` |
| ARM64 | \`dotstartech/mqbase:${VERSION}-arm64-distroless\` | \`ghcr.io/dotstartech/mqbase:${VERSION}-arm64-distroless\` |
### Quick Start
\`\`\`bash
docker run -d --name mqbase -p 1883:1883 -p 8080:8080 -p 9001:9001 dotstartech/mqbase:${VERSION}
\`\`\`
Open http://localhost:8080 and log in with \`admin:admin\`.
---
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: mqBase v${{ needs.build.outputs.version }}
body_path: release_notes.md
generate_release_notes: true # Appends auto-generated notes from commits
draft: false
prerelease: ${{ contains(needs.build.outputs.version, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ===========================================================================
# Deploy Job - Runs on self-hosted runner on production server
# ===========================================================================
deploy:
name: Deploy to Production
needs: build
# Only deploy on tag push OR when manually triggered with deploy=true
# Note: runs after release job completes (if it ran) due to GitHub's job ordering
if: |
always() &&
needs.build.result == 'success' &&
(startsWith(github.ref, 'refs/tags/v') || inputs.deploy == true)
runs-on: [self-hosted, linux, prod]
environment: prod # Requires approval from reviewers
steps:
- name: Deploy mqBase v${{ needs.build.outputs.version }}
run: |
echo "=== Deploying mqBase v${{ needs.build.outputs.version }} ==="
cd /opt/mqbase
# Pull the new image
echo "Pulling new image..."
sudo docker compose -f compose.prod.yml pull
# Stop and remove existing container, then start fresh
echo "Stopping existing container..."
sudo docker compose -f compose.prod.yml down --remove-orphans || true
echo "Starting new container..."
sudo docker compose -f compose.prod.yml up -d
# Wait for container to be healthy
echo "Waiting for health check..."
sleep 5
# Verify deployment
HEALTH=$(curl -sf --max-time 10 https://mqbase.io/health || echo "FAILED")
if [ "$HEALTH" = "OK" ]; then
echo "✅ Deployment successful!"
else
echo "❌ Health check failed: $HEALTH"
exit 1
fi
- name: Deployment Summary
run: |
echo "## Deployment Complete :white_check_mark:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ needs.build.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Server**: mqbase.io (78.46.17.48)" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: Healthy" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Verification" >> $GITHUB_STEP_SUMMARY
echo "- Health endpoint: https://mqbase.io/health → OK" >> $GITHUB_STEP_SUMMARY
- name: Notify on failure
if: failure()
run: |
echo "## ❌ Deployment Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the logs above for details." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Rollback" >> $GITHUB_STEP_SUMMARY
echo "To rollback, SSH to the server and run:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "cd /opt/mqbase" >> $GITHUB_STEP_SUMMARY
echo "sudo docker compose -f compose.prod.yml down" >> $GITHUB_STEP_SUMMARY
echo "sudo docker pull dotstartech/mqbase:<previous-version>" >> $GITHUB_STEP_SUMMARY
echo "sudo docker compose -f compose.prod.yml up -d" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY