From f2bc4fe0810071d365417dd2e3ce1b4d64b82c47 Mon Sep 17 00:00:00 2001 From: Alex Bice Date: Mon, 13 Nov 2023 09:41:23 -0700 Subject: [PATCH] use go base image --- .github/workflows/build_and_test.yml | 3 --- .goreleaser.yml | 1 + .ko.yaml | 19 +++++++++++++++++++ Makefile | 14 ++++++-------- README.md | 8 ++++++++ 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 .ko.yaml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 874c6fb..8c8f891 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -13,9 +13,6 @@ jobs: fail-fast: false matrix: go: - # Drop support of go 1.17 - - "1.18" - - "1.19" - "1.20" - "1.21" name: run tests with go version ${{ matrix.go }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 9f7dd48..52ec91c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -21,6 +21,7 @@ archives: kos: - repository: abice/go-enum + base_image: cgr.dev/chainguard/go # need the go binary for formatting 🔧 purposes 🫤 tags: - "{{.Version}}" - latest diff --git a/.ko.yaml b/.ko.yaml new file mode 100644 index 0000000..ffab3c8 --- /dev/null +++ b/.ko.yaml @@ -0,0 +1,19 @@ +defaultBaseImage: cgr.dev/chainguard/go # For now, we need the go binary in order to format go files. +defaultPlatforms: + - linux/arm64 + - linux/amd64 + +builds: + - id: go-enum + dir: . # default is . + main: . + flags: + - -tags + - netgo + ldflags: + - -s -w + - -extldflags "-static" + - -X "main.version={{.Env.VERSION}}" + - -X "main.commit={{.Env.COMMIT}}" + - -X "main.date={{.Env.DATE}}" + - -X "main.builtBy={{.Env.BUILT_BY}}" diff --git a/Makefile b/Makefile index 5074ad5..bffaf9a 100644 --- a/Makefile +++ b/Makefile @@ -99,28 +99,26 @@ bin/goveralls: go.sum $(call goinstall,github.com/mattn/goveralls) # snapshots: snapshots_1.17 -snapshots: snapshots_1.20 +snapshots: snapshots_1.21 snapshots_%: clean echo "##### updating snapshots for golang $* #####" docker run -i -t -w /app -v $(shell pwd):/app --entrypoint /bin/sh golang:$* -c './update-snapshots.sh || true' .PHONY: ci -# ci: docker_1.16 -# ci: docker_1.17 -ci: docker_1.18 -ci: docker_1.19 ci: docker_1.20 +ci: docker_1.21 docker_%: echo "##### testing golang $* #####" docker run -i -t -w /app -v $(shell pwd):/app --entrypoint /bin/sh golang:$* -c 'make clean && make' .PHONY: pullimages -pullimages: pullimage_1.17 -pullimages: pullimage_1.18 -pullimages: pullimage_1.19 pullimages: pullimage_1.20 +pullimages: pullimage_1.21 pullimage_%: docker pull golang:$* + +build_docker: + KO_DOCKER_REPO=abice/go-enum VERSION=$(GITHUB_REF) COMMIT=$(GITHUB_SHA) DATE=$(DATE) BUILT_BY=$(USER) ko build --bare --local diff --git a/README.md b/README.md index a736c57..f8f926d 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,14 @@ It's not perfect, but I think it's useful. I took the output of the [Stringer](https://godoc.org/golang.org/x/tools/cmd/stringer) command as the `String()` method, and added a way to parse a string value. +## Docker image + +You can now use a docker image directly for running the command if you do not wish to install anything! + +```shell + docker run -w /app -v $(pwd):/app abice/go-enum:$(GO_ENUM_VERSION) +``` + ## Installation You can now download a release directly from github and use that for generating your enums! (Thanks to [GoReleaser](https://github.com/goreleaser/goreleaser-action))