From 931992753246e2f17c8a119383280f08d2c824b6 Mon Sep 17 00:00:00 2001 From: greg pereira Date: Mon, 6 May 2024 09:03:04 -0700 Subject: [PATCH] allow override of image as a while and workflow creation Signed-off-by: greg pereira --- .github/workflows/iso_builder_test.yaml | 99 +++++++++++++++++++++++++ .gitignore | 2 + training/iso-builder/ISOs/.gitkeep | 0 training/iso-builder/Makefile | 13 +++- 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/iso_builder_test.yaml create mode 100644 training/iso-builder/ISOs/.gitkeep diff --git a/.github/workflows/iso_builder_test.yaml b/.github/workflows/iso_builder_test.yaml new file mode 100644 index 000000000..165e17e5c --- /dev/null +++ b/.github/workflows/iso_builder_test.yaml @@ -0,0 +1,99 @@ +name: Iso Builder Test Worfklow + +on: + pull_request: + branches: + - main + paths: + - './training/iso-builder/**' + - '!training/iso-builder/README.md' + - '.github/workflows/iso_builder_test.yaml' + push: + branches: + - main + paths: + - './training/iso-builder/**' + - '!training/iso-builder/README.md' + - '.github/workflows/iso_builder_test.yaml' + + workflow_dispatch: + +env: + REGISTRY: quay.io + REGISTRY_ORG: ai-lab + +jobs: + iso-builder-build-and-test: + if: "!contains(github.event.pull_request.labels.*.name, 'hold-tests')" + strategy: + matrix: + include: + - platforms: linux/amd64,linux/arm64 + parent_image_registry: quay.io + parent_image_org: centos-bootc + parent_image_name: centos-bootc + parent_image_tag: stream9 + iso_image_name: iso-builder-centos-bootc + iso_download_url: https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso + iso_name: CentOS-Stream-9-latest-x86_64-boot.iso + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + steps: + + - name: Remove unnecessary files + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + + - uses: actions/checkout@v4.1.4 + + - name: Install qemu dependency + run: | + sudo apt-get update + sudo apt-get install -y qemu-user-static + + - name: Generate an SSH key + id: ssh-keygen + run: | + ssh-keygen -t ed25519 -C "ai-lab-recipes@redhat.com" -N "" -f id_rsa + echo "sshpubkey=$(cat id_rsa.pub | xargs)" >> $GITHUB_OUTPUT + + - name: Download the ISO + working-directory: ./training/iso-builder/ + run: | + make centos-iso-download + + - name: Build Image + id: build_image + working-directory: ./training/iso-builder/ + run: | + make image FROM=${{ matrix.parent_image_registry }}/${{ matrix.parent_image_org }}/${{ matrix.parent_image_name }}:${{ matrix.parent_image_tag }} IMAGE_NAME=${{ matrix.iso_image_name }} IMAGE_TAG=${{ matrix.parent_image_tag }} + echo "embedded_image=$(echo '${{ matrix.parent_image_registry }}/${{ matrix.parent_image_org }}/${{ matrix.parent_image_name }}:${{ matrix.parent_image_tag }}' | xargs)" >> $GITHUB_OUTPUT + echo "produced_image=$(echo '${{env.REGISTRY}}/${{env.REGISTRY_ORG}}/${{ matrix.iso_image_name }}:${{ matrix.parent_image_tag }}' | xargs)" >> $GITHUB_OUTPUT + + - name: Run the Image + working-directory: ./training/iso-builder/ + run: | + make iso IMAGE=${{ steps.build_image.outputs.produced_image }} EMBED_IMAGE=${{ steps.build_image.outputs.embedded_image }} ORIGINAL_ISO="ISOs/${{ matrix.iso_name }}" SSHKEY="${{ steps.ssh-keygen.outputs.sshpubkey }}" CONTAINER_TOOL_EXTRA_ARGS=--pull=never + + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3.18 + timeout-minutes: 10 + with: + detached: false + limit-access-to-actor: true + + # - name: Publish Job Results to Slack + # id: slack + # if: always() + # uses: slackapi/slack-github-action@v1.26.0 + # with: + # payload: | + # { + # "text": "${{ github.workflow }} workflow status: ${{ job.status }}\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + # } + # env: + # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.gitignore b/.gitignore index 347e2d36a..f4080f98c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ recipes/common/bin/* */.venv/ training/cloud/examples training/instructlab/instructlab +training/iso-builder/ISOs/* +!training/iso-builder/ISOs/.gitkeep diff --git a/training/iso-builder/ISOs/.gitkeep b/training/iso-builder/ISOs/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/training/iso-builder/Makefile b/training/iso-builder/Makefile index 07a554a6f..166fc0d26 100644 --- a/training/iso-builder/Makefile +++ b/training/iso-builder/Makefile @@ -4,20 +4,21 @@ REGISTRY ?= quay.io REGISTRY_ORG ?= ai-lab IMAGE_NAME ?= iso-builder IMAGE_TAG ?= latest +IMAGE ?= ${REGISTRY}/${REGISTRY_ORG}/${IMAGE_NAME}:${IMAGE_TAG} CONTAINER_TOOL ?= podman CONTAINER_TOOL_EXTRA_ARGS ?= EMBED_IMAGE ?= -ORIGINAL_ISO ?= +ORIGINAL_ISO ?= SSHKEY ?= OUTPUT_DIR ?= ./iso -.PHONY: image iso +.PHONY: image iso centos-iso-download image: "${CONTAINER_TOOL}" build \ --file Containerfile \ - --tag "${REGISTRY}/${REGISTRY_ORG}/${IMAGE_NAME}:${IMAGE_TAG}" \ + --tag "${IMAGE}" \ $(FROM:%=--from=%) \ $(MODEL_REPO:%=--build-arg MODEL_REPO=%) \ $(MODEL_PATH:%=--build-arg MODEL_PATH=%) \ @@ -44,9 +45,13 @@ iso: --volume $(shell readlink -f ${ORIGINAL_ISO}):/root/original.iso:ro \ --volume ${OUTPUT_DIR}:/output \ --volume $(shell ${CONTAINER_TOOL} system info --format json | jq -r '.store.graphRoot'):/var/lib/containers/storage \ - "${REGISTRY}/${REGISTRY_ORG}/${IMAGE_NAME}:${IMAGE_TAG}" \ + "${IMAGE}" \ "${EMBED_IMAGE}" \ /root/ks.template \ "${SSHKEY}" \ /root/original.iso \ + ${CONTAINER_TOOL_EXTRA_ARGS} \ "/output/$(shell basename ${EMBED_IMAGE}).iso" + +centos-iso-download: + curl -sL https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso -o ISOs/CentOS-Stream-9-latest-x86_64-boot.iso