Skip to content

Commit f26c2db

Browse files
committed
update github action
1 parent cb0eeba commit f26c2db

File tree

5 files changed

+76
-62
lines changed

5 files changed

+76
-62
lines changed

.github/scripts/on_release_deleted.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ set -euo pipefail
44
COMPONENT="$1"
55
TAG="$2"
66
VERSION="${TAG#v}"
7-
REPO_NAME="subvortex-${COMPONENT//_/-}"
8-
IMAGE="subvortex/$REPO_NAME"
7+
REPO_NAME="$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
8+
COMPONENT_NAME="subvortex-${COMPONENT//_/-}"
9+
IMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER}/$REPO_NAME/$COMPONENT_NAME"
910

10-
DOCKER_USERNAME="${DOCKER_USERNAME:-}"
11-
DOCKER_PASSWORD="${DOCKER_PASSWORD:-}"
11+
GHCR_USERNAME="${GHCR_USERNAME:-}"
12+
GHCR_TOKEN="${GHCR_TOKEN:-}"
1213

13-
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
14-
echo "❌ Missing Docker credentials (DOCKER_USERNAME / DOCKER_PASSWORD)"
14+
if [[ -z "$GHCR_USERNAME" || -z "$GHCR_TOKEN" ]]; then
15+
echo "❌ Missing GHCR credentials (GHCR_USERNAME / GHCR_TOKEN)"
1516
exit 1
1617
fi
1718

@@ -41,19 +42,26 @@ printf " latest → %s\n" "${LATEST_TAG:-<none>}"
4142
delete_docker_tag() {
4243
local tag="$1"
4344

44-
echo "🔐 Authenticating to Docker Hub..."
45-
TOKEN=$(curl -s -X POST https://hub.docker.com/v2/users/login/ \
46-
-H "Content-Type: application/json" \
47-
-d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" | jq -r .token)
45+
echo "🗑️ Attempting to delete $IMAGE:$tag from GHCR..."
46+
47+
# Find version ID
48+
VERSION_ID=$(gh api "user/packages/container/${REPO_NAME}/versions" \
49+
-H "Authorization: Bearer $GHCR_TOKEN" \
50+
| jq -r ".[] | select(.metadata.container.tags[]? == \"$tag\") | .id")
51+
52+
if [[ -z "$VERSION_ID" ]]; then
53+
echo "⚠️ No version ID found for tag $tag — skipping delete."
54+
return
55+
fi
4856

49-
echo "🗑️ Attempting to delete $IMAGE:$tag from Docker Hub..."
5057
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
51-
"https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/$REPO_NAME/tags/$tag/" \
52-
-H "Authorization: JWT $TOKEN")
58+
-H "Authorization: Bearer $GHCR_TOKEN" \
59+
-H "Accept: application/vnd.github.v3+json" \
60+
"https://api.github.com/user/packages/container/${REPO_NAME}/versions/${VERSION_ID}")
5361

5462
case "$RESPONSE" in
5563
204) echo "✅ Deleted $IMAGE:$tag" ;;
56-
404) echo "⚠️ Tag $IMAGE:$tag not found on Docker Hub" ;;
64+
404) echo "⚠️ Tag $IMAGE:$tag not found on GHCR" ;;
5765
*) echo "❌ Failed to delete $IMAGE:$tag (HTTP $RESPONSE)" ;;
5866
esac
5967
}

.github/scripts/on_release_pushed.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ IS_PRERELEASE="$3"
77
IS_DRAFT="$4"
88

99
VERSION="${RAW_VERSION_TAG#v}"
10-
REPO_NAME="subvortex-${COMPONENT//_/-}"
11-
IMAGE="subvortex/$REPO_NAME"
10+
REPO_NAME="$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
11+
COMPONENT_NAME="subvortex-${COMPONENT//_/-}"
12+
IMAGE="ghcr.io/${GIIMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER}/$REPO_NAME/$COMPONENT_NAME"
1213
1314
if [[ "$IS_DRAFT" == "true" ]]; then
1415
echo "⏭️ Skipping draft release"

.github/scripts/on_tag_deleted.sh

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,34 @@ SERVICE="$2"
66
TAG="$3"
77

