diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f062d6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/release 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 ./... 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..a4cab81 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}" @@ -16,8 +16,11 @@ help: ## Get help .PHONY: release release: ## Build the release files - xgo --dest release --targets=$(targets) --ldflags=$(ldflags) $(pkg) - docker-compose run -w /src main sh -c 'apk add build-base && go build -o release/rambler-alpine-amd64 --ldflags=${ldflags}' + mkdir -p release/github.com/elwinar + xgo --dest release --targets=$(targets) --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 / 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