|
| 1 | +name: Build Bootc PodVM Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ devel ] |
| 6 | + paths: |
| 7 | + - 'config/peerpods/podvm/bootc/**' |
| 8 | + pull_request: |
| 9 | + branches: [ devel ] |
| 10 | + paths: |
| 11 | + - 'config/peerpods/podvm/bootc/**' |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + cloud_provider: |
| 15 | + description: 'Cloud provider (azure, aws, libvirt)' |
| 16 | + required: true |
| 17 | + default: 'azure' |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - azure |
| 21 | + - aws |
| 22 | + - libvirt |
| 23 | + |
| 24 | + build_disk: |
| 25 | + description: 'Build disk image from container' |
| 26 | + required: false |
| 27 | + default: true |
| 28 | + type: boolean |
| 29 | + container_variant: |
| 30 | + description: 'Container variant to convert to disk (standard or nvidia)' |
| 31 | + required: false |
| 32 | + default: 'standard' |
| 33 | + type: choice |
| 34 | + options: |
| 35 | + - standard |
| 36 | + - nvidia |
| 37 | + |
| 38 | +env: |
| 39 | + CLOUD_PROVIDER: ${{ github.event.inputs.cloud_provider || 'azure' }} |
| 40 | + |
| 41 | +jobs: |
| 42 | + build-container: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: Delete huge unnecessary tools folder |
| 46 | + run: rm -rf /opt/hostedtoolcache |
| 47 | + |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Docker Buildx |
| 52 | + uses: docker/setup-buildx-action@v3 |
| 53 | + |
| 54 | + - name: Build container image |
| 55 | + id: build |
| 56 | + uses: docker/build-push-action@v6 |
| 57 | + with: |
| 58 | + context: config/peerpods/podvm/bootc |
| 59 | + file: config/peerpods/podvm/bootc/Containerfile.fedora |
| 60 | + target: default-target |
| 61 | + build-args: | |
| 62 | + CLOUD_PROVIDER=${{ env.CLOUD_PROVIDER }} |
| 63 | + tags: podvm-bootc:${{ github.sha }} |
| 64 | + cache-from: type=gha |
| 65 | + cache-to: type=gha,mode=max |
| 66 | + platforms: linux/amd64 |
| 67 | + outputs: type=docker,dest=/tmp/podvm-bootc.tar |
| 68 | + |
| 69 | + - name: Upload container image artifact |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: podvm-bootc-container-${{ github.sha }} |
| 73 | + path: /tmp/podvm-bootc.tar |
| 74 | + retention-days: 7 |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + build-nvidia-container: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + if: github.event.inputs.cloud_provider == 'azure' || github.event_name != 'workflow_dispatch' |
| 81 | + steps: |
| 82 | + - name: Delete huge unnecessary tools folder |
| 83 | + run: rm -rf /opt/hostedtoolcache |
| 84 | + |
| 85 | + - name: Checkout repository |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Set up Docker Buildx |
| 89 | + uses: docker/setup-buildx-action@v3 |
| 90 | + |
| 91 | + - name: Build NVIDIA container image |
| 92 | + id: build |
| 93 | + uses: docker/build-push-action@v6 |
| 94 | + with: |
| 95 | + context: config/peerpods/podvm/bootc |
| 96 | + file: config/peerpods/podvm/bootc/Containerfile.fedora |
| 97 | + target: nvidia-podvm-bootc |
| 98 | + build-args: | |
| 99 | + CLOUD_PROVIDER=${{ env.CLOUD_PROVIDER }} |
| 100 | + tags: podvm-bootc-nvidia:${{ github.sha }} |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
| 103 | + platforms: linux/amd64 |
| 104 | + outputs: type=docker,dest=/tmp/podvm-bootc-nvidia.tar |
| 105 | + |
| 106 | + - name: Upload NVIDIA container image artifact |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: podvm-bootc-nvidia-container-${{ github.sha }} |
| 110 | + path: /tmp/podvm-bootc-nvidia.tar |
| 111 | + retention-days: 7 |
| 112 | + |
| 113 | + build-disk-image: |
| 114 | + runs-on: ubuntu-latest |
| 115 | + needs: [build-container, build-nvidia-container] |
| 116 | + if: github.event_name != 'pull_request' && (github.event.inputs.build_disk != 'false') && (always() && !cancelled() && !failure()) |
| 117 | + steps: |
| 118 | + - name: Delete huge unnecessary tools folder |
| 119 | + run: rm -rf /opt/hostedtoolcache |
| 120 | + |
| 121 | + - name: Checkout repository |
| 122 | + uses: actions/checkout@v4 |
| 123 | + |
| 124 | + - name: Set up Docker Buildx |
| 125 | + uses: docker/setup-buildx-action@v3 |
| 126 | + |
| 127 | + - name: Determine container variant |
| 128 | + run: | |
| 129 | + VARIANT="${{ github.event.inputs.container_variant || 'standard' }}" |
| 130 | + echo "CONTAINER_VARIANT=$VARIANT" >> $GITHUB_ENV |
| 131 | +
|
| 132 | + if [ "$VARIANT" = "nvidia" ]; then |
| 133 | + echo "ARTIFACT_NAME=podvm-bootc-nvidia-container-${{ github.sha }}" >> $GITHUB_ENV |
| 134 | + echo "CONTAINER_FILE=podvm-bootc-nvidia.tar" >> $GITHUB_ENV |
| 135 | + else |
| 136 | + echo "ARTIFACT_NAME=podvm-bootc-container-${{ github.sha }}" >> $GITHUB_ENV |
| 137 | + echo "CONTAINER_FILE=podvm-bootc.tar" >> $GITHUB_ENV |
| 138 | + fi |
| 139 | +
|
| 140 | + - name: Download container image artifact |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + name: ${{ env.ARTIFACT_NAME }} |
| 144 | + path: /tmp |
| 145 | + |
| 146 | + - name: Load container image |
| 147 | + run: | |
| 148 | + # Load the container image from the artifact |
| 149 | + echo "Loading container from: /tmp/${{ env.CONTAINER_FILE }}" |
| 150 | + docker load -i /tmp/${{ env.CONTAINER_FILE }} |
| 151 | +
|
| 152 | + # Get the loaded image name and tag |
| 153 | + IMAGE_NAME=$(docker images --format "table {{.Repository}}:{{.Tag}}" | grep -v REPOSITORY | head -n1) |
| 154 | + echo "Loaded image: $IMAGE_NAME (variant: ${{ env.CONTAINER_VARIANT }})" |
| 155 | + echo "LOADED_IMAGE=$IMAGE_NAME" >> $GITHUB_ENV |
| 156 | +
|
| 157 | + # Transfer image from Docker to Podman storage for bootc-image-builder |
| 158 | + echo "Transferring image to Podman storage..." |
| 159 | + docker save "$IMAGE_NAME" | sudo podman load |
| 160 | +
|
| 161 | + # Verify image is available in Podman |
| 162 | + sudo podman images | grep -E "(REPOSITORY|$(echo $IMAGE_NAME | cut -d: -f1))" |
| 163 | +
|
| 164 | + - name: Create output directory |
| 165 | + run: | |
| 166 | + mkdir -p output |
| 167 | + sudo chown -R $(id -u):$(id -g) output |
| 168 | +
|
| 169 | + - name: Convert container to disk image |
| 170 | + run: | |
| 171 | + echo "Converting container image: $LOADED_IMAGE" |
| 172 | +
|
| 173 | + # Convert bootc container to qcow2 disk image using the loaded image |
| 174 | + sudo podman run \ |
| 175 | + --rm \ |
| 176 | + --privileged \ |
| 177 | + --security-opt label=type:unconfined_t \ |
| 178 | + -v $(pwd)/config/peerpods/podvm/bootc/config.toml:/config.toml:ro \ |
| 179 | + -v $(pwd)/output:/output \ |
| 180 | + -v /var/lib/containers/storage:/var/lib/containers/storage \ |
| 181 | + quay.io/centos-bootc/bootc-image-builder:latest \ |
| 182 | + --type qcow2 \ |
| 183 | + --rootfs xfs \ |
| 184 | + --use-librepo=True \ |
| 185 | + "$LOADED_IMAGE" |
| 186 | +
|
| 187 | + - name: Compress disk image |
| 188 | + run: | |
| 189 | + cd output/qcow2 |
| 190 | + if [ -f disk.qcow2 ]; then |
| 191 | + echo "Compressing disk image..." |
| 192 | + xz -9 -T 0 disk.qcow2 |
| 193 | + ls -lah disk.qcow2.xz |
| 194 | + else |
| 195 | + echo "Error: disk.qcow2 not found" |
| 196 | + ls -la |
| 197 | + exit 1 |
| 198 | + fi |
| 199 | +
|
| 200 | + - name: Upload disk image artifact |
| 201 | + uses: actions/upload-artifact@v4 |
| 202 | + with: |
| 203 | + name: podvm-disk-${{ env.CONTAINER_VARIANT }}-${{ env.CLOUD_PROVIDER }}-${{ github.sha }} |
| 204 | + path: output/qcow2/disk.qcow2.xz |
| 205 | + retention-days: 30 |
| 206 | + |
| 207 | + - name: Generate disk image metadata |
| 208 | + run: | |
| 209 | + cd output/qcow2 |
| 210 | + if [ -f disk.qcow2.xz ]; then |
| 211 | + echo "DISK_SIZE=$(stat -c%s disk.qcow2.xz)" >> $GITHUB_ENV |
| 212 | + echo "DISK_SHA256=$(sha256sum disk.qcow2.xz | cut -d' ' -f1)" >> $GITHUB_ENV |
| 213 | + fi |
| 214 | +
|
| 215 | + - name: Create release info |
| 216 | + if: github.ref == 'refs/heads/devel' |
| 217 | + run: | |
| 218 | + cat > disk-info.json << EOF |
| 219 | + { |
| 220 | + "cloud_provider": "${{ env.CLOUD_PROVIDER }}", |
| 221 | + "container_variant": "${{ env.CONTAINER_VARIANT }}", |
| 222 | + "container_image": "${{ env.LOADED_IMAGE }}", |
| 223 | + "disk_size_bytes": "${{ env.DISK_SIZE }}", |
| 224 | + "disk_sha256": "${{ env.DISK_SHA256 }}", |
| 225 | + "build_date": "$(date -u +%Y-%m-%dT%H:%M:%SZ)", |
| 226 | + "git_commit": "${{ github.sha }}", |
| 227 | + "git_ref": "${{ github.ref }}" |
| 228 | + } |
| 229 | + EOF |
| 230 | +
|
| 231 | + - name: Upload disk metadata |
| 232 | + if: github.ref == 'refs/heads/devel' |
| 233 | + uses: actions/upload-artifact@v4 |
| 234 | + with: |
| 235 | + name: podvm-disk-metadata-${{ env.CONTAINER_VARIANT }}-${{ env.CLOUD_PROVIDER }}-${{ github.sha }} |
| 236 | + path: disk-info.json |
| 237 | + retention-days: 90 |
0 commit comments