Skip to content

Commit 13c7f75

Browse files
committed
agent: add container build ci
1 parent 09a70ab commit 13c7f75

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and push container image
2+
3+
# Configures this workflow to run every time a tag is created
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- docker-ci
9+
paths:
10+
- agent/**
11+
- .github/workflows/build_agent_container.yaml
12+
13+
# NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long
14+
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
15+
16+
17+
# 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.
18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
23+
jobs:
24+
build-and-push-image:
25+
runs-on: ubuntu-latest
26+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
27+
permissions:
28+
contents: read
29+
packages: write
30+
attestations: write
31+
id-token: write
32+
#
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
# 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.
37+
- name: Log in to the Container registry
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ${{ env.REGISTRY }}
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
44+
# Setup for multi-platform
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Check outputs
52+
run: cd agent && make docker-build-only
53+
env:
54+
AGENT_IMAGE: ${{env.IMAGE_NAME}}/agent
55+
TAGS: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent:${{ env.GITHUB_SHA }}
56+
57+
# 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).
58+
- name: Generate artifact attestation
59+
uses: actions/attest-build-provenance@v2
60+
with:
61+
subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent
62+
subject-digest: ${{ steps.push.outputs.digest }}
63+
push-to-registry: true
64+

agent/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ docker-setup:
6666
docker buildx create --platform linux/amd64,linux/arm64 --use builder
6767
docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64
6868

69+
.PHONY: docker-build-only
70+
docker-build-only:
71+
@TAGS="-t $(REGISTRY)/$(AGENT_IMAGE):$(shell date +%y.%m.%d-%H%M%S)-$(COMMIT_SHORT_SHA) $(TAGS)"
72+
docker buildx build $(BUILD_ARGS) --platform linux/amd64,linux/arm64 $(TAGS) -f docker/Dockerfile .
73+
6974
##@ Docker Build
7075
.PHONY: docker-build
71-
docker-build docker-setup ## Builds skyhook-agent docker image using docker buildx.
72-
@TAGS="-t $(REGISTRY)/$(AGENT_IMAGE):$(shell date +%y.%m.%d-%H%M%S)-$(COMMIT_SHORT_SHA)"
73-
docker buildx build $(BUILD_ARGS) --platform linux/amd64,linux/arm64 $(TAGS) -f docker/Dockerfile .
76+
docker-build-only docker-setup ## Builds skyhook-agent docker image using docker buildx.
77+
@echo "Building skyhook-agent docker image"
7478

7579
##@ Vendor
7680
.PHONY: vendor

0 commit comments

Comments
 (0)