-
Notifications
You must be signed in to change notification settings - Fork 12
225 lines (194 loc) · 7.81 KB
/
docker-publish.yml
File metadata and controls
225 lines (194 loc) · 7.81 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
name: Build and Push Docker image
# CalVer Release Workflow
#
# Automatically creates a CalVer release on every push to main.
# Version format: YYYY.MM.DD (e.g., 2026.01.16)
# If multiple releases happen on the same day, adds sequence: YYYY.MM.DD.2, YYYY.MM.DD.3, etc.
#
# Build strategy: native runners (no QEMU) for maximum speed
# amd64 builds on ubuntu-latest
# arm64 builds on ubuntu-24.04-arm
#
# Docker tags created (linux/amd64 + linux/arm64 multi-arch manifest):
# - CalVer tag (e.g., 2026.01.16) [main only]
# - latest [main only]
# - Branch name (e.g., main)
# - Branch + short sha (e.g., main-a1b2c3d)
on:
push:
branches: [main, release-test]
tags: ['v*']
jobs:
prepare:
runs-on: ubuntu-latest
permissions:
contents: write # needed to create git tags
outputs:
version: ${{ steps.calver.outputs.version }}
short_sha: ${{ steps.git.outputs.short_sha }}
build_time: ${{ steps.git.outputs.build_time }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: Generate CalVer version
id: calver
run: |
TODAY=$(date +"%Y.%m.%d")
EXISTING_TAGS=$(git tag -l "${TODAY}*" | sort -V)
if [ -z "$EXISTING_TAGS" ]; then
VERSION="${TODAY}"
else
LAST_TAG=$(echo "$EXISTING_TAGS" | tail -1)
if [[ "$LAST_TAG" == "$TODAY" ]]; then
VERSION="${TODAY}.2"
elif [[ "$LAST_TAG" =~ ^${TODAY}\.([0-9]+)$ ]]; then
SEQ="${BASH_REMATCH[1]}"
VERSION="${TODAY}.$((SEQ + 1))"
else
VERSION="${TODAY}.2"
fi
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Generated CalVer version: ${VERSION}"
- name: Get git commit info
id: git
run: |
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
- name: Create git tag
if: github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git rev-parse "${{ steps.calver.outputs.version }}" >/dev/null 2>&1; then
echo "Tag ${{ steps.calver.outputs.version }} already exists, skipping"
else
git tag -a "${{ steps.calver.outputs.version }}" -m "Release ${{ steps.calver.outputs.version }}"
git push origin "${{ steps.calver.outputs.version }}"
echo "Created and pushed tag ${{ steps.calver.outputs.version }}"
fi
build:
needs: prepare
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- platform: linux/amd64
platform_tag: amd64
runner: ubuntu-latest
- platform: linux/arm64
platform_tag: arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Amazon ECR Public
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY }}
password: ${{ secrets.AWS_SECRET }}
- name: Build and push (${{ matrix.platform_tag }})
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha,scope=vcon-server-${{ matrix.platform_tag }}
cache-to: type=gha,mode=max,scope=vcon-server-${{ matrix.platform_tag }}
tags: public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:${{ github.ref_name }}-${{ matrix.platform_tag }}
build-args: |
VCON_SERVER_VERSION=${{ needs.prepare.outputs.version }}
VCON_SERVER_GIT_COMMIT=${{ needs.prepare.outputs.short_sha }}
VCON_SERVER_BUILD_TIME=${{ needs.prepare.outputs.build_time }}
merge:
needs: [prepare, build]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Amazon ECR Public
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY }}
password: ${{ secrets.AWS_SECRET }}
- name: Create multi-arch manifests
env:
IMAGE: public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server
VERSION: ${{ needs.prepare.outputs.version }}
SHORT_SHA: ${{ needs.prepare.outputs.short_sha }}
BRANCH: ${{ github.ref_name }}
run: |
AMD64="${IMAGE}:${BRANCH}-amd64"
ARM64="${IMAGE}:${BRANCH}-arm64"
# Branch tag (always)
docker buildx imagetools create --tag "${IMAGE}:${BRANCH}" "${AMD64}" "${ARM64}"
# Branch + sha tag (always)
docker buildx imagetools create --tag "${IMAGE}:${BRANCH}-${SHORT_SHA}" "${AMD64}" "${ARM64}"
# CalVer and latest (main only)
if [ "${BRANCH}" = "main" ]; then
docker buildx imagetools create --tag "${IMAGE}:${VERSION}" "${AMD64}" "${ARM64}"
docker buildx imagetools create --tag "${IMAGE}:latest" "${AMD64}" "${ARM64}"
fi
release:
needs: [prepare, merge]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.prepare.outputs.version }}
name: Release ${{ needs.prepare.outputs.version }}
body: |
## Release ${{ needs.prepare.outputs.version }}
**Commit:** ${{ needs.prepare.outputs.short_sha }}
**Build Time:** ${{ needs.prepare.outputs.build_time }}
### Docker Images
Both `linux/amd64` and `linux/arm64` are supported.
Pull using CalVer:
```bash
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:${{ needs.prepare.outputs.version }}
```
Pull using git hash:
```bash
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:main-${{ needs.prepare.outputs.short_sha }}
```
Pull latest:
```bash
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:latest
```
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| **Version** | ${{ needs.prepare.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Git Commit** | ${{ needs.prepare.outputs.short_sha }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Build Time** | ${{ needs.prepare.outputs.build_time }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Tags (linux/amd64 + linux/arm64)" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ needs.prepare.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`latest\`" >> $GITHUB_STEP_SUMMARY
echo "- \`main\`" >> $GITHUB_STEP_SUMMARY
echo "- \`main-${{ needs.prepare.outputs.short_sha }}\`" >> $GITHUB_STEP_SUMMARY