Skip to content

Commit

Permalink
build: Use ko for image building
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Oct 16, 2023
1 parent 03ae17c commit b4dde60
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 194 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ jobs:
with:
enable-cache: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Run e2e tests
run: devbox run -- make e2e-test
env:
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/release-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ jobs:
with:
enable-cache: true

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Release
run: devbox run -- make release
env:
Expand Down
1 change: 0 additions & 1 deletion .go-tools

This file was deleted.

81 changes: 33 additions & 48 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,21 @@ builds:
- amd64
- arm64
mod_timestamp: '{{ .CommitTimestamp }}'
hooks:
post:
- cmd: make SKIP_UPX={{ if index .Env "SKIP_UPX" }}{{ .Env.SKIP_UPX }}{{ else }}{{ .IsSnapshot }}{{ end }} GOOS={{ .Os }} GOARCH={{ .Arch }} UPX_TARGET={{ .Path }} upx

upx:
- enabled: "{{ not .IsSnapshot }}"
goos:
- linux
compress: "9"
lzma: true
- enabled: "{{ not .IsSnapshot }}"
goos:
- windows
goarch:
- amd64
compress: "9"
lzma: true

archives:
- name_template: '{{ .ProjectName }}_v{{trimprefix .Version "v"}}_{{ .Os }}_{{ .Arch }}'
format_overrides:
Expand All @@ -58,51 +70,24 @@ archives:
builds:
- mindthegap
rlcp: true
dockers:
- image_templates:
# Specify the image tag including `-amd64` suffix if the build is not a snapshot build or is not being built on
# arm64 machine. This allows for using the snapshot image build without the archtecture specific suffix
# consistently on local machines, i.e. can always use `ghcr.io/mesosphere/mindthegap:v<VERSION>` on the machine the snapshot
# is built on.
#
# For a release build the `-amd64` suffix will always be included and the `docker_manifests` specification below
# will create the final multiplatform manifest to be pushed to the registry.
- 'ghcr.io/mesosphere/mindthegap:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "amd64")) }}-amd64{{ end }}'
use: buildx
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=mindthegap"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- image_templates:
# Specify the image tag including `-amd64v8` suffix if the build is not a snapshot build or is not being built on
# arm64 machine. This allows for using the snapshot image build without the archtecture specific suffix
# consistently on local machines, i.e. can always use `ghcr.io/mesosphere/mindthegap:v<VERSION>` on the machine the snapshot
# is built on.
#
# For a release build the `-amd64v8` suffix will always be included and the `docker_manifests` specification below
# will create the final multiplatform manifest to be pushed to the registry.
- 'ghcr.io/mesosphere/mindthegap:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "arm64")) }}-arm64v8{{ end }}'
use: buildx
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=mindthegap"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
docker_manifests:
- name_template: ghcr.io/mesosphere/mindthegap:v{{trimprefix .Version "v"}}
image_templates:
- ghcr.io/mesosphere/mindthegap:v{{trimprefix .Version "v"}}-amd64
- ghcr.io/mesosphere/mindthegap:v{{trimprefix .Version "v"}}-arm64v8

kos:
- id: mindthegap
build: mindthegap
labels:
org.opencontainers.image.created: "{{ .CommitDate }}"
org.opencontainers.image.title: mindthegap
org.opencontainers.image.revision: "{{ .FullCommit }}"
org.opencontainers.image.version: v{{trimprefix .Version "v"}}
org.opencontainers.image.source: "{{ .GitURL }}"
platforms:
- linux/amd64
- linux/arm64
repository: ghcr.io/mesosphere/mindthegap
bare: true
tags:
- v{{trimprefix .Version "v"}}

checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
10 changes: 0 additions & 10 deletions .tool-versions

This file was deleted.

