Skip to content

Commit 01d3834

Browse files
committed
fix last details
1 parent cbee7d0 commit 01d3834

6 files changed

Lines changed: 284 additions & 240 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
TAG="$2"
6+
VERSION="${TAG#v}"
7+
REPO_NAME="subvortex-${COMPONENT//_/-}"
8+
IMAGE="subvortex/$REPO_NAME"
9+
10+
DOCKER_USERNAME="${DOCKER_USERNAME:-}"
11+
DOCKER_PASSWORD="${DOCKER_PASSWORD:-}"
12+
13+
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
14+
echo "❌ Missing Docker credentials (DOCKER_USERNAME / DOCKER_PASSWORD)"
15+
exit 1
16+
fi
17+
18+
echo "🧹 Cleaning up release: $TAG"
19+
echo "📦 Target image: $IMAGE"
20+
21+
# Fetch all GitHub releases
22+
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
23+
ALL_RELEASES=$(gh api "/repos/$REPO/releases" --paginate | jq -rc '[.[] | select(.draft == false)] | sort_by(.created_at) | reverse')
24+
25+
# Helper to safely extract tags or return empty
26+
jq_extract_or_empty() {
27+
echo "$ALL_RELEASES" | jq -r "$1" | grep -v '^null$' || echo ""
28+
}
29+
30+
# Determine floating tag targets
31+
DEV_TAG=$(jq_extract_or_empty '.[0].tag_name')
32+
STABLE_TAG=$(jq_extract_or_empty 'map(select(.tag_name | test("-alpha") | not)) | .[0].tag_name')
33+
LATEST_TAG=$(jq_extract_or_empty 'map(select(.prerelease == false)) | .[0].tag_name')
34+
35+
echo "🔁 Floating tag targets:"
36+
printf " dev → %s\n" "${DEV_TAG:-<none>}"
37+
printf " stable → %s\n" "${STABLE_TAG:-<none>}"
38+
printf " latest → %s\n" "${LATEST_TAG:-<none>}"
39+
40+
# Function to delete a tag via Docker Hub API
41+
delete_docker_tag() {
42+
local tag="$1"
43+
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)
48+
49+
echo "🗑️ Attempting to delete $IMAGE:$tag from Docker Hub..."
50+
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")
53+
54+
case "$RESPONSE" in
55+
204) echo "✅ Deleted $IMAGE:$tag" ;;
56+
404) echo "⚠️ Tag $IMAGE:$tag not found on Docker Hub" ;;
57+
*) echo "❌ Failed to delete $IMAGE:$tag (HTTP $RESPONSE)" ;;
58+
esac
59+
}
60+
61+
# Apply floating tags or delete if no valid target
62+
for FTAG in dev stable latest; do
63+
case "$FTAG" in
64+
dev) TARGET="$DEV_TAG" ;;
65+
stable) TARGET="$STABLE_TAG" ;;
66+
latest) TARGET="$LATEST_TAG" ;;
67+
esac
68+
69+
if [[ -n "$TARGET" ]]; then
70+
echo "🏷️ Re-tagging $IMAGE:$FTAG$IMAGE:$TARGET"
71+
docker buildx imagetools create \
72+
--tag "$IMAGE:$FTAG" \
73+
"$IMAGE:$TARGET"
74+
else
75+
echo "⚠️ No valid candidate for $FTAG — will attempt cleanup"
76+
delete_docker_tag "$FTAG"
77+
fi
78+
done
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
RAW_VERSION_TAG="$2"
6+
IS_PRERELEASE="$3"
7+
IS_DRAFT="$4"
8+
9+
VERSION="${RAW_VERSION_TAG#v}"
10+
REPO_NAME="subvortex-${COMPONENT//_/-}"
11+
IMAGE="subvortex/$REPO_NAME"
12+
13+
if [[ "$IS_DRAFT" == "true" ]]; then
14+
echo "⏭️ Skipping draft release"
15+
exit 0
16+
fi
17+
18+
echo "📦 Current release: $RAW_VERSION_TAG (prerelease=$IS_PRERELEASE)"
19+
echo "🔍 Getting manifest for $IMAGE:$VERSION"
20+
docker buildx imagetools inspect "$IMAGE:$VERSION"
21+
22+
# Fetch all GitHub releases
23+
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
24+
ALL_RELEASES=$(gh api "/repos/$REPO/releases" --paginate | jq -rc '[.[] | select(.draft == false)] | sort_by(.created_at) | reverse')
25+
26+
# Safe extract function
27+
jq_extract_or_empty() {
28+
echo "$ALL_RELEASES" | jq -r "$1" | grep -v '^null$' || echo ""
29+
}
30+
31+
# Determine floating tag targets
32+
DEV_TAG=$(jq_extract_or_empty '.[0].tag_name')
33+
STABLE_TAG=$(jq_extract_or_empty 'map(select(.tag_name | test("-alpha") | not)) | .[0].tag_name')
34+
LATEST_TAG=$(jq_extract_or_empty 'map(select(.prerelease == false)) | .[0].tag_name')
35+
36+
echo "🔁 Will update Docker floating tags:"
37+
printf " dev → %s\n" "${DEV_TAG:-<none>}"
38+
printf " stable → %s\n" "${STABLE_TAG:-<none>}"
39+
printf " latest → %s\n" "${LATEST_TAG:-<none>}"
40+
41+
# Retag floating tags
42+
for FLOAT_TAG in dev stable latest; do
43+
case "$FLOAT_TAG" in
44+
dev) TARGET_TAG="$DEV_TAG" ;;
45+
stable) TARGET_TAG="$STABLE_TAG" ;;
46+
latest) TARGET_TAG="$LATEST_TAG" ;;
47+
esac
48+
49+
if [[ -z "$TARGET_TAG" ]]; then
50+
echo "⚠️ No tag found for $FLOAT_TAG — skipping"
51+
continue
52+
fi
53+
54+
if [[ "$IS_PRERELEASE" == "true" && "$FLOAT_TAG" == "latest" ]]; then
55+
echo "⏭️ Skipping 'latest' for prerelease"
56+
continue
57+
fi
58+
59+
TARGET_VERSION="${TARGET_TAG#v}"
60+
echo "🔁 Creating manifest for $IMAGE:$FLOAT_TAG from $IMAGE:$TARGET_VERSION"
61+
docker buildx imagetools create \
62+
--tag "$IMAGE:$FLOAT_TAG" \
63+
"$IMAGE:$TARGET_VERSION"
64+
done

