Skip to content

Commit 5300af1

Browse files
author
Slingexe
authored
Create docker-publish.yaml
1 parent e2f209d commit 5300af1

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-and-push:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up QEMU
16+
uses: docker/setup-qemu-action@v3
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
21+
- name: Log in to GitHub Container Registry (GHCR)
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GHCR_PAT || secrets.GITHUB_TOKEN }}
27+
28+
- name: Log in to DockerHub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USER }}
32+
password: ${{ secrets.DOCKERHUB_AT }}
33+
34+
- name: Extract release version
35+
id: get_version
36+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
37+
38+
- name: Retrieve previous release version
39+
id: previous_version
40+
run: |
41+
PREV_VERSION=$(gh release list --limit 2 --json tagName --jq '.[1].tagName' || echo "")
42+
if [ -z "$PREV_VERSION" ]; then
43+
echo "No previous version found, skipping retagging."
44+
echo "PREV_VERSION=" >> $GITHUB_ENV
45+
else
46+
echo "Previous version: $PREV_VERSION"
47+
echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_ENV
48+
fi
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Build and Push Docker Image (GitHub Packages)
53+
run: |
54+
docker buildx build --platform linux/amd64,linux/arm64 \
55+
--tag ghcr.io/${{ github.repository }}:${{ env.VERSION }} \
56+
--tag ghcr.io/${{ github.repository }}:latest \
57+
--push .
58+
59+
- name: Build and Push Docker Image (DockerHub)
60+
run: |
61+
docker buildx build --platform linux/amd64,linux/arm64 \
62+
--tag ${{ secrets.DOCKERHUB_USER }}/your-image:${{ env.VERSION }} \
63+
--tag ${{ secrets.DOCKERHUB_USER }}/your-image:latest \
64+
--push .
65+
66+
- name: Retag and Push Previous Version (DockerHub)
67+
if: env.PREV_VERSION != ''
68+
run: |
69+
docker pull ${{ secrets.DOCKERHUB_USER }}/your-image:latest
70+
docker tag ${{ secrets.DOCKERHUB_USER }}/your-image:latest \
71+
${{ secrets.DOCKERHUB_USER }}/your-image:${{ env.PREV_VERSION }}
72+
docker push ${{ secrets.DOCKERHUB_USER }}/your-image:${{ env.PREV_VERSION }}

0 commit comments

Comments
 (0)