-
Notifications
You must be signed in to change notification settings - Fork 12
182 lines (159 loc) · 6.55 KB
/
docker-publish.yml
File metadata and controls
182 lines (159 loc) · 6.55 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
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.
#
# Docker tags created:
# - CalVer tag (e.g., 2026.01.16)
# - Branch name (e.g., main)
# - Git short hash (e.g., main-a1b2c3d)
# - latest (for main branch only)
on:
push:
branches: [main, release-test]
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # Need write for creating tags
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: Generate CalVer version
id: calver
run: |
# Get today's date in YYYY.MM.DD format
TODAY=$(date +"%Y.%m.%d")
# Get all existing tags for today
EXISTING_TAGS=$(git tag -l "${TODAY}*" | sort -V)
if [ -z "$EXISTING_TAGS" ]; then
# No tags for today, use base date
VERSION="${TODAY}"
else
# Find the highest sequence number
LAST_TAG=$(echo "$EXISTING_TAGS" | tail -1)
if [[ "$LAST_TAG" == "$TODAY" ]]; then
# First tag was just the date, next is .2
VERSION="${TODAY}.2"
elif [[ "$LAST_TAG" =~ ^${TODAY}\.([0-9]+)$ ]]; then
# Extract sequence number and increment
SEQ="${BASH_REMATCH[1]}"
NEXT_SEQ=$((SEQ + 1))
VERSION="${TODAY}.${NEXT_SEQ}"
else
# Fallback
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 "full_sha=$(git rev-parse 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"
# Check if tag already exists
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
- 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: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server
tags: |
# CalVer tag (e.g., 2026.01.16)
type=raw,value=${{ steps.calver.outputs.version }},enable=${{ github.ref == 'refs/heads/main' }}
# Branch name
type=ref,event=branch
# PR number
type=ref,event=pr
# Semver tags (for manual v* tags)
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Git sha with branch prefix
type=sha,prefix={{branch}}-
# Latest tag for main branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VCON_SERVER_VERSION=${{ steps.calver.outputs.version }}
VCON_SERVER_GIT_COMMIT=${{ steps.git.outputs.short_sha }}
VCON_SERVER_BUILD_TIME=${{ steps.git.outputs.build_time }}
- name: Create GitHub Release
if: github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.calver.outputs.version }}
name: Release ${{ steps.calver.outputs.version }}
body: |
## Release ${{ steps.calver.outputs.version }}
**Commit:** ${{ steps.git.outputs.short_sha }}
**Build Time:** ${{ steps.git.outputs.build_time }}
### Docker Images
Pull using CalVer:
```bash
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:${{ steps.calver.outputs.version }}
```
Pull using git hash:
```bash
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-server:main-${{ steps.git.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** | ${{ steps.calver.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Git Commit** | ${{ steps.git.outputs.short_sha }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Build Time** | ${{ steps.git.outputs.build_time }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Tags" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY