Skip to content

Commit 6b8814e

Browse files
igorpecovnikclaude
andcommitted
Add cache mirror support to redirector update workflow
Extend the redirector configuration workflow to support cache mirrors: - Add cache to build platform matrix - Add Cache-index job to fetch mirrors from NetBox - Add Cache check job to compare mirrors against source - Add cache redirector config generation (port 8084) - Handle cache directory mirroring (mirror root, not dists/) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3ecaf3a commit 6b8814e

1 file changed

Lines changed: 119 additions & 1 deletion

File tree

.github/workflows/infrastructure-update-redirector-config.yml

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
- apt
4646
- dl
4747
- archive
48+
- cache
4849
steps:
4950

5051
- name: "Install dependencies: lftp"
@@ -71,6 +72,11 @@ jobs:
7172
7273
# Move top-level archive subdirs from source to destination
7374
find source/*/archive/ -mindepth 1 -maxdepth 1 -exec mv -i -- "{}" destination/ \;
75+
elif [[ "$platform" == "cache" ]]; then
76+
# Mirror cache root directory directly
77+
pushd destination >/dev/null
78+
lftp -e "mirror --parallel=64; quit" "${source_of_truth}/${platform}"
79+
popd >/dev/null
7480
else
7581
# Mirror dists directly into ./destination
7682
pushd destination >/dev/null
@@ -162,6 +168,25 @@ jobs:
162168
| xargs -n3 -d'\n' | sed -e 's/\s\+/\//' | sed "s/ /,/" | jq -cnR '[inputs | select(length>0)]' | jq >> $GITHUB_OUTPUT
163169
echo 'EOF' >> $GITHUB_OUTPUT
164170
171+
Cache-index:
172+
name: "Compare cache mirrors"
173+
needs: build
174+
outputs:
175+
matrix: ${{steps.json.outputs.JSON_CONTENT}}
176+
runs-on: ubuntu-24.04
177+
steps:
178+
179+
- name: "Get cache mirrors from database"
180+
id: json
181+
run: |
182+
183+
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
184+
curl -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
185+
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&tag=cache&status=active" \
186+
| jq '.results[] | .name,.custom_fields["download_path_cache"],.id' | sed "s|null|cache|" | sed "s/\"//g" \
187+
| xargs -n3 -d'\n' | sed -e 's/\s\+/\//' | sed "s/ /,/" | jq -cnR '[inputs | select(length>0)]' | jq >> $GITHUB_OUTPUT
188+
echo 'EOF' >> $GITHUB_OUTPUT
189+
165190
Debs-beta:
166191
name: "B"
167192
runs-on: ubuntu-24.04
@@ -400,8 +425,67 @@ jobs:
400425
path: status
401426
if-no-files-found: ignore
402427

428+
Cache:
429+
name: "C"
430+
runs-on: ubuntu-24.04
431+
needs: [ Cache-index ]
432+
outputs:
433+
matrix: ${{needs.Cache-index.outputs.matrix}}
434+
if: ${{ needs.Cache-index.outputs.matrix != '[]' && needs.Cache-index.outputs.matrix != '' }}
435+
timeout-minutes: 7
436+
strategy:
437+
fail-fast: false
438+
matrix:
439+
node: ${{fromJson(needs.Cache-index.outputs.matrix)}}
440+
441+
steps:
442+
443+
- uses: actions/download-artifact@v7
444+
with:
445+
name: cache
446+
path: cache
447+
448+
- name: "Install dependencies"
449+
uses: awalsh128/cache-apt-pkgs-action@latest
450+
with:
451+
packages: lftp
452+
version: 1.0
453+
454+
- name: "Check ${{ matrix.node }} "
455+
run: |
456+
457+
SERVER_URL=$(echo "${{ matrix.node }}" | cut -d"," -f1)
458+
SERVER_ID=$(echo "${{ matrix.node }}" | cut -d"," -f2)
459+
echo "SERVER_ID=${SERVER_ID}" >> $GITHUB_ENV
460+
mkdir -p compare; cd compare
461+
if curl --output /dev/null --silent --head --fail "https://${SERVER_URL}/cache/"; then
462+
timeout 5m lftp -e "mirror --parallel=16; exit" https://${SERVER_URL}/cache/ || exit_status=$?
463+
fi
464+
cd ..
465+
OUT=$(diff -rq compare cache || true)
466+
mkdir -p status
467+
if [[ -z "${OUT}" ]]; then
468+
echo "true" >> status/${SERVER_ID}
469+
echo "STATUS=true" >> $GITHUB_ENV
470+
elif [[ "${exit_status}" -eq 0 ]]; then
471+
echo "not_in_sync" >> status/${SERVER_ID}
472+
echo "${SERVER_URL}" >> status/${SERVER_ID}
473+
echo "STATUS=not_in_sync" >> $GITHUB_ENV
474+
elif [[ "${exit_status}" -eq 124 ]]; then
475+
echo "timeout" >> status/${SERVER_ID}
476+
echo "${SERVER_URL}" >> status/${SERVER_ID}
477+
echo "STATUS=not_in_sync" >> $GITHUB_ENV
478+
fi
479+
480+
- name: Upload ${{ env.STATUS }} for ${{ matrix.node }}
481+
uses: actions/upload-artifact@v6
482+
with:
483+
name: cache-${{ env.SERVER_ID }}
484+
path: status
485+
if-no-files-found: ignore
486+
403487
download:
404-
needs: [ Debs-beta,Debs-stable,Images-stable,Images-archive ]
488+
needs: [ Debs-beta,Debs-stable,Images-stable,Images-archive,Cache ]
405489
runs-on: ubuntu-24.04
406490
steps:
407491

@@ -545,6 +629,38 @@ jobs:
545629
netbox: ${{ secrets.NETBOX_TOKEN }}
546630
netboxapi: ${{ secrets.NETBOX_API }}
547631

632+
- name: Download All Artifacts
633+
uses: actions/download-artifact@v7
634+
with:
635+
path: status
636+
pattern: cache*
637+
merge-multiple: true
638+
639+
- name: "Grep only those that are in sync"
640+
run: |
641+
echo "# Not in sync" >> $GITHUB_STEP_SUMMARY
642+
grep not_in_sync status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
643+
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
644+
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
645+
646+
echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
647+
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
648+
rm -rf status
649+
650+
- name: Cache
651+
uses: armbian/actions/make-yaml-redirector@main
652+
with:
653+
variant: cache
654+
failoverserver: "${{ env.failoverserver }}"
655+
port: 8084
656+
geodb: "${{ env.GEODB }}"
657+
asndb: "${{ env.ASNDB }}"
658+
dl_map: "${{ env.DL_MAP }}"
659+
certDataPath: "${{ env.CERTPATH }}"
660+
reloadKey: ${{ env.reloadKey }}
661+
netbox: ${{ secrets.NETBOX_TOKEN }}
662+
netboxapi: ${{ secrets.NETBOX_API }}
663+
548664
Close:
549665
needs: [ download ]
550666
runs-on: ubuntu-24.04
@@ -596,10 +712,12 @@ jobs:
596712
debs-*
597713
dl-*
598714
archive-*
715+
cache-*
599716
apt
600717
beta
601718
dl
602719
archive
720+
cache
603721
604722
- name: Install SSH key + known_hosts (task two)
605723
uses: shimataro/ssh-key-action@v2

0 commit comments

Comments
 (0)