Skip to content

Commit

Permalink
fix(Dockerfile): extract binaries from tarball when using GoReleaser …
Browse files Browse the repository at this point in the history
…artifacts

According to GoReleaser docs, the directory names inside dist have no
guarantee of remaining the same across different GoReleaser
versions[^1]. Therefore, we extract from tarballs instead of using those
directories directly.

[^1]: https://goreleaser.com/customization/builds/#a-note-about-directory-names-inside-dist

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei committed Dec 8, 2024
1 parent e399e52 commit b88b74c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dockers:
build_flag_templates:
- --platform=linux/386
- --build-arg=USE_GORELEASER_ARTIFACTS=1
- --build-arg=GORELEASER_ARTIFACTS_TARBALL=.dist/{{.ProjectName}}{{.Version}}.linux-386.tar.gz
extra_files:
- ./
- goarch: amd64
Expand All @@ -60,6 +61,7 @@ dockers:
build_flag_templates:
- --platform=linux/amd64
- --build-arg=USE_GORELEASER_ARTIFACTS=1
- --build-arg=GORELEASER_ARTIFACTS_TARBALL=.dist/{{.ProjectName}}{{.Version}}.linux-amd64.tar.gz
extra_files:
- ./
- goarch: arm64
Expand All @@ -69,6 +71,7 @@ dockers:
build_flag_templates:
- --platform=linux/arm64
- --build-arg=USE_GORELEASER_ARTIFACTS=1
- --build-arg=GORELEASER_ARTIFACTS_TARBALL=.dist/{{.ProjectName}}{{.Version}}.linux-arm64.tar.gz
extra_files:
- ./

Expand Down
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ ARG BASE_IMAGE=golang:1.22-bookworm

FROM $BASE_IMAGE AS build
ARG USE_GORELEASER_ARTIFACTS=0
ARG GORELEASER_ARTIFACTS_TARBALL
WORKDIR /usr/local/src/gop
COPY . .
ENV GOPROOT=/usr/local/gop
RUN set -eux; \
mkdir -p $GOPROOT/bin; \
mkdir $GOPROOT; \
git ls-tree --full-tree --name-only -r HEAD | grep -vE "^\." | xargs -I {} cp --parents {} $GOPROOT/; \
if [ $USE_GORELEASER_ARTIFACTS -eq 1 ]; then \
GOARCH=$(go env GOARCH); \
BIN_DIR_SUFFIX=linux_$GOARCH; \
[ $GOARCH = "amd64" ] && BIN_DIR_SUFFIX=${BIN_DIR_SUFFIX}_v1; \
[ $GOARCH = "arm" ] && BIN_DIR_SUFFIX=${BIN_DIR_SUFFIX}_$(go env GOARM | cut -d , -f 1); \
cp .dist/gop_$BIN_DIR_SUFFIX/bin/gop $GOPROOT/bin/; \
tar -xzf "${GORELEASER_ARTIFACTS_TARBALL}" -C $GOPROOT bin; \
else \
./all.bash; \
cp bin/gop $GOPROOT/bin/; \
mv bin $GOPROOT/; \
fi

FROM $BASE_IMAGE
Expand Down

0 comments on commit b88b74c

Please sign in to comment.