Skip to content

Docker

Docker #494

Workflow file for this run

name: Docker
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
pull_request:
paths-ignore:
- 'README.md'
- '.github/*.y[a]?ml'
push:
branches: [ 'master' ]
tags: [ 'v*' ]
env:
BUILDKIT_PROGRESS: plain
GHCR: ghcr.io
REGISTRY: ${{ vars.REGISTRY }}
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
REPO: ${{ vars.REPO }}
PUSH_IMAGE: ${{ github.event_name != 'pull_request' }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
actions: write # See https://docs.github.com/en/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
contents: read
packages: write
steps:
# Checkout the repository
- name: Checkout 🎯
uses: actions/checkout@v4
with:
fetch-depth: 1
# Get current year
- name: Get current year πŸ“…
id: get-year
shell: bash
run: echo "year=$(date +%Y)" >> ${GITHUB_OUTPUT}
- name: Restore cached repository πŸ“¦
id: restore
uses: actions/cache/restore@v4
with:
path: texlive/
key: rsync-TL${{ steps.get-year.outputs.year }}-${{ github.sha }}
restore-keys: |
rsync-TL${{ steps.get-year.outputs.year }}-
rsync-
enableCrossOsArchive: true
fail-on-cache-miss: false
- name: Run rsync πŸ“
shell: bash
run: |
echo "::group::rsync"
script/rsync.sh ${{ env.REPO }} texlive/ --exclude-from=rsyncignore.txt
echo "::endgroup::"
echo "::group::Repository tree"
tree -nh texlive/
echo "::endgroup::"
- name: Get TeX Live release version πŸ”–
id: tl-release
shell: bash
run: echo "number=$(find ${{ github.workspace }}/texlive/ -name 'TEXLIVE_*' -print0 | sed -e s/[^0-9]//g)" >> ${GITHUB_OUTPUT}
- name: Save repository to cache πŸ’Ύ
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
uses: actions/cache/save@v4
with:
path: texlive/
key: rsync-TL${{ steps.tl-release.outputs.number }}-${{ github.sha }}
enableCrossOsArchive: true
# Workaround: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
- name: Delete old repo cache πŸ—‘οΈ
if: ${{ steps.restore.outputs.cache-hit }}
shell: bash
run: |
gh extension install actions/gh-actions-cache
[ $(gh actions-cache list -R ${{ github.repository }} -B ${{ github.ref }} --key rsync- | wc -l) -lt 2 ] && exit 0
gh actions-cache delete ${{ steps.restore.outputs.cache-matched-key }} -R ${{ github.repository }} --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU πŸ’»
uses: docker/setup-qemu-action@v3
- name: Setup buildx πŸ”§
uses: docker/setup-buildx-action@v3
- name: Extract metadata πŸ”
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR }}/${{ github.repository }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
bake-target: metadata-action-bullseye-full
flavor: |
latest=auto
prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,onlatest=false
tags: |
type=schedule,pattern=nightly
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha,prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,format=short
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
# Read platforms as CSV from bake file
- name: Read platforms from bake file πŸ”
id: get-platforms
shell: bash
run: |
echo "platform=$(docker buildx bake -f docker-bake.hcl --print _platforms | jq -cr '.target._platforms.platforms | @csv' | tr -d '"')" >> ${GITHUB_OUTPUT}
- name: Log into GitHub registry πŸ“‡
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Login to another registry
- name: Log into ${{ env.REGISTRY }} πŸ“‡
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# Free up disk space
# Workaround: actions/runner-images#2840
- name: Free up disk space πŸ—‘οΈ
# Since this step is not critical as long as the space is freed up, we can ignore errors
continue-on-error: true
shell: bash
run: |
echo "::group::Current disk space usage"
echo "Listing 100 largest packages"
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
df -h
echo "::endgroup::"
echo "::group::Purging apt packages"
echo "Removing large packages"
sudo apt purge -qy \
'^dotnet-.*' '^mono.*' \
'^llvm-.*' '^libllvm.*' '^clang-.*' '^libclang.*' \
'^gfortran-.*' \
'^mysql.*' '^postgresql.*' '^mongodb.*'
sudo apt purge -qy \
azure-cli \
microsoft-edge-stable \
google-chrome-stable \
firefox \
powershell \
nginx \
libgl1-mesa-dri
sudo apt autoremove -qy
sudo apt clean -qy
df -h
echo "::endgroup::"
echo "Removing large directories..."
sudo rm -rf \
${AGENT_TOOLSDIRECTORY} \
/usr/share/dotnet \
/usr/local/graalvm/ \
/usr/local/.ghcup/ \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/chromium \
/usr/local/share/edge_driver \
/usr/local/share/powershell \
/usr/local/share/vcpkg
df -h
docker system df
- name: Build / Push image 🐳
uses: docker/bake-action@v4
with:
files: |
docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
set: |
*.cache-to=type=registry,mode=max,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache,oci-mediatypes=true
*.cache-from=type=registry,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache
*.platform=${{ steps.get-platforms.outputs.platform }}
env:
PUSH: ${{ fromJson(env.PUSH_IMAGE) }}
# NOTE: More space is required to run the upload-artifact action
- name: Cleanup CWD 🧹
if: ${{ ! fromJson(env.PUSH_IMAGE) }}
shell: bash
run: |
echo "::group::Current disk"
df -h
tree -nhL 2
echo "::endgroup::"
rm -rf texlive
df -h
- name: Upload artifacts πŸ“š
if: ${{ ! fromJson(env.PUSH_IMAGE) }}
uses: actions/upload-artifact@v4
with:
name: TL${{ steps.tl-release.outputs.number }}
path: texlive.oci
if-no-files-found: error