Skip to content

Commit

Permalink
feat: add CGO, trim variant, buildx parallel...
Browse files Browse the repository at this point in the history
- Remove goreleaser json files
- Restructured goreleaser flags
  • Loading branch information
pratikbin committed Dec 25, 2021
1 parent c2522d0 commit 86ddb86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
config-inline: |
[worker.oci]
max-parallelism = 4
- name: Build and push
uses: docker/bake-action@master
Expand All @@ -32,7 +36,9 @@ jobs:
*.cache-to=type=gha,mode=max
- name: Move artifacts
shell: bash
run: |
find ./dist -name *.json* -type f -exec rm -f {} \;
mv -f ./dist/**/* ./dist/
- name: Release
Expand Down
31 changes: 17 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG GO_VERSION=1.17

FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:edge AS goreleaser-xx
FROM --platform=$BUILDPLATFORM pratikimprowise/upx AS upx
FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:1.2.2 AS goreleaser-xx
FROM --platform=$BUILDPLATFORM pratikimprowise/upx:3.96 AS upx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=goreleaser-xx / /
COPY --from=upx / /
Expand All @@ -19,12 +19,13 @@ RUN --mount=type=bind,source=.,target=/src,rw \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
goreleaser-xx --debug \
--name "tarrer" \
--dist "/out" \
--envs="CGO_ENABLED=0" \
--name="tarrer" \
--main="." \
--dist="/out" \
--artifacts="bin" \
--artifacts="archive" \
--snapshot="no" \
--main="."
--snapshot="no"

FROM vendored AS trim
ARG TARGETPLATFORM
Expand All @@ -34,14 +35,15 @@ RUN --mount=type=bind,source=.,target=/src,rw \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
goreleaser-xx --debug \
--envs="CGO_ENABLED=0" \
--name="tarrer-trim" \
--ldflags="-s -w" \
--flags="-trimpath" \
--main="." \
--dist="/out" \
--snapshot="no" \
--artifacts="bin" \
--artifacts="archive" \
--ldflags="-s -w" \
--flags="-trimpath" \
--name="tarrer-trim"
--snapshot="no"

FROM vendored AS slim
ARG TARGETPLATFORM
Expand All @@ -51,14 +53,15 @@ RUN --mount=type=bind,source=.,target=/src,rw \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
goreleaser-xx --debug \
--envs="CGO_ENABLED=0" \
--name="tarrer-slim" \
--ldflags="-s -w" \
--flags="-trimpath" \
--main="." \
--dist="/out" \
--snapshot="no" \
--artifacts="bin" \
--artifacts="archive" \
--ldflags="-s -w" \
--flags="-trimpath" \
--name="tarrer-slim" \
--snapshot="no" \
--post-hooks="sh -cx 'upx --ultra-brute --best /usr/local/bin/tarrer-slim || true'"

FROM scratch AS artifact
Expand Down

0 comments on commit 86ddb86

Please sign in to comment.