Skip to content

Commit

Permalink
build static Golang binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
erkexzcx committed Oct 11, 2023
1 parent ca1ab86 commit d7d39f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ jobs:
export GOOS=$(echo ${{ matrix.platform }} | awk -F/ '{print $1}')
export GOARCH=$(echo ${{ matrix.platform }} | awk -F/ '{print $2}')
export GOARM=$(echo ${{ matrix.platform }} | awk -F/ '{print $3}' | sed 's/v//')
export CGO_ENABLED=0
reponame="${{ github.event.repository.name }}"
version="${{ github.event.release.tag_name }}"
fullarch="${GOARCH}$(echo ${{ matrix.platform }} | awk -F/ '{print $3}')"
filename="${reponame}_${version}_${GOOS}_${fullarch}"
go build -ldflags "-s -w -X main.version=$version" -o "$filename" cmd/$reponame/main.go
go build -ldflags '-s -w -X main.version=$version -extldflags "-static"' -o "$filename" cmd/$reponame/main.go
echo "FILENAME=$filename" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG version
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} go build -a -ldflags "-w -s -X main.version=$version" -o valetudopng ./cmd/valetudopng/main.go
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} go build -a -ldflags '-w -s -X main.version=$version -extldflags "-static"' -o valetudopng ./cmd/valetudopng/main.go

FROM scratch
COPY --from=builder /etc/ssl/cert.pem /etc/ssl/
Expand Down

0 comments on commit d7d39f0

Please sign in to comment.