Skip to content

Commit 8736972

Browse files
committed
feat: add Docker CI/CD workflow
- Add GitHub Actions workflow for Docker image builds - Builds and pushes to DockerHub with smart tagging - Triggers on pushes to docker-containerization branch - Triggers on PRs to develop, main, and sn-auth-package-extraimprovements - Safely skips build if no Dockerfile exists - Uses branch-based and SHA-based tags for versioning
1 parent 86652da commit 8736972

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "feature/docker-containerization" # Only containerization branch for now
7+
pull_request:
8+
branches:
9+
- "develop"
10+
- "main"
11+
- "feature/sn-auth-package-extraimprovements" # Current dev branch with latest sn-auth
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Check out the repo
19+
uses: actions/checkout@v4
20+
21+
- name: Check if Dockerfile exists
22+
id: check_dockerfile
23+
run: |
24+
if [ -f "Dockerfile" ]; then
25+
echo "dockerfile_exists=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "dockerfile_exists=false" >> $GITHUB_OUTPUT
28+
echo "⚠️ No Dockerfile found, skipping Docker build"
29+
fi
30+
31+
- name: Set up Docker metadata
32+
if: steps.check_dockerfile.outputs.dockerfile_exists == 'true'
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: sensenetcsp/sn-client
37+
tags: |
38+
# Branch name
39+
type=ref,event=branch
40+
# Latest tag for main branch
41+
type=raw,value=latest,enable={{is_default_branch}}
42+
# PR number for pull requests
43+
type=ref,event=pr
44+
# Short SHA
45+
type=sha,prefix={{branch}}-
46+
47+
- name: Login to DockerHub
48+
if: steps.check_dockerfile.outputs.dockerfile_exists == 'true'
49+
uses: docker/login-action@v3
50+
with:
51+
username: ${{ secrets.DOCKERHUB_USERNAME }}
52+
password: ${{ secrets.DOCKERHUB_TOKEN }}
53+
54+
- name: Build and push Docker image
55+
if: steps.check_dockerfile.outputs.dockerfile_exists == 'true'
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: .
59+
file: ./Dockerfile
60+
push: true
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)