From 52b28cdf25d84415d5f36b432d6cf86eab6f770b Mon Sep 17 00:00:00 2001 From: Franky W Date: Sat, 21 Aug 2021 11:45:11 +0200 Subject: [PATCH 1/6] GoReleaser as a release strategy Switches from using gox to using GoReleaser to release binaries --- .gitignore | 1 + .goreleaser.yml | 35 +++++++++++++++++++++++++++++++++++ Dockerfile.e2e | 9 --------- Makefile | 31 ++++++++++--------------------- cross.sh | 9 --------- 5 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 Dockerfile.e2e delete mode 100755 cross.sh diff --git a/.gitignore b/.gitignore index 275ea47..4b88713 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,4 @@ Temporary Items /*.yaml build_docker_cross +!/.goreleaser.yml diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..b5b83c0 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,35 @@ +before: + hooks: + - go mod tidy +builds: + - + binary: biscuit + goos: + - darwin + - linux + - windows + goarch: + - amd64 + - arm64 + - 386 + ldflags: + - -s -w + - -X main.Version={{.Version}} +archives: +- + name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}" + replacements: + darwin: MacOS + linux: Linux + windows: Windows + amd64: 64bit +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Dockerfile.e2e b/Dockerfile.e2e deleted file mode 100644 index 47b55b5..0000000 --- a/Dockerfile.e2e +++ /dev/null @@ -1,9 +0,0 @@ -FROM golang:1.16 -ADD Makefile src/github.com/dcoker/biscuit/ -RUN go install github.com/mitchellh/gox@v1.0.1 -WORKDIR /go/src/github.com/dcoker/biscuit -ADD go.mod . -ADD go.sum . -RUN go mod download -ADD . . -RUN make build diff --git a/Makefile b/Makefile index 8b9ee9b..0eca6a7 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,7 @@ GOFLAGS := -v PKG := ./... TESTS := ".*" GOIMPORTS := goimports -PROGNAME := biscuit -VERSION := $(shell git describe --long --tags --always) -GOVERSIONLDFLAG := -ldflags="-X main.Version=$(VERSION)" +VERSION ?= $(shell git describe --long --tags --always) .PHONY: build $(GO) install $(GOVERSIONLDFLAG) $(GOFLAGS) @@ -32,24 +30,15 @@ clean: rm -f $(GOPATH)/bin/$(PROGNAME) $(GO) clean $(GOFLAGS) -i $(PKG) -.PHONY: cross -cross: - gox $(GOVERSIONLDFLAG) \ - -output 'build/{{.Dir}}/{{.OS}}_{{.Arch}}/biscuit' \ - -os "linux darwin windows" \ - -arch "amd64 arm arm64 386" \ - -osarch '!darwin/arm !darwin/386 !darwin/arm64' - ./cross.sh - -.PHONY: docker-build -docker-build: - docker build -f Dockerfile.e2e -t $(PROGNAME)/local . - -.PHONY: docker-cross -docker-cross: docker-build - mkdir build_docker_cross || /bin/true - docker run -v $(shell pwd)/build_docker_cross/:/tmp/build/ $(PROGNAME)/local /bin/bash -xe -c \ - "rm -f build && ln -s /tmp/build/ build && make cross" +.PHONY: goreleaser-test +goreleaser-test: + git tag ${VERSION} + docker run --rm \ + -v $(shell pwd):/go/src/github.com/dcoker/biscuit \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -w /go/src/github.com/dcoker/biscuit \ + -e GITHUB_TOKEN=${GITHUB_TOKEN} \ + goreleaser/goreleaser release --rm-dist --snapshot .PHONY: localstack diff --git a/cross.sh b/cross.sh deleted file mode 100755 index dbc15be..0000000 --- a/cross.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e -for rls in build/biscuit/{linux,darwin}*; do \ - tar czf build/biscuit-$(echo ${rls} | cut -f3 -d/).tgz -C ${rls} biscuit; \ -done -for rls in build/biscuit/windows*; do \ - mv ${rls}/biscuit.exe build/biscuit-$(echo ${rls} | cut -f3 -d/).exe -done -ls -l build/ From 47e1428ecb03c5f2255db1ea8fc72eb96eee3255 Mon Sep 17 00:00:00 2001 From: Franky W Date: Sat, 21 Aug 2021 12:16:16 +0200 Subject: [PATCH 2/6] Use Github Workflows to release binaries Uses github workflows to release binaries when a tag is created. This means we can go into Github's UI and create a release. --- .github/workflows/release.yml | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..578682f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +on: + release: + types: + - published + +name: Release + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: 1.17 + + - name: Checkout code + uses: actions/checkout@v2 + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod tidy -v + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a701e3a320fdc9d6935fb59b2d8d3f6e7ea7581b Mon Sep 17 00:00:00 2001 From: Franky W Date: Sun, 22 Aug 2021 00:52:53 +0200 Subject: [PATCH 3/6] Cleanup .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4b88713..858949c 100644 --- a/.gitignore +++ b/.gitignore @@ -160,5 +160,4 @@ Temporary Items /*.yml /*.yaml -build_docker_cross !/.goreleaser.yml From 11ae8e01c38ab09fc41efacbee83124dab758a19 Mon Sep 17 00:00:00 2001 From: Franky W Date: Sat, 21 Aug 2021 12:28:26 +0200 Subject: [PATCH 4/6] Create Docker image Create & release docker image as part of the release process --- .github/workflows/release.yml | 9 +++++++++ .goreleaser.Dockerfile | 23 +++++++++++++++++++++++ .goreleaser.yml | 17 +++++++++++++++++ Makefile | 2 ++ 4 files changed, 51 insertions(+) create mode 100644 .goreleaser.Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 578682f..5bf1fe0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,15 @@ jobs: go mod download go mod tidy -v + - name: Login Github Container Registry + run: echo "${{ secrets.GORELEASER_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Set SOURCE Environment Variable + run: | + echo 'SOURCE<> $GITHUB_ENV + echo ${GITHUB_SERVER_URL}/${{ github.repository }} >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: diff --git a/.goreleaser.Dockerfile b/.goreleaser.Dockerfile new file mode 100644 index 0000000..97ac153 --- /dev/null +++ b/.goreleaser.Dockerfile @@ -0,0 +1,23 @@ +FROM alpine:3.13.6 + +ARG BUILD_VERSION +ARG REVISION +ARG BUILD_DATE +ARG SOURCE + +LABEL org.opencontainers.image.revision=$REVISION \ + org.opencontainers.image.source=$SOURCE \ + org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.created=$BUILD_DATE + +COPY biscuit /usr/local/bin/. + +RUN apk update && apk add --no-cache \ + ca-certificates \ + openssl + +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +USER appuser + +ENTRYPOINT ["biscuit"] diff --git a/.goreleaser.yml b/.goreleaser.yml index b5b83c0..7b1b04e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -33,3 +33,20 @@ changelog: exclude: - '^docs:' - '^test:' + +dockers: + - + goos: linux + goarch: amd64 + ids: + - biscuit + image_templates: + - "ghcr.io/dcoker/biscuit:latest" + - "ghcr.io/dcoker/biscuit:{{ .Tag }}" + dockerfile: .goreleaser.Dockerfile + build_flag_templates: + - "--pull" + - "--build-arg=REVISION={{.FullCommit}}" + - "--build-arg=SOURCE={{.Env.SOURCE}}" + - "--build-arg=BUILD_VERSION={{.Version}}" + - "--build-arg=BUILD_DATE={{.Date}}" diff --git a/Makefile b/Makefile index 0eca6a7..d970893 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ PKG := ./... TESTS := ".*" GOIMPORTS := goimports VERSION ?= $(shell git describe --long --tags --always) +SOURCE ?= $(shell pwd) .PHONY: build $(GO) install $(GOVERSIONLDFLAG) $(GOFLAGS) @@ -37,6 +38,7 @@ goreleaser-test: -v $(shell pwd):/go/src/github.com/dcoker/biscuit \ -v /var/run/docker.sock:/var/run/docker.sock \ -w /go/src/github.com/dcoker/biscuit \ + -e SOURCE=${SOURCE} \ -e GITHUB_TOKEN=${GITHUB_TOKEN} \ goreleaser/goreleaser release --rm-dist --snapshot From ff809c2cdc825cf2ac167b7486259ec9ab7b73d2 Mon Sep 17 00:00:00 2001 From: Franky W Date: Sun, 10 Oct 2021 14:25:49 +0200 Subject: [PATCH 5/6] Revert "Create Docker image" This reverts commit 859c98e411cb57d62caf1f282ce90d2851649b3b. --- .github/workflows/release.yml | 9 --------- .goreleaser.Dockerfile | 23 ----------------------- .goreleaser.yml | 17 ----------------- Makefile | 2 -- 4 files changed, 51 deletions(-) delete mode 100644 .goreleaser.Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bf1fe0..578682f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,15 +29,6 @@ jobs: go mod download go mod tidy -v - - name: Login Github Container Registry - run: echo "${{ secrets.GORELEASER_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set SOURCE Environment Variable - run: | - echo 'SOURCE<> $GITHUB_ENV - echo ${GITHUB_SERVER_URL}/${{ github.repository }} >> $GITHUB_ENV - echo 'EOF' >> $GITHUB_ENV - - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: diff --git a/.goreleaser.Dockerfile b/.goreleaser.Dockerfile deleted file mode 100644 index 97ac153..0000000 --- a/.goreleaser.Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM alpine:3.13.6 - -ARG BUILD_VERSION -ARG REVISION -ARG BUILD_DATE -ARG SOURCE - -LABEL org.opencontainers.image.revision=$REVISION \ - org.opencontainers.image.source=$SOURCE \ - org.opencontainers.image.version=$BUILD_VERSION \ - org.opencontainers.image.created=$BUILD_DATE - -COPY biscuit /usr/local/bin/. - -RUN apk update && apk add --no-cache \ - ca-certificates \ - openssl - -RUN addgroup -S appgroup && adduser -S appuser -G appgroup - -USER appuser - -ENTRYPOINT ["biscuit"] diff --git a/.goreleaser.yml b/.goreleaser.yml index 7b1b04e..b5b83c0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -33,20 +33,3 @@ changelog: exclude: - '^docs:' - '^test:' - -dockers: - - - goos: linux - goarch: amd64 - ids: - - biscuit - image_templates: - - "ghcr.io/dcoker/biscuit:latest" - - "ghcr.io/dcoker/biscuit:{{ .Tag }}" - dockerfile: .goreleaser.Dockerfile - build_flag_templates: - - "--pull" - - "--build-arg=REVISION={{.FullCommit}}" - - "--build-arg=SOURCE={{.Env.SOURCE}}" - - "--build-arg=BUILD_VERSION={{.Version}}" - - "--build-arg=BUILD_DATE={{.Date}}" diff --git a/Makefile b/Makefile index d970893..0eca6a7 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ PKG := ./... TESTS := ".*" GOIMPORTS := goimports VERSION ?= $(shell git describe --long --tags --always) -SOURCE ?= $(shell pwd) .PHONY: build $(GO) install $(GOVERSIONLDFLAG) $(GOFLAGS) @@ -38,7 +37,6 @@ goreleaser-test: -v $(shell pwd):/go/src/github.com/dcoker/biscuit \ -v /var/run/docker.sock:/var/run/docker.sock \ -w /go/src/github.com/dcoker/biscuit \ - -e SOURCE=${SOURCE} \ -e GITHUB_TOKEN=${GITHUB_TOKEN} \ goreleaser/goreleaser release --rm-dist --snapshot From 8a1c22f0323f79b3b3c029ef66f942415df749ef Mon Sep 17 00:00:00 2001 From: Franky W Date: Tue, 19 Oct 2021 11:11:18 +0200 Subject: [PATCH 6/6] Publish MacOS Universal Binaries See https://goreleaser.com/customization/universalbinaries/ --- .goreleaser.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index b5b83c0..8344a0d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,6 +15,8 @@ builds: ldflags: - -s -w - -X main.Version={{.Version}} +universal_binaries: + - replace: false archives: - name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"