Skip to content

Update images for 22.04 #22

Update images for 22.04

Update images for 22.04 #22

Workflow file for this run

name: update
on:
schedule:
- cron: '0 22 * * 0-4'
pull_request:
jobs:
update:
name: Update images
env:
GH_TOKEN: ${{ secrets.CYBOZU_NECO_PAT }}
runs-on: ubuntu-22.04
strategy:
matrix:
ubuntu-version: [ "20.04", "22.04" ]
defaults:
run:
working-directory: ${{ matrix.ubuntu-version }}
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.9.1
- name: Check minimal image updates
shell: bash -xe {0}
run: |
if [ "${{ matrix.ubuntu-version }}" = "20.04" ]; then
codename=focal
elif [ "${{ matrix.ubuntu-version }}" = "22.04" ]; then
codename=jammy
else
echo "Unknown Ubuntu version: ${{ matrix.ubuntu-version }}"
exit 1
fi
TOKEN=$(curl -sSf "https://auth.docker.io/token?scope=repository%3Alibrary%2Fubuntu%3Apull&service=registry.docker.io"| jq -r .token)
LATEST_TAG=$(curl -sSf -H "Authorization: Bearer $TOKEN" "https://registry-1.docker.io/v2/library/ubuntu/tags/list" | jq -r ".tags[] | select(. | test(\"$codename-.*\"))" | tail -n1)
if [ -z "$LATEST_TAG" ]; then
echo "Failed to get the latest tag for $codename"
exit 1
fi
sed -i -e "s/$codename-[0-9]\{8\}/$LATEST_TAG/g" ./TAG_MINIMAL
echo "Update images for ${{ matrix.ubuntu-version }}" > ./BODY
diffs=$(git status -s)
if [ -n "$diffs" ]; then
echo "NEED_UPDATE=1" >> $GITHUB_ENV
echo "- Minimal image updated: $LATEST_TAG" >> ./BODY
fi
- name: Check package updates
shell: bash -xe {0}
run: |
TAG_MINIMAL=$(cat ./TAG_MINIMAL)
TAG=$(cat ./TAG)
for img in ubuntu ubuntu-debug ubuntu-dev; do
docker pull ghcr.io/cybozu/$img:$TAG
docker buildx build --platform linux/amd64 -t $img:${{ matrix.ubuntu-version }}-new --load --build-arg TAG_MINIMAL=$TAG_MINIMAL --build-arg TAG=$TAG ./$img/
docker run --rm ghcr.io/cybozu/$img:$TAG dpkg -l > $img-$TAG
docker run --rm $img:${{ matrix.ubuntu-version }}-new dpkg -l > $img-${{ matrix.ubuntu-version }}-new
docker image rm $img:${{ matrix.ubuntu-version }}-new
if ! diff -u $img-$TAG $img-${{ matrix.ubuntu-version }}-new; then
echo "- $img:${{ matrix.ubuntu-version }}: package updated" >> ./BODY
echo "```diff" >> ./BODY
diff -u $img-$TAG $img-${{ matrix.ubuntu-version }}-new >> ./BODY || true
echo -e "```\n" >> ./BODY
if [ "$NEED_UPDATE" != "1" ]; then
echo "NEED_UPDATE=1" >> $GITHUB_ENV
fi
fi
done
- name: Create PR
if: env.NEED_UPDATE == '1'
shell: bash -xe {0}
run: |
TODAY=$(date "+%Y%m%d")
sed -i -e "s/${{ matrix.ubuntu-version }}\.[0-9]\{8\}/${{ matrix.ubuntu-version }}\.$TODAY/g" ./TAG
git config --global user.email "[email protected]"
git config --global user.name "cybozu-neco"
BRANCH=update-${{ matrix.ubuntu-version }}-$TODAY
git checkout -b $BRANCH
git add .
git commit -m "Update images for ${{ matrix.ubuntu-version }}"
git push origin $BRANCH
gh pr create --title "Update images for ${{ matrix.ubuntu-version }}" --body-file ./BODY