-
Notifications
You must be signed in to change notification settings - Fork 5
253 lines (223 loc) Β· 9.52 KB
/
docker-release.yml
File metadata and controls
253 lines (223 loc) Β· 9.52 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
name: π Docker Release Build
on:
push:
tags:
- 'v*.*.*' # Trigger on semantic version tags (v1.2.3)
workflow_dispatch: # Allow manual trigger
inputs:
version:
description: 'Version tag (e.g., v1.2.0)'
required: true
default: 'v0.0.0'
env:
REGISTRY: docker.io
REGISTRY_USERNAME: ${{ secrets.DOCKER_USERNAME }} # Set in GitHub repository secrets
jobs:
build-and-push:
name: Build & Push Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- service: fabrikam-api
dockerfile: FabrikamApi/Dockerfile
context: .
- service: fabrikam-mcp
dockerfile: FabrikamMcp/Dockerfile
context: .
- service: fabrikam-simulator
dockerfile: FabrikamSimulator/Dockerfile
context: .
- service: fabrikam-dashboard
dockerfile: FabrikamDashboard/Dockerfile
context: .
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
- name: π·οΈ Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION_NO_V=${VERSION#v}" >> $GITHUB_OUTPUT
echo "π¦ Building version: $VERSION"
- name: π§ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: π Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: π Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_USERNAME }}/${{ matrix.service }}
tags: |
type=semver,pattern={{version}},value=${{ steps.version.outputs.VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.VERSION }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.VERSION }}
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=Fabrikam ${{ matrix.service }}
org.opencontainers.image.description=Fabrikam modular homes business platform - ${{ matrix.service }}
org.opencontainers.image.vendor=CSP Level Up
org.opencontainers.image.version=${{ steps.version.outputs.VERSION }}
- name: π Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY_USERNAME }}/${{ matrix.service }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY_USERNAME }}/${{ matrix.service }}:buildcache,mode=max
build-args: |
BUILD_VERSION=${{ steps.version.outputs.VERSION }}
BUILD_DATE=${{ github.event.head_commit.timestamp }}
GIT_SHA=${{ github.sha }}
- name: β
Image build summary
run: |
echo "### π Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Service:** ${{ matrix.service }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** ${{ env.REGISTRY }}/${{ env.REGISTRY_USERNAME }}/${{ matrix.service }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build-and-push
permissions:
contents: write
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for changelog generation
- name: π·οΈ Extract version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: π Generate changelog
id: changelog
run: |
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -v "${{ steps.version.outputs.VERSION }}" | head -n1)
if [ -z "$PREVIOUS_TAG" ]; then
CHANGELOG="Initial release"
else
CHANGELOG=$(git log ${PREVIOUS_TAG}..${{ steps.version.outputs.VERSION }} --pretty=format:"- %s (%h)" --no-merges)
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: π Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.VERSION }}
release_name: Release ${{ steps.version.outputs.VERSION }}
body: |
## π Docker Images
All services have been published to Docker Hub:
- `${{ env.REGISTRY_USERNAME }}/fabrikam-api:${{ steps.version.outputs.VERSION }}`
- `${{ env.REGISTRY_USERNAME }}/fabrikam-mcp:${{ steps.version.outputs.VERSION }}`
- `${{ env.REGISTRY_USERNAME }}/fabrikam-simulator:${{ steps.version.outputs.VERSION }}`
- `${{ env.REGISTRY_USERNAME }}/fabrikam-dashboard:${{ steps.version.outputs.VERSION }}`
## π Deployment
Update your `.env` file:
```bash
VERSION=${{ steps.version.outputs.VERSION }}
```
Then deploy:
```bash
docker-compose -f docker-compose.prod.yml pull
docker-compose -f docker-compose.prod.yml up -d
```
Or let Watchtower auto-update (5 minute polling interval).
## π Changes
${{ steps.changelog.outputs.CHANGELOG }}
## π Links
- [Docker Hub Registry](https://hub.docker.com/u/${{ env.REGISTRY_USERNAME }})
- [Deployment Guide](https://github.com/${{ github.repository }}/blob/main/docs/deployment/UBUNTU-DEPLOYMENT.md)
- [Troubleshooting](https://github.com/${{ github.repository }}/blob/main/docs/deployment/DOCKER-TROUBLESHOOTING.md)
draft: false
prerelease: false
notify:
name: Notify Deployment
runs-on: ubuntu-latest
needs: create-release
if: success()
steps:
- name: π·οΈ Extract version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: π’ Deployment summary
run: |
echo "### π Release ${{ steps.version.outputs.VERSION }} Complete!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All Docker images have been built and pushed to Docker Hub." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Watchtower will automatically update containers within 5 minutes.**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Or manually update:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "VERSION=${{ steps.version.outputs.VERSION }} docker-compose -f docker-compose.prod.yml up -d" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# ============================================================================
# Workflow Summary:
# ============================================================================
# Trigger: Push tags matching v*.*.* (e.g., v1.2.3) or manual dispatch
#
# Steps:
# 1. Build all 4 Docker images in parallel (matrix strategy)
# 2. Push images with multiple tags:
# - Specific version: v1.2.3
# - Minor version: v1.2
# - Major version: v1
# - Latest (if default branch)
# 3. Create GitHub Release with changelog
# 4. Notify completion (Watchtower auto-updates within 5 min)
#
# Required Secrets (set in GitHub Settings > Secrets > Actions):
# - DOCKER_USERNAME: Your Docker Hub username
# - DOCKER_PASSWORD: Docker Hub access token (not password!)
# Generate at: https://hub.docker.com/settings/security
#
# Usage:
# 1. Create and push version tag:
# git tag v1.2.3
# git push origin v1.2.3
#
# 2. Or trigger manually from Actions tab with version input
#
# 3. Monitor workflow at: https://github.com/{owner}/{repo}/actions
# ============================================================================