1 change: 1 addition & 0 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"findutils@latest",
"ginkgo@latest",
"git@latest",
"path:./hack/flakes/go-mod-upgrade",
"gnused@latest",
"gnugrep@latest",
"gnumake@latest",
Expand Down
22 changes: 18 additions & 4 deletions devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,24 @@
"version": "0.11.0"
},
"goreleaser@latest": {
"last_modified": "2023-07-23T03:35:12Z",
"resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#goreleaser",
"source": "devbox-search",
"version": "1.19.2"
"last_modified": "2023-10-01T23:11:39Z",
"resolved": "github:NixOS/nixpkgs/f8be2c43b4b1c1aec02f741ae909696b8410ebc1#goreleaser",
"source": "devbox-search",
"version": "1.21.2",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/x9zmzrlmgwrvh8873yj4gyfwirzmr56q-goreleaser-1.21.2"
},
"aarch64-linux": {
"store_path": "/nix/store/p33a0pj50ajjhqr5af7p3gz9m4x6kxps-goreleaser-1.21.2"
},
"x86_64-darwin": {
"store_path": "/nix/store/bcxrzsd200xxj50y3rm214brig4g4gbb-goreleaser-1.21.2"
},
"x86_64-linux": {
"store_path": "/nix/store/qn65854flb2l2kb0168c3ci24ra0irm6-goreleaser-1.21.2"
}
}
},
"gotestsum@latest": {
"last_modified": "2023-07-23T03:35:12Z",
Expand Down
44 changes: 44 additions & 0 deletions hack/flakes/go-mod-upgrade/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions hack/flakes/go-mod-upgrade/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2023 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{
description = "Update outdated Go dependencies interactively";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils/v1.0.0";
};

outputs =
{ self
, nixpkgs
, utils
,
}:
let
appReleaseVersion = "0.9.1";
appReleaseBinaries = {
"x86_64-linux" = {
fileName = "go-mod-upgrade_${appReleaseVersion}_Linux_x86_64.tar.gz";
sha256 = "38b7f36b275fa08bedf0e4c7fb1eaf256fa632a7489abe7c40a1d2b87a688b01";
};
"x86_64-darwin" = {
fileName = "go-mod-upgrade_${appReleaseVersion}_Darwin_x86_64.tar.gz";
sha256 = "e1e0294040cfadde0f119590f37fbff73654abc482ac60c1e3ca60b867326713";
};
"aarch64-darwin" = {
fileName = "go-mod-upgrade_${appReleaseVersion}_Darwin_arm64.tar.gz";
sha256 = "15027f435a85f31346fd0796977180c43c737b7fe7bbb4fc3bcc5f4b8f32804c";
};
};
supportedSystems = builtins.attrNames appReleaseBinaries;
in
utils.lib.eachSystem supportedSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
appReleaseBinary = appReleaseBinaries.${system};
in
rec {
packages.go-mod-upgrade = pkgs.stdenv.mkDerivation {
pname = "go-mod-upgrade";
version = appReleaseVersion;

src = pkgs.fetchurl {
url = "https://github.com/oligot/go-mod-upgrade/releases/download/v${appReleaseVersion}/${appReleaseBinary.fileName}";
sha256 = appReleaseBinary.sha256;
};

sourceRoot = ".";

installPhase = ''
install -m755 -D go-mod-upgrade $out/bin/go-mod-upgrade
'';
};
packages.default = packages.go-mod-upgrade;

apps.go-mod-upgrade = utils.lib.mkApp {
drv = packages.go-mod-upgrade;
};
apps.default = apps.go-mod-upgrade;
});
}
3 changes: 0 additions & 3 deletions make/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ include $(INCLUDE_DIR)shell.mk
include $(INCLUDE_DIR)help.mk
include $(INCLUDE_DIR)repo.mk
include $(INCLUDE_DIR)platform.mk
include $(INCLUDE_DIR)tools.mk
include $(INCLUDE_DIR)pre-commit.mk
include $(INCLUDE_DIR)go.mk
include $(INCLUDE_DIR)goreleaser.mk
include $(INCLUDE_DIR)docker.mk
include $(INCLUDE_DIR)ci.mk
include $(INCLUDE_DIR)tag.mk
include $(INCLUDE_DIR)upx.mk
50 changes: 0 additions & 50 deletions make/ci.mk

This file was deleted.

4 changes: 2 additions & 2 deletions make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ E2E_FLAKE_ATTEMPTS ?= 1
e2e-test: ## Runs e2e tests
$(info $(M) running e2e tests$(if $(E2E_LABEL), labelled "$(E2E_LABEL)")$(if $(E2E_FOCUS), matching "$(E2E_FOCUS)"))
ifndef E2E_SKIP_BUILD
$(MAKE) GORELEASER_FLAGS=$$'--config=<(env GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) gojq --yaml-input --yaml-output \'del(.builds[0].goarch) | del(.builds[0].goos) | .builds[0].targets|=(["linux_amd64","linux_arm64",env.GOOS+"_"+env.GOARCH] | unique | map(. | sub("_amd64";"_amd64_v1")))\' .goreleaser.yml) --clean --skip-validate --skip-publish' release
$(MAKE) GORELEASER_FLAGS=$$'--config=<(env GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) gojq --yaml-input --yaml-output \'del(.builds[0].goarch) | del(.builds[0].goos) | .builds[0].targets|=(["linux_amd64","linux_arm64",env.GOOS+"_"+env.GOARCH] | unique | map(. | sub("_amd64";"_amd64_v1")))\' .goreleaser.yml) --clean --skip=validate,publish' release
endif
ginkgo run \
--r \
Expand Down Expand Up @@ -164,5 +164,5 @@ go-generate: ; $(info $(M) running go generate)

.PHONY: go-mod-upgrade
go-mod-upgrade: ## Interactive check for direct module dependency upgrades
go-mod-upgrade: install-tool.go.go-mod-upgrade ; $(info $(M) checking for direct module dependency upgrades)
go-mod-upgrade: ; $(info $(M) checking for direct module dependency upgrades)
go-mod-upgrade
2 changes: 1 addition & 1 deletion make/goreleaser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ release-snapshot: dockerauth; $(info $(M) building snapshot release $*)
goreleaser --debug=$(GORELEASER_DEBUG) \
release \
--snapshot \
--skip-publish \
--skip=publish \
--clean \
--parallelism=$(GORELEASER_PARALLELISM) \
--timeout=60m
Loading

0 comments on commit b4dde60

Please sign in to comment.