88
VERSION="${TAG#v}"
9-
REPO_NAME="subvortex-${COMPONENT//_/-}"
10-
IMAGE="subvortex/$REPO_NAME"
9+
REPO_NAME="$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
10+
COMPONENT_NAME="subvortex-${COMPONENT//_/-}"
11+
IMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER}/$REPO_NAME/$COMPONENT_NAME"
1112

12-
DOCKER_USERNAME="${DOCKER_USERNAME:-}"
13-
DOCKER_PASSWORD="${DOCKER_PASSWORD:-}"
13+
GHCR_USERNAME="${GHCR_USERNAME:-}"
14+
GHCR_TOKEN="${GHCR_TOKEN:-}"
1415

15-
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
16-
echo "❌ Missing Docker credentials (DOCKER_USERNAME / DOCKER_PASSWORD)"
17-
exit 1
16+
if [[ -z "$GHCR_USERNAME" || -z "$GHCR_TOKEN" ]]; then
17+
echo "❌ Missing Docker credentials (GHCR_USERNAME / GHCR_TOKEN)"
18+
exit 1
1819
fi
1920

20-
echo "🔐 Requesting Docker Hub JWT token..."
21-
TOKEN=$(curl -s -X POST https://hub.docker.com/v2/users/login/ \
22-
-H "Content-Type: application/json" \
23-
-d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" | jq -r .token)
24-
25-
if [[ "$TOKEN" == "null" || -z "$TOKEN" ]]; then
26-
echo "❌ Failed to authenticate with Docker Hub"
27-
exit 1
28-
fi
21+
echo "🔍 Deleting $IMAGE:$VERSION from GitHub Container Registry..."
2922

30-
echo "🔍 Deleting $IMAGE:$VERSION from Docker Hub..."
3123
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
32-
-H "Authorization: JWT $TOKEN" \
33-
"https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/$REPO_NAME/tags/$VERSION/")
24+
-H "Authorization: Bearer $GHCR_TOKEN" \
25+
-H "Accept: application/vnd.github.v3+json" \
26+
"https://api.github.com/orgs/${GHCR_USERNAME}/packages/container/${REPO_NAME}/versions/$VERSION")
3427

3528
case "$RESPONSE" in
36-
204)
37-
echo "✅ Deleted $IMAGE:$VERSION"
29+
204)
30+
echo "✅ Deleted $IMAGE:$VERSION"
3831
;;
39-
404)
40-
echo "⚠️ Tag not found: $IMAGE:$VERSION"
32+
404)
33+
echo "⚠️ Tag not found: $IMAGE:$VERSION"
4134
;;
42-
*)
43-
echo "❌ Failed to delete tag: HTTP $RESPONSE"
44-
exit 1
35+
*)
36+
echo "❌ Failed to delete tag: HTTP $RESPONSE"
37+
exit 1
4538
;;
46-
esac
39+
esac

.github/scripts/on_tag_pushed.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ COMPONENT="$1"
55
WHEEL_IMAGE="$2"
66
VERSION_TAG="$3"
77

8-
REPO_NAME="subvortex-${COMPONENT//_/-}"
9-
IMAGE="subvortex/$REPO_NAME"
8+
REPO_NAME="$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
9+
COMPONENT_NAME="subvortex-${COMPONENT//_/-}"
10+
IMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER}/$REPO_NAME/$COMPONENT_NAME"
1011
VERSION="${VERSION_TAG#v}"
1112
DOCKERFILE="subvortex/$COMPONENT/Dockerfile"
1213

@@ -30,7 +31,7 @@ echo "🧾 Resolved Versions:"
3031
echo "VERSION=$VERSION"
3132
echo "COMPONENT_VERSION=$COMPONENT_VERSION"
3233

33-
echo "🚀 Building and pushing Docker image: $IMAGE:$VERSION"
34+
echo "🚀 Building and pushing image: $IMAGE:$VERSION"
3435

3536
docker buildx build \
3637
--squash \
@@ -44,3 +45,8 @@ docker buildx build \
4445
--file "$DOCKERFILE" \
4546
--push \
4647
.
48+
# echo "🌍 Making image public: $IMAGE"
49+
50+
# # Needs gh CLI installed and authenticated (GH_TOKEN must be available in env)
51+
# PACKAGE_NAME="container/${REPO_NAME}"
52+
# gh api --method PATCH "/user/packages/${PACKAGE_NAME}/visibility" --field visibility=public

