name: Airgap Image Tarballs
on:
  pull_request:
    paths:
      - "scripts/package-airgap"
      - "scripts/airgap/image-list.txt"
      - ".github/workflows/airgap.yaml"
  workflow_call: {}

permissions:
  contents: read

jobs:
  build-airgap:
    name: Export Images (${{ matrix.arch }})
    runs-on: ubuntu-latest # Runs on standard runner, docker pulls with --platform
    strategy:
      matrix:
        arch: [amd64, arm64, arm]

    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

      - name: Set up Docker
        uses: docker/setup-docker-action@0234bb73ccb40f0c430b795634f9247e2b5c2d23 # v5
        with:
          version: type=image,tag=29
          daemon-config: '{"features":{"containerd-snapshotter":true}}'
          set-host: true
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0

      - name: Install Dependencies
        run: sudo apt-get update -y && sudo apt-get install -y zstd pigz

      - name: Create Airgap Package
        run: |
          mkdir -p ./dist/artifacts
          export CONTAINERD_ADDRESS=$(docker info --format '{{.Containerd.Address}}')
          sudo chgrp $(id -g) $CONTAINERD_ADDRESS $(dirname $CONTAINERD_ADDRESS)
          ./scripts/package-airgap ${{ matrix.arch }}

      - name: Upload Artifacts
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: images-${{ matrix.arch }}
          path: dist/artifacts/k3s-airgap-images-${{ matrix.arch }}.*
          if-no-files-found: error
          retention-days: 7
