-
Notifications
You must be signed in to change notification settings - Fork 169
85 lines (73 loc) · 2.87 KB
/
docker.yml
File metadata and controls
85 lines (73 loc) · 2.87 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
name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- "v*.*.*"
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=short
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref_type == 'tag' }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Make package public
run: |
PACKAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
PACKAGE_NAME_ENCODED="${PACKAGE_NAME//\//%2F}"
# Try user endpoint first (for personal repos)
RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/user/packages/container/${PACKAGE_NAME_ENCODED}/visibility" \
-d '{"visibility":"public"}')
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
# If user endpoint fails, try org endpoint
if [ "$HTTP_CODE" != "204" ] && [ "$HTTP_CODE" != "200" ]; then
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/orgs/${OWNER}/packages/container/${PACKAGE_NAME_ENCODED}/visibility" \
-d '{"visibility":"public"}' || echo "Note: Package visibility may need to be set manually at https://github.com/${{ github.repository }}/pkgs/container/document/settings"
else
echo "✅ Package set to public"
fi