Skip to content

Commit d35d6da

Browse files
committed
Add GitHub Actions workflow for Docker build, CLI documentation, and performance benchmarks
1 parent a1edc2e commit d35d6da

File tree

4 files changed

+936
-0
lines changed

4 files changed

+936
-0
lines changed

.github/workflows/docker-build.yml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches:
8+
- main
9+
- feature/go-migration
10+
paths-ignore:
11+
- "**.md"
12+
- "docs/**"
13+
- ".github/ISSUE_TEMPLATE/**"
14+
pull_request:
15+
branches:
16+
- main
17+
paths-ignore:
18+
- "**.md"
19+
- "docs/**"
20+
- ".github/ISSUE_TEMPLATE/**"
21+
workflow_dispatch:
22+
23+
env:
24+
REGISTRY_IMAGE: johandevl/export-trakt-4-letterboxd
25+
GITHUB_REGISTRY: ghcr.io
26+
GITHUB_IMAGE: ghcr.io/johandevl/export_trakt_4_letterboxd
27+
28+
jobs:
29+
build:
30+
name: Build and push multi-platform Docker images
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read
34+
packages: write
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up QEMU
41+
uses: docker/setup-qemu-action@v3
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Extract metadata for Docker
47+
id: meta
48+
uses: docker/metadata-action@v5
49+
with:
50+
images: |
51+
${{ env.REGISTRY_IMAGE }}
52+
${{ env.GITHUB_IMAGE }}
53+
tags: |
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
type=sha,format=short
59+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
60+
61+
- name: Log in to Docker Hub
62+
if: github.event_name != 'pull_request'
63+
uses: docker/login-action@v3
64+
with:
65+
username: ${{ secrets.DOCKERHUB_USERNAME }}
66+
password: ${{ secrets.DOCKERHUB_TOKEN }}
67+
68+
- name: Log in to GitHub Container Registry
69+
if: github.event_name != 'pull_request'
70+
uses: docker/login-action@v3
71+
with:
72+
registry: ${{ env.GITHUB_REGISTRY }}
73+
username: ${{ github.actor }}
74+
password: ${{ secrets.GITHUB_TOKEN }}
75+
76+
- name: Build and export Docker image
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: .
80+
file: ./Dockerfile
81+
push: ${{ github.event_name != 'pull_request' }}
82+
platforms: linux/amd64,linux/arm64,linux/arm/v7
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
85+
cache-from: type=gha
86+
cache-to: type=gha,mode=max
87+
build-args: |
88+
VERSION=${{ steps.meta.outputs.version }}
89+
COMMIT_SHA=${{ github.sha }}
90+
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
91+
92+
- name: Scan image for vulnerabilities
93+
if: github.event_name != 'pull_request'
94+
uses: aquasecurity/trivy-action@master
95+
with:
96+
image-ref: ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
97+
format: "sarif"
98+
output: "trivy-results.sarif"
99+
100+
- name: Upload Trivy scan results to GitHub Security tab
101+
if: github.event_name != 'pull_request'
102+
uses: github/codeql-action/upload-sarif@v2
103+
with:
104+
sarif_file: "trivy-results.sarif"
105+
106+
test:
107+
name: Test Docker image
108+
needs: build
109+
runs-on: ubuntu-latest
110+
if: github.event_name != 'pull_request'
111+
112+
steps:
113+
- name: Checkout repository
114+
uses: actions/checkout@v4
115+
116+
- name: Set up Docker Buildx
117+
uses: docker/setup-buildx-action@v3
118+
119+
- name: Log in to Docker Hub
120+
uses: docker/login-action@v3
121+
with:
122+
username: ${{ secrets.DOCKERHUB_USERNAME }}
123+
password: ${{ secrets.DOCKERHUB_TOKEN }}
124+
125+
- name: Extract Docker metadata
126+
id: meta
127+
uses: docker/metadata-action@v5
128+
with:
129+
images: ${{ env.REGISTRY_IMAGE }}
130+
tags: |
131+
type=sha,format=short
132+
133+
- name: Pull image for testing
134+
run: docker pull ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
135+
136+
- name: Test Docker image
137+
run: |
138+
# Create test directories
139+
mkdir -p ./test_config ./test_logs ./test_exports
140+
141+
# Basic image test - check if it runs and displays version
142+
docker run --rm \
143+
-v $(pwd)/test_config:/app/config \
144+
-v $(pwd)/test_logs:/app/logs \
145+
-v $(pwd)/test_exports:/app/exports \
146+
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} --version
147+
148+
# Check if the help command works
149+
docker run --rm \
150+
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} --help
151+
152+
echo "Docker image tests passed successfully"
153+
154+
notify:
155+
name: Notify on success or failure
156+
needs: [build, test]
157+
runs-on: ubuntu-latest
158+
if: always() && github.event_name == 'release'
159+
160+
steps:
161+
- name: Check build result
162+
id: check
163+
run: |
164+
if ${{ needs.build.result == 'success' && needs.test.result == 'success' }}; then
165+
echo "status=success" >> $GITHUB_OUTPUT
166+
else
167+
echo "status=failure" >> $GITHUB_OUTPUT
168+
fi
169+
170+
- name: Create GitHub comment - Success
171+
if: steps.check.outputs.status == 'success'
172+
uses: actions/github-script@v7
173+
with:
174+
github-token: ${{ secrets.GITHUB_TOKEN }}
175+
script: |
176+
github.rest.issues.createComment({
177+
issue_number: context.issue.number,
178+
owner: context.repo.owner,
179+
repo: context.repo.repo,
180+
body: `✅ Docker images for version ${{ github.ref_name }} have been successfully built and published to:
181+
182+
- Docker Hub: \`johandevl/export-trakt-4-letterboxd:${{ github.ref_name }}\`
183+
- GitHub Packages: \`ghcr.io/johandevl/export_trakt_4_letterboxd:${{ github.ref_name }}\`
184+
185+
The images are available for the following platforms:
186+
- linux/amd64
187+
- linux/arm64
188+
- linux/arm/v7
189+
190+
To use the image:
191+
\`\`\`bash
192+
docker pull johandevl/export-trakt-4-letterboxd:${{ github.ref_name }}
193+
\`\`\`
194+
`
195+
})
196+
197+
- name: Create GitHub comment - Failure
198+
if: steps.check.outputs.status == 'failure'
199+
uses: actions/github-script@v7
200+
with:
201+
github-token: ${{ secrets.GITHUB_TOKEN }}
202+
script: |
203+
github.rest.issues.createComment({
204+
issue_number: context.issue.number,
205+
owner: context.repo.owner,
206+
repo: context.repo.repo,
207+
body: `❌ Docker image build for version ${{ github.ref_name }} failed. Please check the [workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.`
208+
})

0 commit comments

Comments
 (0)