.github/scripts/on_tag_deleted.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
SERVICE="$2"
6+
TAG="$3"
7+
8+
VERSION="${TAG#v}"
9+
REPO_NAME="subvortex-${COMPONENT//_/-}"
10+
IMAGE="subvortex/$REPO_NAME"
11+
12+
DOCKER_USERNAME="${DOCKER_USERNAME:-}"
13+
DOCKER_PASSWORD="${DOCKER_PASSWORD:-}"
14+
15+
if [[ -z "$DOCKER_USERNAME" || -z "$DOCKER_PASSWORD" ]]; then
16+
echo "❌ Missing Docker credentials (DOCKER_USERNAME / DOCKER_PASSWORD)"
17+
exit 1
18+
fi
19+
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
29+
30+
echo "🔍 Deleting $IMAGE:$VERSION from Docker Hub..."
31+
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/")
34+
35+
case "$RESPONSE" in
36+
204)
37+
echo "✅ Deleted $IMAGE:$VERSION"
38+
;;
39+
404)
40+
echo "⚠️ Tag not found: $IMAGE:$VERSION"
41+
;;
42+
*)
43+
echo "❌ Failed to delete tag: HTTP $RESPONSE"
44+
exit 1
45+
;;
46+
esac

.github/scripts/on_tag_pushed.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
WHEEL_IMAGE="$2"
6+
VERSION_TAG="$3"
7+
8+
REPO_NAME="subvortex-${COMPONENT//_/-}"
9+
IMAGE="subvortex/$REPO_NAME"
10+
VERSION="${VERSION_TAG#v}"
11+
DOCKERFILE="subvortex/$COMPONENT/Dockerfile"
12+
13+
echo "🔍 Building image for component: $COMPONENT"
14+
echo "📦 Image name: $IMAGE"
15+
echo "🏷️ Tag: $VERSION"
16+
17+
COMPONENT_PATH="subvortex/$COMPONENT"
18+
if [[ -f "$COMPONENT_PATH/pyproject.toml" ]]; then
19+
echo "✅ Found pyproject.toml"
20+
COMPONENT_VERSION=$(grep -E '^version\s*=' "$COMPONENT_PATH/pyproject.toml" | head -1 | sed -E 's/version\s*=\s*"([^"]+)"/\1/')
21+
elif [[ -f "$COMPONENT_PATH/version.py" ]]; then
22+
echo "✅ Found version.py"
23+
COMPONENT_VERSION=$(python -c "import ast; f=open('$COMPONENT_PATH/version.py'); print([n.value.s for n in ast.walk(ast.parse(f.read())) if isinstance(n, ast.Assign) and n.targets[0].id == '__version__'][0])")
24+
else
25+
echo "❌ No version file found for component: $COMPONENT"
26+
exit 1
27+
fi
28+
29+
echo "🧾 Resolved Versions:"
30+
echo "VERSION=$VERSION"
31+
echo "COMPONENT_VERSION=$COMPONENT_VERSION"
32+
33+
echo "🚀 Building and pushing Docker image: $IMAGE:$VERSION"
34+
35+
docker buildx build \
36+
--squash \
37+
--platform linux/amd64 \
38+
--build-context wheelbuilder=docker-image://$WHEEL_IMAGE \
39+
--build-arg VERSION="$VERSION" \
40+
--build-arg COMPONENT_VERSION="$COMPONENT_VERSION" \
41+
--cache-from=type=gha,scope=wheels_${COMPONENT}_amd64 \
42+
--cache-to=type=gha,mode=max,scope=wheels_${COMPONENT}_amd64 \
43+
--tag "$IMAGE:$VERSION" \
44+
--file "$DOCKERFILE" \
45+
--push \
46+
.

0 commit comments

Comments
 (0)