.github/workflows/docker-workflow.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,34 @@ jobs:
7474
- name: 🧾 Checkout repository
7575
uses: actions/checkout@v3
7676

77-
- name: 🛠 Set up QEMU
78-
uses: docker/setup-qemu-action@v2
77+
- name: 🛠 Install QEMU
78+
run: |
79+
sudo apt-get update
80+
sudo apt-get install -y qemu-user-static binfmt-support
81+
docker run --privileged --rm tonistiigi/binfmt --install all || true
7982
8083
- name: 🧱 Set up Docker Buildx
8184
uses: docker/setup-buildx-action@v2
8285

83-
- name: 🔐 Docker Login
86+
- name: 🔐 Docker Login to GitHub Container Registry (ghcr.io)
8487
uses: docker/login-action@v2
8588
with:
86-
username: ${{ secrets.DOCKER_USERNAME }}
87-
password: ${{ secrets.DOCKER_PASSWORD }}
89+
registry: ghcr.io
90+
username: ${{ secrets.GHCR_USERNAME }}
91+
password: ${{ secrets.GHCR_TOKEN }}
8892

8993
- name: 🧠 Generate build tag from hash
9094
id: meta
9195
run: |
9296
HASH=$(sha256sum subvortex/core/Dockerfile.builder | cut -d ' ' -f1)
93-
echo "tag=subvortex/subvortex-wheel-builder:3.11-$HASH" >> $GITHUB_OUTPUT
97+
echo "tag=ghcr.io/${{ github.repository_owner }}/subvortex-wheel-builder:3.11-$HASH" >> $GITHUB_OUTPUT
9498
9599
- name: 🐋 Build & push wheel-builder (only if not exists)
96100
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
97101
id: wheelbuilder
98102
run: |
99103
TAG="${{ steps.meta.outputs.tag }}"
100-
LATEST_TAG="subvortex/subvortex-wheel-builder:latest"
104+
LATEST_TAG="ghcr.io/${{ github.repository_owner }}/subvortex-wheel-builder:latest"
101105
102106
if docker pull "$TAG" >/dev/null 2>&1; then
103107
echo "✅ Image already exists: $TAG"
@@ -141,8 +145,8 @@ jobs:
141145
run: |
142146
.github/scripts/on_tag_deleted.sh "${{ matrix.component }}" "${{ matrix.service }}" "${{ github.event.ref }}"
143147
env:
144-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
145-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
148+
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
149+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
146150

147151
release:
148152
if: github.event_name == 'release'
@@ -159,17 +163,21 @@ jobs:
159163
- name: 🧾 Checkout repository
160164
uses: actions/checkout@v3
161165

162-
- name: 🛠 Set up QEMU
163-
uses: docker/setup-qemu-action@v2
166+
- name: 🛠 Install QEMU
167+
run: |
168+
sudo apt-get update
169+
sudo apt-get install -y qemu-user-static binfmt-support
170+
docker run --privileged --rm tonistiigi/binfmt --install all || true
164171
165172
- name: 🧱 Set up Docker Buildx
166173
uses: docker/setup-buildx-action@v2
167174

168-
- name: 🔐 Docker Login
175+
- name: 🔐 Docker Login to GitHub Container Registry (ghcr.io)
169176
uses: docker/login-action@v2
170177
with:
171-
username: ${{ secrets.DOCKER_USERNAME }}
172-
password: ${{ secrets.DOCKER_PASSWORD }}
178+
registry: ghcr.io
179+
username: ${{ secrets.GHCR_USERNAME }}
180+
password: ${{ secrets.GHCR_TOKEN }}
173181

174182
- name: 🧠 Determine tag and floating tags
175183
id: taginfo
@@ -193,5 +201,3 @@ jobs:
193201
"${{ steps.taginfo.outputs.version_tag }}" \
194202
"${{ github.event.release.prerelease }}" \
195203
"${{ github.event.release.draft }}"
196-
env:
197-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)