Skip to content

Commit f9aca1e

Browse files
committed
update workflows
1 parent 026a614 commit f9aca1e

File tree

2 files changed

+46
-73
lines changed

2 files changed

+46
-73
lines changed

.github/actions/1-addition/1-maps/action.yml

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -187,71 +187,13 @@ runs:
187187
configFile: ${{ inputs.action_path }}/.devcontainer.json
188188
push: ${{ env.RERUN_RUNNER == 'true' && 'always' || 'never' }}
189189

190-
- name: 🗑️ Delete 15 Oldest Docker Images
191-
id: variables
190+
- name: 🗑️ Delete Docker Tags AND Images
191+
id: delete_images
192192
shell: bash
193193
env:
194194
IMAGE_NAME: "${{ inputs.image_name }}"
195195
HUB_USERNAME: "${{ inputs.hub_username }}"
196196
HUB_PASSWORD: "${{ inputs.hub_password }}"
197197
MAX_DELETIONS: 15
198198
run: |
199-
echo "Fetching manifests to delete..."
200-
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST \
201-
-d "{\"username\": \"${{ inputs.hub_username }}\", \"password\": \"${{ inputs.hub_password }}\"}" \
202-
https://hub.docker.com/v2/users/login/ | jq -r .token)
203-
[ -z "$HUB_TOKEN" ] && { echo "❌ Authentication failed"; exit 1; }
204-
205-
MANIFESTS=$(curl -s -H "Authorization: JWT $HUB_TOKEN" \
206-
"https://hub.docker.com/v2/repositories/${{ inputs.image_name }}/tags/?page_size=${{ env.MAX_DELETIONS }}&ordering=last_updated" \
207-
| jq -r '.results[] | select(.images != null) | .images[].digest' \
208-
| sort | uniq | head -n ${{ env.MAX_DELETIONS }})
209-
210-
DELETED_MANIFESTS=0
211-
for SHA in $MANIFESTS; do
212-
echo "Processing manifest ${SHA:0:12}..."
213-
214-
# 1. Handle SHA256 prefix (some APIs need it, some don't)
215-
CLEAN_SHA="${SHA#sha256:}"
216-
217-
# 2. Try two different API endpoints
218-
ENDPOINTS=(
219-
"https://hub.docker.com/v2/repositories/$IMAGE_NAME/manifests/sha256:$CLEAN_SHA"
220-
"https://hub.docker.com/v2/namespaces/${IMAGE_NAME%/*}/repositories/${IMAGE_NAME#*/}/manifests/sha256:$CLEAN_SHA"
221-
)
222-
223-
for DELETE_URL in "${ENDPOINTS[@]}"; do
224-
echo "Trying endpoint: ${DELETE_URL//$CLEAN_SHA/***}"
225-
226-
# 3. Make the request with full debugging
227-
RESPONSE=$(curl -v -s -o /dev/null -w "%{http_code}" -X DELETE \
228-
-H "Authorization: JWT $HUB_TOKEN" \
229-
-H "Accept: application/json" \
230-
"$DELETE_URL" 2> curl_debug.log)
231-
232-
# 4. Check response
233-
if [ "$RESPONSE" -eq 202 ]; then
234-
((DELETED_MANIFESTS++))
235-
echo "✅ Successfully deleted manifest"
236-
# Show successful response headers
237-
grep "< HTTP/2" curl_debug.log | head -5
238-
break
239-
else
240-
echo "❌ Failed (HTTP $RESPONSE)"
241-
# Show error details
242-
grep -E "< HTTP/2|error" curl_debug.log || cat curl_debug.log
243-
fi
244-
done
245-
246-
# 5. Verify token is still valid
247-
if [ "$RESPONSE" -eq 401 ]; then
248-
echo "🔄 Token expired, refreshing..."
249-
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST \
250-
-d "{\"username\": \"$HUB_USERNAME\", \"password\": \"$HUB_PASSWORD\"}" \
251-
https://hub.docker.com/v2/users/login/ | jq -r .token)
252-
fi
253-
254-
sleep 3 # Conservative rate limiting
255-
done
256-
echo "Total manifests deleted: $DELETED_MANIFESTS/$MAX_DELETIONS"
257-
rm -f curl_debug.log
199+
./.github/entrypoint/remote.sh

.github/entrypoint/remote.sh

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

3-
deploy_remote() {
4-
echo -e "Deploying to $1 on branch gh-pages"
5-
REMOTE_REPO="https://${ACTOR}:${TOKEN}@github.com/$1.git"
3+
# 1. Authenticate
4+
token=$(curl -s -H "Content-Type: application/json" -X POST \
5+
-d "{\"username\": \"$HUB_USERNAME\", \"password\": \"$HUB_PASSWORD\"}" \
6+
https://hub.docker.com/v2/users/login/ | jq -r .token)
7+
[ -z "$token" ] && { echo "❌ Auth failed"; exit 1; }
68

7-
git config --global user.name "${ACTOR}"
8-
git config --global user.email "${ACTOR}@users.noreply.github.com"
9+
# 2. Get manifests with tags
10+
response=$(curl -s -H "Authorization: JWT $token" \
11+
"https://hub.docker.com/v2/repositories/$IMAGE_NAME/tags/?page_size=$MAX_DELETIONS&ordering=last_updated")
912

10-
git clone -b gh-pages --single-branch ${REMOTE_REPO} &>/dev/null
11-
cd "$(basename "${REMOTE_REPO}" .git)" && rm -rf *
13+
# 3. Process deletions
14+
deleted=0
15+
echo "$response" | jq -c '.results[]' | while read -r item; do
16+
tag=$(echo "$item" | jq -r '.name')
17+
digest=$(echo "$item" | jq -r '.images[0].digest')
18+
19+
echo "Processing ${digest:7:12}..."
20+
21+
# Delete tag first (if not latest)
22+
if [ "$tag" != "null" ] && [ "$tag" != "latest" ]; then
23+
echo " 🏷️ Deleting tag: $tag"
24+
curl -s -o /dev/null -X DELETE \
25+
-H "Authorization: JWT $token" \
26+
"https://hub.docker.com/v2/namespaces/${IMAGE_NAME%/*}/repositories/${IMAGE_NAME#*/}/tags/$tag"
27+
fi
28+
29+
# Delete the actual image manifest
30+
echo " 🖼️ Deleting image manifest..."
31+
status=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
32+
-H "Authorization: JWT $token" \
33+
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
34+
"https://hub.docker.com/v2/repositories/$IMAGE_NAME/manifests/$digest")
35+
36+
if [ "$status" -eq 202 ]; then
37+
((deleted++))
38+
echo " ✅ Deleted successfully"
39+
else
40+
echo " ❌ Failed to delete image (HTTP $status)"
41+
fi
42+
43+
sleep 2
44+
[ $deleted -ge $MAX_DELETIONS ] && break
45+
done
1246

13-
mv -v ${GITHUB_WORKSPACE}/_site/* . && touch .nojekyll && git add .
14-
git commit -m "jekyll build from cction ${GITHUB_SHA}"
15-
git push -u origin gh-pages
16-
}
47+
echo "Result: Deleted $deleted images (tags AND manifests)"

0 commit comments

Comments
 (0)