Skip to content

Commit 84a8969

Browse files
committed
Add Dockerfile and GitHub Actions workflow for Docker image build and publish
- Introduced a Dockerfile to set up the Python environment, install dependencies, and define the application entry point. - Added a GitHub Actions workflow to automate the building and pushing of Docker images to Amazon ECR Public, including versioning with CalVer and tagging based on Git commit information. - The workflow triggers on pushes to the main and release-test branches, as well as on version tags, ensuring continuous integration and deployment for the audio adapter application.
1 parent e2367c9 commit 84a8969

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: Build and Push Docker image
2+
3+
# CalVer Release Workflow
4+
#
5+
# Automatically creates a CalVer release on every push to main.
6+
# Version format: YYYY.MM.DD (e.g., 2026.01.16)
7+
# If multiple releases happen on the same day, adds sequence: YYYY.MM.DD.2, YYYY.MM.DD.3, etc.
8+
#
9+
# Docker tags created:
10+
# - CalVer tag (e.g., 2026.01.16)
11+
# - Branch name (e.g., main)
12+
# - Git short hash (e.g., main-a1b2c3d)
13+
# - latest (for main branch only)
14+
15+
on:
16+
push:
17+
branches: [main, release-test]
18+
tags: ['v*']
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: write
25+
packages: write
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Generate CalVer version
34+
id: calver
35+
run: |
36+
TODAY=$(date +"%Y.%m.%d")
37+
EXISTING_TAGS=$(git tag -l "${TODAY}*" | sort -V)
38+
39+
if [ -z "$EXISTING_TAGS" ]; then
40+
VERSION="${TODAY}"
41+
else
42+
LAST_TAG=$(echo "$EXISTING_TAGS" | tail -1)
43+
if [[ "$LAST_TAG" == "$TODAY" ]]; then
44+
VERSION="${TODAY}.2"
45+
elif [[ "$LAST_TAG" =~ ^${TODAY}\.([0-9]+)$ ]]; then
46+
SEQ="${BASH_REMATCH[1]}"
47+
NEXT_SEQ=$((SEQ + 1))
48+
VERSION="${TODAY}.${NEXT_SEQ}"
49+
else
50+
VERSION="${TODAY}.2"
51+
fi
52+
fi
53+
54+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
55+
echo "Generated CalVer version: ${VERSION}"
56+
57+
- name: Get git commit info
58+
id: git
59+
run: |
60+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
61+
echo "full_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
62+
echo "build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
63+
64+
- name: Create git tag
65+
if: github.ref == 'refs/heads/main'
66+
run: |
67+
git config user.name "github-actions[bot]"
68+
git config user.email "github-actions[bot]@users.noreply.github.com"
69+
70+
if git rev-parse "${{ steps.calver.outputs.version }}" >/dev/null 2>&1; then
71+
echo "Tag ${{ steps.calver.outputs.version }} already exists, skipping"
72+
else
73+
git tag -a "${{ steps.calver.outputs.version }}" -m "Release ${{ steps.calver.outputs.version }}"
74+
git push origin "${{ steps.calver.outputs.version }}"
75+
echo "Created and pushed tag ${{ steps.calver.outputs.version }}"
76+
fi
77+
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
80+
81+
- name: Log in to Amazon ECR Public
82+
uses: docker/login-action@v3
83+
with:
84+
registry: public.ecr.aws
85+
username: ${{ secrets.AWS_ACCESS_KEY }}
86+
password: ${{ secrets.AWS_SECRET }}
87+
88+
- name: Extract metadata
89+
id: meta
90+
uses: docker/metadata-action@v5
91+
with:
92+
images: |
93+
public.ecr.aws/r4g1k2s3/vcon-dev/vcon-audio-adapter
94+
tags: |
95+
type=raw,value=${{ steps.calver.outputs.version }},enable=${{ github.ref == 'refs/heads/main' }}
96+
type=ref,event=branch
97+
type=ref,event=pr
98+
type=semver,pattern={{version}}
99+
type=semver,pattern={{major}}.{{minor}}
100+
type=sha,prefix={{branch}}-
101+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
102+
103+
- name: Build and push Docker image
104+
uses: docker/build-push-action@v5
105+
with:
106+
context: .
107+
file: ./Dockerfile
108+
platforms: linux/amd64
109+
push: true
110+
cache-from: type=gha
111+
cache-to: type=gha,mode=max
112+
tags: ${{ steps.meta.outputs.tags }}
113+
labels: ${{ steps.meta.outputs.labels }}
114+
build-args: |
115+
VCON_AUDIO_ADAPTER_VERSION=${{ steps.calver.outputs.version }}
116+
VCON_AUDIO_ADAPTER_GIT_COMMIT=${{ steps.git.outputs.short_sha }}
117+
VCON_AUDIO_ADAPTER_BUILD_TIME=${{ steps.git.outputs.build_time }}
118+
119+
- name: Create GitHub Release
120+
if: github.ref == 'refs/heads/main'
121+
uses: softprops/action-gh-release@v1
122+
with:
123+
tag_name: ${{ steps.calver.outputs.version }}
124+
name: Release ${{ steps.calver.outputs.version }}
125+
body: |
126+
## Release ${{ steps.calver.outputs.version }}
127+
128+
**Commit:** ${{ steps.git.outputs.short_sha }}
129+
**Build Time:** ${{ steps.git.outputs.build_time }}
130+
131+
### Docker Images
132+
133+
Pull using CalVer:
134+
```bash
135+
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-audio-adapter:${{ steps.calver.outputs.version }}
136+
```
137+
138+
Pull using git hash:
139+
```bash
140+
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-audio-adapter:main-${{ steps.git.outputs.short_sha }}
141+
```
142+
143+
Pull latest:
144+
```bash
145+
docker pull public.ecr.aws/r4g1k2s3/vcon-dev/vcon-audio-adapter:latest
146+
```
147+
draft: false
148+
prerelease: false
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
152+
- name: Summary
153+
run: |
154+
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
155+
echo "" >> $GITHUB_STEP_SUMMARY
156+
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
157+
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
158+
echo "| **Version** | ${{ steps.calver.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
159+
echo "| **Git Commit** | ${{ steps.git.outputs.short_sha }} |" >> $GITHUB_STEP_SUMMARY
160+
echo "| **Build Time** | ${{ steps.git.outputs.build_time }} |" >> $GITHUB_STEP_SUMMARY
161+
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
162+
echo "" >> $GITHUB_STEP_SUMMARY
163+
echo "### Docker Tags" >> $GITHUB_STEP_SUMMARY
164+
echo '```' >> $GITHUB_STEP_SUMMARY
165+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
166+
echo '```' >> $GITHUB_STEP_SUMMARY

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.11-slim
2+
3+
# Build arguments for version information (injected by CI/CD)
4+
ARG VCON_AUDIO_ADAPTER_VERSION=dev
5+
ARG VCON_AUDIO_ADAPTER_GIT_COMMIT=unknown
6+
ARG VCON_AUDIO_ADAPTER_BUILD_TIME=unknown
7+
8+
# Set version info as environment variables (available at runtime)
9+
ENV VCON_AUDIO_ADAPTER_VERSION=${VCON_AUDIO_ADAPTER_VERSION}
10+
ENV VCON_AUDIO_ADAPTER_GIT_COMMIT=${VCON_AUDIO_ADAPTER_GIT_COMMIT}
11+
ENV VCON_AUDIO_ADAPTER_BUILD_TIME=${VCON_AUDIO_ADAPTER_BUILD_TIME}
12+
13+
ENV PYTHONDONTWRITEBYTECODE=1 \
14+
PYTHONUNBUFFERED=1
15+
16+
WORKDIR /app
17+
18+
COPY requirements.txt .
19+
RUN pip install --no-cache-dir -r requirements.txt
20+
21+
COPY audio_adapter ./audio_adapter
22+
COPY main.py ./main.py
23+
COPY pyproject.toml ./pyproject.toml
24+
25+
CMD ["python", "main.py"]

0 commit comments

Comments
 (0)