Skip to content

Commit 8b615ac

Browse files
committed
Add "cache" redirection to autogeneration
1 parent 194a0ab commit 8b615ac

File tree

1 file changed

+118
-1
lines changed

1 file changed

+118
-1
lines changed

.github/workflows/generate-redirector-config.yml

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- apt
4545
- dl
4646
- archive
47+
- cache
4748
steps:
4849

4950
- name: "Install dependencies: lftp"
@@ -60,6 +61,10 @@ jobs:
6061
cd source ; lftp -e "mirror --include-glob=*/archive/*.torrent --parallel=64; exit" https://rsync.armbian.com/${{ matrix.platform }}
6162
cd ..
6263
find source/*/archive/ -mindepth 1 -maxdepth 1 -exec mv -i -- {} destination/ \;
64+
elif [[ "${{ matrix.platform }}" =~ ^(cache) ]]; then
65+
cd source ; lftp -e "mirror --include-glob=*.torrent --parallel=64; exit" https://rsync.armbian.com/${{ matrix.platform }}
66+
cd ..
67+
find source/*/* -mindepth 1 -maxdepth 1 -exec mv -i -- {} destination/ \;
6368
else
6469
cd destination; lftp -e "mirror --parallel=64; exit" https://rsync.armbian.com/${{ matrix.platform }}/dists
6570
fi
@@ -148,6 +153,25 @@ jobs:
148153
| xargs -n3 -d'\n' | sed -e 's/\s\+/\//' | sed "s/ /,/" | jq -cnR '[inputs | select(length>0)]' | jq >> $GITHUB_OUTPUT
149154
echo 'EOF' >> $GITHUB_OUTPUT
150155
156+
Cache-index:
157+
name: "Compare cache mirrors"
158+
needs: build
159+
outputs:
160+
matrix: ${{steps.json.outputs.JSON_CONTENT}}
161+
runs-on: ubuntu-24.04
162+
steps:
163+
164+
- name: "Get cache mirrors from database"
165+
id: json
166+
run: |
167+
168+
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
169+
curl -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
170+
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&tag=cache&status=active" \
171+
| jq '.results[] | .name,.custom_fields["download_path_images"],.id' | sed "s|null|cache|" | sed "s/\"//g" \
172+
| xargs -n3 -d'\n' | sed -e 's/\s\+/\//' | sed "s/ /,/" | jq -cnR '[inputs | select(length>0)]' | jq >> $GITHUB_OUTPUT
173+
echo 'EOF' >> $GITHUB_OUTPUT
174+
151175
Debs-beta:
152176
name: "B"
153177
runs-on: ubuntu-24.04
@@ -386,8 +410,68 @@ jobs:
386410
path: status
387411
if-no-files-found: ignore
388412

413+
Cache:
414+
name: "C"
415+
runs-on: ubuntu-24.04
416+
needs: [ Cache-index ]
417+
outputs:
418+
matrix: ${{needs.Cache-index.outputs.matrix}}
419+
if: ${{ needs.Cache-index.outputs.matrix != '[]' && needs.Cache-index.outputs.matrix != '' }}
420+
timeout-minutes: 7
421+
strategy:
422+
fail-fast: false
423+
matrix:
424+
node: ${{fromJson(needs.Cache-index.outputs.matrix)}}
425+
426+
steps:
427+
428+
- uses: actions/download-artifact@v4
429+
with:
430+
name: cache
431+
path: cache
432+
433+
- name: "Install dependencies"
434+
uses: awalsh128/cache-apt-pkgs-action@latest
435+
with:
436+
packages: lftp
437+
version: 1.0
438+
439+
- name: "Check ${{ matrix.node }} "
440+
run: |
441+
442+
SERVER_URL=$(echo "${{ matrix.node }}" | cut -d"," -f1)
443+
SERVER_ID=$(echo "${{ matrix.node }}" | cut -d"," -f2)
444+
echo "SERVER_ID=${SERVER_ID}" >> $GITHUB_ENV
445+
mkdir -p compare source; cd source
446+
if curl --output /dev/null --silent --head --fail "https://${SERVER_URL}"; then
447+
timeout 5m lftp -e "mirror --include-glob=*.torrent --parallel=64; exit" https://${SERVER_URL} || exit_status=$?
448+
cd ..
449+
find source/*/*/ -mindepth 1 -maxdepth 1 -exec mv -i -- {} compare/ \; || true
450+
fi
451+
OUT=$(diff -rq compare archive || true)
452+
mkdir -p status
453+
if [[ -z "${OUT}" ]]; then
454+
echo "true" >> status/${SERVER_ID}
455+
echo "STATUS=true" >> $GITHUB_ENV
456+
elif [[ "${exit_status}" -eq 0 ]]; then
457+
echo "not_in_sync" >> status/${SERVER_ID}
458+
echo "${SERVER_URL}" >> status/${SERVER_ID}
459+
echo "STATUS=not_in_sync" >> $GITHUB_ENV
460+
elif [[ "${exit_status}" -eq 124 ]]; then
461+
echo "timeout" >> status/${SERVER_ID}
462+
echo "${SERVER_URL}" >> status/${SERVER_ID}
463+
echo "STATUS=not_in_sync" >> $GITHUB_ENV
464+
fi
465+
466+
- name: Upload ${{ env.STATUS }} for ${{ matrix.node }}
467+
uses: actions/upload-artifact@v4
468+
with:
469+
name: archive-${{ env.SERVER_ID }}
470+
path: status
471+
if-no-files-found: ignore
472+
389473
download:
390-
needs: [ Debs-beta,Debs-stable,Images-stable,Images-archive ]
474+
needs: [ Debs-beta,Debs-stable,Images-stable,Images-archive, Cache ]
391475
runs-on: ubuntu-24.04
392476
steps:
393477

@@ -523,6 +607,38 @@ jobs:
523607
reloadKey: ${{ env.reloadKey }}
524608
netbox: ${{ secrets.NETBOX_TOKEN }}
525609

610+
- name: Download All Artifacts
611+
uses: actions/download-artifact@v4
612+
with:
613+
path: status
614+
pattern: cache*
615+
merge-multiple: true
616+
617+
- name: "Grep only those that are in sync"
618+
run: |
619+
echo "# Not in sync" >> $GITHUB_STEP_SUMMARY
620+
#echo "$(grep not_in_sync status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
621+
grep not_in_sync status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
622+
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
623+
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
624+
#echo "$(grep timeout status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
625+
626+
echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
627+
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
628+
rm -rf status
629+
630+
- name: Cache
631+
uses: armbian/actions/make-yaml-redirector@main
632+
with:
633+
variant: cache
634+
failoverserver: "${{ env.failoverserver }}"
635+
port: 8084
636+
geodb: "${{ env.GEODB }}"
637+
asndb: "${{ env.ASNDB }}"
638+
dl_map: "${{ env.DL_MAP }}"
639+
reloadKey: ${{ env.reloadKey }}
640+
netbox: ${{ secrets.NETBOX_TOKEN }}
641+
526642
Close:
527643
needs: [ download ]
528644
runs-on: ubuntu-24.04
@@ -578,6 +694,7 @@ jobs:
578694
beta
579695
dl
580696
archive
697+
cache
581698
582699
- name: "Run webindex update action"
583700
uses: peter-evans/repository-dispatch@v3

0 commit comments

Comments
 (0)