Skip to content

Commit 45f42a8

Browse files
committed
feat: improved docker publish action
1 parent f152f63 commit 45f42a8

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

.github/workflows/docker-publish.yml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ name: 🚀 Build, Scan, and Publish Docker Image
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
tags:
8-
- 'v*.*.*' # Only tags like v1.2.0
7+
- 'v*.*.*'
98

109
jobs:
1110
build-scan-push:
@@ -21,38 +20,31 @@ jobs:
2120
username: ${{ secrets.DOCKER_USERNAME }}
2221
password: ${{ secrets.DOCKER_PASSWORD }}
2322

24-
- name: 🏷️ Extract Git Tag (if exists)
25-
id: vars
26-
run: |
27-
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
28-
VERSION_TAG=${GITHUB_REF#refs/tags/}
29-
else
30-
VERSION_TAG=""
31-
fi
32-
echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV
23+
- name: 🏷️ Extract Docker metadata
24+
id: meta
25+
uses: docker/metadata-action@v5
26+
with:
27+
images: xqbuilds/autoproject
28+
tags: |
29+
type=raw,value=latest,enable={{is_default_branch}}
30+
type=semver,pattern={{version}}
3331
3432
- name: 🏗️ Set up Docker Buildx
3533
uses: docker/setup-buildx-action@v3
3634

37-
- name: 🛡️ Install Trivy
38-
run: |
39-
sudo apt-get update
40-
sudo apt-get install -y wget
41-
wget https://github.com/aquasecurity/trivy/releases/download/v0.61.1/trivy_0.61.1_Linux-64bit.deb
42-
sudo dpkg -i trivy_0.61.1_Linux-64bit.deb
43-
44-
- name: 🏗️ Build Docker image (multi-arch)
45-
run: |
46-
if [ -z "${{ env.VERSION_TAG }}" ]; then
47-
echo "No version tag — building :latest only"
48-
docker buildx build --platform linux/amd64,linux/arm64 -t xqbuilds/autoproject:latest --push .
49-
else
50-
echo "Version tag detected: ${{ env.VERSION_TAG }}"
51-
docker buildx build --platform linux/amd64,linux/arm64 -t xqbuilds/autoproject:latest -t xqbuilds/autoproject:${{ env.VERSION_TAG }} --push .
52-
fi
53-
54-
- name: 🔍 Trivy Scan (optional, non-blocking)
35+
- name: 🛡️ Trivy Scan (pre-push, non-blocking)
5536
continue-on-error: true
56-
run: |
57-
echo "Scanning image for vulnerabilities..."
58-
trivy image xqbuilds/autoproject:latest
37+
uses: aquasecurity/trivy-action@v0.28.0
38+
with:
39+
image-ref: xqbuilds/autoproject:latest
40+
format: table
41+
severity: CRITICAL,HIGH
42+
43+
- name: 🏗️ Build & Push (multi-arch)
44+
uses: docker/build-push-action@v6
45+
with:
46+
context: .
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)