Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/build_agent_container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build and push container image

# Configures this workflow to run every time a tag is created
on:
push:
branches:
- main
- docker_ci
paths:
- agent/**
- .github/workflows/build_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-image:
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 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

40 changes: 23 additions & 17 deletions agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ help: ## Display this help.
venv: ## Sets up a python venv at `./venv`
python3 -m venv venv
$(VENV)pip install hatch coverage
$(VENV)hatch config set dirs.project "[\"${PWD}\"]"
$(VENV)hatch config set dirs.project "[\"$(shell pwd)\"]"

##@ Test
.PHONY: test
Expand All @@ -46,43 +46,49 @@ format:

##@ Build
.PHONY: build
build: ## Builds using hatch to `skyhook-agent/dist`
$(VENV)hatch -p skyhook-agent version ${1:unkown}
build: ## Builds using hatch to `dist`
$(VENV)hatch -p skyhook-agent version $(build_version)
$(VENV)hatch -p skyhook-agent build -c

##@ Publish
.PHONY: publish
publish: ## Publishes using hatch
$(VENV)hatch -p skyhook-agent publish

DOCKER_CMD ?= docker
BUILD_ARGS ?=
ifndef GITLAB_CI
BUILD_ARGS = --push
COMMIT_SHORT_SHA := $(shell git rev-parse --short HEAD)
endif

docker-setup:
test ! $(docker context ls | grep builder) || docker context create builder;
docker buildx create --platform linux/amd64,linux/arm64 --use builder
docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64
test ! $($(DOCKER_CMD) context ls | grep builder) || $(DOCKER_CMD) context create builder;
$(DOCKER_CMD) buildx create --platform linux/amd64,linux/arm64 --use builder
$(DOCKER_CMD) run --privileged --rm tonistiigi/binfmt --install amd64,arm64

ACTUAL_TAGS=$(shell echo "-t $(REGISTRY)/$(AGENT_IMAGE):$(shell date +%y.%m.%d-%H%M%S)-$(COMMIT_SHORT_SHA) $(TAGS)" | tr A-Z a-z)
.PHONY: docker-build-only
docker-build-only:
@echo "Building skyhook-agent $(DOCKER_CMD) image with tags: $(ACTUAL_TAGS)"
$(DOCKER_CMD) buildx build $(BUILD_ARGS) --build-arg AGENT_VERSION=$(AGENT_VERSION) --platform linux/amd64,linux/arm64 $(ACTUAL_TAGS) --metadata-file=metadata.json -f docker/Dockerfile .

##@ Docker Build
.PHONY: docker-build
docker-build docker-setup ## Builds skyhook-agent docker image using docker buildx.
@TAGS="-t $(REGISTRY)/$(AGENT_IMAGE):$(shell date +%y.%m.%d-%H%M%S)-$(COMMIT_SHORT_SHA)"
docker buildx build $(BUILD_ARGS) --platform linux/amd64,linux/arm64 $(TAGS) -f docker/Dockerfile .
docker-build: docker-build-only docker-setup ## Builds skyhook-agent docker image using docker buildx.
@echo "Built skyhook-agent $(DOCKER_CMD) image."

##@ Vendor
.PHONY: vendor
vendor: ## Uses Unearth to vendor all dependencies locally.
python3 -m venv ./venv_vendor
./venv_vendor/bin/pip install unearth toml
dependencies=$(shell python -c 'import toml; print(" ".join(toml.loads(open("skyhook-agent/pyproject.toml","r").read())["project"]["dependencies"]))')
rm -rf vendor
mkdir -p vendor
for dep in $(dependencies); do \
./venv_vendor/bin/unearth --no-binary -d ./vendor $(dep) >> vendor/lock_file; \
done
python3 -m venv ./venv_vendor
./venv_vendor/bin/pip install unearth toml
dependencies=$(shell python -c 'import toml; print(" ".join(toml.loads(open("skyhook-agent/pyproject.toml","r").read())["project"]["dependencies"]))')
rm -rf vendor
mkdir -p vendor
for dep in $(dependencies); do \
./venv_vendor/bin/unearth --no-binary -d ./vendor $(dep) >> vendor/lock_file; \
done

##@ Clean
.PHONY: clean
Expand Down
15 changes: 9 additions & 6 deletions agent/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM python:3.10-alpine as builder
FROM python:3.12-alpine AS builder

ARG CI_COMMIT_TAG:-0.0.0
ARG AGENT_VERSION

COPY . /code
WORKDIR /code
RUN apk add bash
RUN USE_VENV=false /code/cmds.sh setup
RUN USE_VENV=false /code/cmds.sh build ${CI_COMMIT_TAG}
RUN echo "AGENT_VERSION=${AGENT_VERSION}"
RUN apk update && apk add bash make build-base gcc python3-dev musl-dev linux-headers
RUN make test
RUN make clean
RUN make venv
RUN make build build_version=${AGENT_VERSION}

FROM python:3.10-alpine
FROM python:3.12-alpine

RUN mkdir -p /skyhook-agent-wheels
COPY --from=builder /code/skyhook-agent/dist/* /skyhook-agent-wheels
Expand Down
7 changes: 3 additions & 4 deletions agent/hatch.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mode = "local"

[envs.default]
dependencies = [
"coverage[toml]",
Expand All @@ -16,7 +18,7 @@ cov = [
]

[[envs.all.matrix]]
python = ["3.8", "3.9", "3.10"]
python = ["3.12"]

[envs.lint]
detached = true
Expand All @@ -40,6 +42,3 @@ all = [
"style",
"typing",
]

[version]
source = "vcs"
File renamed without changes.
Empty file added agent/skyhook-agent/README.md
Empty file.
7 changes: 4 additions & 3 deletions agent/pyproject.toml → agent/skyhook-agent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -34,6 +34,7 @@ Source = "https://github.com/nvidia.com/skyhook"
[project.scripts]
controller = "skyhook_agent.controller:cli"


[tool.hatch.version]
path = "src/skyhook_agent/__about__.py"

Expand Down Expand Up @@ -61,8 +62,8 @@ omit = [
]

[tool.coverage.paths]
skyhook_agent = ["src/skyhook_agent", "*/skyhook-agent/src/skyhook_agent"]
tests = ["tests", "*/skyhook-agent/tests"]
skyhook_agent = ["src/skyhook_agent", "*/src/skyhook_agent"]
tests = ["tests", "*/tests"]

[tool.coverage.report]
exclude_lines = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
__version__ = "0.0.6"
__version__ = "0.0.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.