From 33e584b447c28a8a6d74fd5ab8b16c29ac2d7ee5 Mon Sep 17 00:00:00 2001 From: gzzchh Date: Sun, 8 Nov 2020 14:42:55 +0800 Subject: [PATCH] Turn off the CGO to make it static linked --- .github/workflows/build-test.yml | 1 + .github/workflows/release.yml | 6 +++--- Dockerfile | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d5c726f..e99d8bf 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -32,6 +32,7 @@ jobs: env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 run: | go build -v -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=dev-${GIT_COMMIT:0:7}" -o build/wings_${{ matrix.goos }}_${{ matrix.goarch }} wings.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 15dad1c..dc98a75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,9 +20,9 @@ jobs: env: REF: ${{ github.ref }} run: | - GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_amd64 -v wings.go - GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_arm64 -v wings.go - GOOS=linux GOARCH=arm go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_arm -v wings.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_amd64 -v wings.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_arm64 -v wings.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_arm -v wings.go - name: Test run: go test ./... diff --git a/Dockerfile b/Dockerfile index bb7931d..a386a24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ FROM golang:1.15-alpine COPY . /go/wings/ WORKDIR /go/wings/ RUN apk add --no-cache upx \ - && go build -ldflags="-s -w" \ - && upx --brute wings + && CGO_ENABLED=0 go build -ldflags="-s -w" \ + && upx --brute wings FROM alpine:latest COPY --from=0 /go/wings/wings /usr/bin/