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

      - name: Set up Docker
        uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # 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@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.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
