From 1efcb882619a90ed0f9355cd8485f7aa80ebb324 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Wed, 19 Mar 2025 08:51:09 -0400 Subject: [PATCH] Try using ko to build images Signed-off-by: Xe Iaso --- .github/workflows/docker.yml | 24 +++--- .ko.yaml | 13 ++++ Brewfile | 3 +- CHANGELOG.md | 3 + cmd/containerbuild/.gitignore | 1 + cmd/containerbuild/main.go | 133 ++++++++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 11 deletions(-) create mode 100644 .ko.yaml create mode 100644 cmd/containerbuild/.gitignore create mode 100644 cmd/containerbuild/main.go diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 958f9eb..5aa85db 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,6 +8,9 @@ on: pull_request: branches: [ "main" ] +env: + DOCKER_METADATA_SET_OUTPUT_ENV: "true" + permissions: contents: read packages: write @@ -20,6 +23,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -27,6 +33,12 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - uses: actions/setup-go@v5 + with: + go-version: '1.24.x' + + - uses: ko-build/setup-ko@v0.8 + - name: Log into registry uses: docker/login-action@v3 with: @@ -42,16 +54,8 @@ jobs: - name: Build and push id: build - uses: docker/build-push-action@v6 - with: - context: . - cache-to: type=gha - cache-from: type=gha - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/arm64/v8,linux/amd64 - sbom: true - push: true + run: | + go run ./cmd/containerbuild --docker-repo ghcr.io/techarohq/anubis --slog-level debug - name: Generate artifact attestation uses: actions/attest-build-provenance@v2 diff --git a/.ko.yaml b/.ko.yaml new file mode 100644 index 0000000..35c1fa0 --- /dev/null +++ b/.ko.yaml @@ -0,0 +1,13 @@ +defaultBaseImage: cgr.dev/chainguard/static +defaultPlatforms: +- linux/arm64 +- linux/amd64 +- linux/arm/v7 + +builds: +- id: anubis + main: ./cmd/anubis + ldflags: + - -s -w + - -extldflags "-static" + - -X github.com/TecharoHQ/anubis.Version={{.Env.VERSION}} diff --git a/Brewfile b/Brewfile index 883ba6b..2b6b486 100644 --- a/Brewfile +++ b/Brewfile @@ -1,3 +1,4 @@ # programming languages brew "go@1.24" -brew "node" \ No newline at end of file +brew "node" +brew "ko" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d6a37f..c530507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Images are built using ko instead of `docker buildx build` + [#13](https://github.com/TecharoHQ/anubis/pull/13) + ## 1.12.1 - Phrasing in the `