Cache linux/arm64 Docker Image for fsx199/strongdroid:12-arm64 #49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cache Docker Image | |
on: | |
workflow_dispatch: | |
inputs: | |
image_name: | |
description: 'Docker image name' | |
default: 'alpine' | |
required: true | |
version: | |
description: 'Docker image version' | |
default: 'latest' | |
required: true | |
architecture: | |
description: 'Docker image architecture' | |
default: 'linux/arm64' | |
required: true | |
# schedule: | |
# - cron: '0 23 * * *' | |
run-name: Cache ${{ github.event.inputs.architecture }} Docker Image for ${{ github.event.inputs.image_name }}:${{ github.event.inputs.version }} | |
jobs: | |
update_cache: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set input parameters | |
id: params | |
run: | | |
echo "IMAGE_NAME=${{ github.event.inputs.image_name }}" >> $GITHUB_ENV | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
echo "ARCHITECTURE=${{ github.event.inputs.architecture }}" >> $GITHUB_ENV | |
- name: Pull Docker image | |
run: | | |
docker pull --platform $ARCHITECTURE $IMAGE_NAME:$VERSION | |
- name: Save Docker image | |
run: | | |
SHA512=$(echo -n "$IMAGE_NAME:$VERSION" | sha512sum | awk '{print $1}') | |
echo "SHA512=${SHA512}" >> $GITHUB_ENV | |
docker save $IMAGE_NAME:$VERSION -o ${SHA512}.tar | |
- name: compress Docker image | |
run: | | |
tar -cJf ${SHA512}.tar.xz ${SHA512}.tar | |
rm ${SHA512}.tar | |
echo "Compressed to ${SHA512}.tar.xz" | |
- name: Download existing meta.json from mirror release | |
run: | | |
curl -L -o meta.json "https://github.com/${{ github.repository }}/releases/download/mirror/meta.json" || echo '[]' > meta.json | |
- name: Create or update meta.json | |
run: | | |
if jq -e ". | any(.image == \"$IMAGE_NAME\" and .version == \"$VERSION\" and .architecture == \"$ARCHITECTURE\")" meta.json; then | |
jq --arg image "$IMAGE_NAME" --arg version "$VERSION" --arg sha512 "$SHA512" --arg arch "$ARCHITECTURE" \ | |
'(.[] | select(.image == $image and .version == $version and .architecture == $arch).sha512) = $sha512' meta.json > tmp.json && mv tmp.json meta.json | |
else | |
jq --arg image "$IMAGE_NAME" --arg version "$VERSION" --arg sha512 "$SHA512" --arg arch "$ARCHITECTURE" \ | |
'. += [{"image": $image, "version": $version, "sha512": $sha512, "architecture": $arch}]' meta.json > tmp.json && mv tmp.json meta.json | |
fi | |
- name: Upload to Release | |
uses: ncipollo/release-action@main | |
with: | |
tag: mirror | |
artifacts: "*.tar.xz, meta.json" | |
allowUpdates: true | |
removeArtifacts: false | |
replacesArtifacts: true | |
makeLatest: false | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
Docker images cache mirror. don't forget to enable longpath. git config --global core.longpaths true | |
https://github.com/feicong/ebpf-course |