From f3a14aa8297ac1ad6346b4d34b1202b5e1e8dc64 Mon Sep 17 00:00:00 2001 From: Alex Yuskauskas Date: Thu, 30 Jan 2025 10:47:18 -0800 Subject: [PATCH] feat(ci/githubi/agent): organize each container build into its own workflow for clarity and appropriate filters on file changes Change to build on PR, commits to main and agent/* tags --- .github/workflows/agent-ci.yaml | 1 + .github/workflows/agent-container.yaml | 99 +++++++++++++++++++ .github/workflows/agent-coverage.yaml | 21 ---- ...ontainer.yaml => agentless-container.yaml} | 58 +---------- agent/Makefile | 1 + 5 files changed, 104 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/agent-container.yaml delete mode 100644 .github/workflows/agent-coverage.yaml rename .github/workflows/{build_agent_container.yaml => agentless-container.yaml} (52%) diff --git a/.github/workflows/agent-ci.yaml b/.github/workflows/agent-ci.yaml index f9ad6dba..8481f017 100644 --- a/.github/workflows/agent-ci.yaml +++ b/.github/workflows/agent-ci.yaml @@ -3,6 +3,7 @@ on: pull_request: paths: - agent/** + - .github/workflows/agent-ci.yaml jobs: test: name: Skyhook Agent Unit Tests diff --git a/.github/workflows/agent-container.yaml b/.github/workflows/agent-container.yaml new file mode 100644 index 00000000..8780dcd2 --- /dev/null +++ b/.github/workflows/agent-container.yaml @@ -0,0 +1,99 @@ +name: Build and push agent container image + +# Configures this workflow to run every time a tag is created +on: + pull_request: + branches: + - main + paths: + - agent/** + - containers/agent.Dockerfile + - .github/workflows/agent-container.yaml + push: + branches: + - main + tags: + - agent/* + paths: + - agent/** + - containers/agent.Dockerfile + - .github/workflows/agent-container.yaml + +# NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long +# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners + + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-agent: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Setup for multi-platform + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build the agent container image + id: build + run: | + apt-get update && apt-get install -y make git jq + cd agent + # if this is a tag build, use the tag as the version, otherwise use the sha + TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${{ github.sha }}" + case ${{ github.ref_type }} in + branch) + # The last tag + current git sha + export AGENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")+${{ github.sha }} + ;; + tag) + # The version part of the tag + export AGENT_VERSION=$(echo "${{ github.ref_name }}" | cut -f 2 -d /) + TAGS="$TAGS -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${AGENT_VERSION}" + ;; + *) + echo "Unkown type ${{ github.ref_type }}" + exit 1 + ;; + esac + export TAGS=$TAGS + export REGISTRY=${REGISTRY@L} + export BUILD_ARGS="--push" + make docker-build-only agent_version=${AGENT_VERSION} + cat metadata.json + echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + env: + AGENT_IMAGE: ${{env.IMAGE_NAME}}/agent + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v2 + with: + subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true + diff --git a/.github/workflows/agent-coverage.yaml b/.github/workflows/agent-coverage.yaml deleted file mode 100644 index 67c22589..00000000 --- a/.github/workflows/agent-coverage.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Post coverage comment -on: - workflow_run: - workflows: ["Agent Unittest"] - types: - - completed -jobs: - test: - name: Run tests & display coverage - runs-on: ubuntu-latest - if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' - permissions: - pull-requests: write - contents: write - actions: read - steps: - - name: Post comment - uses: py-cov-action/python-coverage-comment-action@v3 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} \ No newline at end of file diff --git a/.github/workflows/build_agent_container.yaml b/.github/workflows/agentless-container.yaml similarity index 52% rename from .github/workflows/build_agent_container.yaml rename to .github/workflows/agentless-container.yaml index 0f9a4d3a..802e0ebf 100644 --- a/.github/workflows/build_agent_container.yaml +++ b/.github/workflows/agentless-container.yaml @@ -1,4 +1,4 @@ -name: Build and push container image +name: Build and push agentless container image # Configures this workflow to run every time a tag is created on: @@ -6,8 +6,8 @@ on: branches: - main paths: - - agent/** - - .github/workflows/build_agent_container.yaml + - containers/agentless/** + - .github/workflows/agentless-container.yaml # NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long # https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners @@ -19,59 +19,7 @@ env: IMAGE_NAME: ${{ github.repository }} DOCKER_CMD: docker -# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. jobs: - build-and-push-agent: - runs-on: ubuntu-latest - # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. - permissions: - contents: read - packages: write - attestations: write - id-token: write - # - steps: - - name: Checkout repository - uses: actions/checkout@v4 - # Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Setup for multi-platform - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build the agent container image - id: build - run: | - apt-get update && apt-get install -y make git jq - cd agent - export TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${{ github.sha }}" - export REGISTRY=${REGISTRY@L} - # Get the last tag and use it as the env var AGENT_VERSION if it doesn't exist use 0.0.0+{github.sha} - export AGENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0+${{ github.sha }}") - make docker-build-only agent_version=${AGENT_VERSION} - cat metadata.json - echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT - cat $GITHUB_OUTPUT - env: - AGENT_IMAGE: ${{env.IMAGE_NAME}}/agent - - # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). - - name: Generate artifact attestation - uses: actions/attest-build-provenance@v2 - with: - subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent - subject-digest: ${{ steps.build.outputs.digest }} - push-to-registry: true - build-and-publish-agentless: runs-on: ubuntu-latest # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. diff --git a/agent/Makefile b/agent/Makefile index 5a5cf348..ee9738c0 100644 --- a/agent/Makefile +++ b/agent/Makefile @@ -15,6 +15,7 @@ VENV := ./venv/bin/ REGISTRY ?= nvcr.io AGENT_IMAGE ?= nvidian/swgpu-baseos/skyhook-agent +DOCKER_CMD ?= docker .PHONY: all all: venv test