-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (78 loc) · 2.61 KB
/
docker-publish.yml
File metadata and controls
90 lines (78 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Build and Push Docker Image
on:
push:
branches: [main]
paths:
- 'Dockerfile'
- 'docker-compose.yml'
- 'backend/**'
- 'frontend/**'
- '.github/workflows/docker-publish.yml'
release:
types: [published]
workflow_dispatch: # Allow manual trigger
jobs:
build-and-push-ghcr:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=semver,pattern={{version}}
type=sha,prefix=
- name: Build and push to GHCR
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false # Disable provenance attestations for consistency
build-and-push-dockerhub:
runs-on: ubuntu-latest
needs: build-and-push-ghcr # Run after GHCR succeeds
continue-on-error: true # Don't fail workflow if Docker Hub has issues
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Use native docker build/push instead of buildx (better for large layers)
- name: Build Docker image
run: |
docker build -t ambsd/heartmula-studio:latest -t ambsd/heartmula-studio:${{ github.sha }} .
- name: Push to Docker Hub (with retry)
run: |
for i in 1 2 3; do
echo "Push attempt $i..."
if docker push ambsd/heartmula-studio:latest && docker push ambsd/heartmula-studio:${{ github.sha }}; then
echo "Push successful!"
exit 0
fi
echo "Push failed, waiting 30s before retry..."
sleep 30
done
echo "All push attempts failed"
exit 1