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

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@v6

      - name: Set up Docker
        uses: docker/setup-docker-action@v5
        with:
          version: type=image,tag=28
          daemon-config: '{"features":{"containerd-snapshotter":true}}'
          set-host: true
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - 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@v6
        with:
          name: images-${{ matrix.arch }}
          path: dist/artifacts/k3s-airgap-images-${{ matrix.arch }}.*
          if-no-files-found: error
          retention-days: 7
