From e8e6f534665cdfcb39021b48607ca781f0cd396b Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 10 Mar 2025 14:22:13 +0100 Subject: [PATCH 1/5] Fix Makefile to work with techknowlogic/xgo --- .gitignore | 1 + Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a6d041f..e294776 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.iml .idea/ +/release diff --git a/Makefile b/Makefile index 07cff82..47ce02f 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ help: ## Get help .PHONY: release release: ## Build the release files - xgo --dest release --targets=$(targets) --ldflags=$(ldflags) $(pkg) + mkdir -p release/github.com/elwinar + xgo --dest release --targets=$(targets) --ldflags=$(ldflags) . docker-compose run -w /src main sh -c 'apk add build-base && go build -o release/rambler-alpine-amd64 --ldflags=${ldflags}' .PHONY: test From 124efcca991ecff9ea43ebb95345985a3c15eda8 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 10 Mar 2025 14:23:08 +0100 Subject: [PATCH 2/5] Add linux/arm64 build target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 47ce02f..636c779 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -targets="windows/amd64,windows/386,darwin/arm64,darwin/amd64,darwin/386,linux/amd64,linux/386" +targets="windows/amd64,windows/386,darwin/arm64,darwin/amd64,darwin/386,linux/amd64,linux/arm64,linux/386" pkg="github.com/elwinar/rambler" version=$(shell git describe --tags) ldflags="-X main.VERSION=${version}" From 456044de0805bf326e087bb425dab7ab26a62666 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 10 Mar 2025 14:51:47 +0100 Subject: [PATCH 3/5] Bump required go version to 1.21 for "slices" lib --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index da16592..2c4c13e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/elwinar/rambler -go 1.18 +go 1.21 require ( dario.cat/mergo v1.0.1 From 5c25f4b4ab67f01ec8884538b7adfa3d676aeba0 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 10 Mar 2025 16:51:36 +0100 Subject: [PATCH 4/5] Improve alpine support and build for arm64 as well as amd64 --- .dockerignore | 1 + Makefile | 4 +++- build.Dockerfile | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 build.Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f062d6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/release diff --git a/Makefile b/Makefile index 636c779..a4cab81 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,9 @@ help: ## Get help release: ## Build the release files mkdir -p release/github.com/elwinar xgo --dest release --targets=$(targets) --ldflags=$(ldflags) . - docker-compose run -w /src main sh -c 'apk add build-base && go build -o release/rambler-alpine-amd64 --ldflags=${ldflags}' + docker buildx build --output type=tar --build-arg VERSION=${version} --platform linux/amd64 --file build.Dockerfile . | tar -xO rambler >release/github.com/elwinar/rambler-alpine-amd64 + docker buildx build --output type=tar --build-arg VERSION=${version} --platform linux/arm64 --file build.Dockerfile . | tar -xO rambler >release/github.com/elwinar/rambler-alpine-arm64 + chmod +x release/github.com/elwinar/rambler-alpine-amd64 release/github.com/elwinar/rambler-alpine-arm64 .PHONY: test test: ## Test the project diff --git a/build.Dockerfile b/build.Dockerfile new file mode 100644 index 0000000..6ab2ac3 --- /dev/null +++ b/build.Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.21 +ARG TARGETARCH +ARG VERSION +COPY . /go/src/github.com/elwinar/rambler +WORKDIR /go/src/github.com/elwinar/rambler +RUN go get ./... +RUN go build -ldflags="-X main.VERSION=${VERSION} -s -linkmode external -extldflags -static -w" + +FROM scratch +COPY --from=0 /go/src/github.com/elwinar/rambler/rambler / From 947cb7826dac190cdb187f76bba706fa6588c54a Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 10 Mar 2025 14:22:58 +0100 Subject: [PATCH 5/5] Add github testing & release worflow --- .github/workflows/release.yaml | 36 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 18 +++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..e85615f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + tags: ['v*'] + +jobs: + test: + uses: ./.github/workflows/test.yaml + secrets: inherit + release: + needs: [test] + runs-on: ubuntu-latest + name: Compile & archive release binaries + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Cache xgo-cache + uses: actions/cache@v4 + with: + path: /home/runner/.xgo-cache + key: xgo-cache + - name: Install techknowlogick/xgo + run: go install src.techknowlogick.com/xgo@v1.8.0+1.23.2 + - uses: docker/setup-buildx-action@v3 + - name: Build rambler + run: PATH=/home/runner/.go/bin:$PATH make release + - name: Archive releases + uses: actions/upload-artifact@v4 + with: + name: release + path: release/github.com/elwinar + retention-days: 90 + if-no-files-found: error diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..93f8457 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,18 @@ +name: Test + +on: + push: + branches: ['*'] + tags: ['!v*'] + workflow_call: {} + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Test + run: go test ./...