From 7b4978f4bc16ce634a49cc809fb80e32b09344cc Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Wed, 5 Apr 2023 16:37:39 +0200 Subject: [PATCH] Revert "build static by default" --- .github/workflows/go-tests.yml | 6 +++ .github/workflows/release_publish-package.yml | 44 +++++++++++++++++++ Makefile | 8 ++-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 8c3a7c61c..bee5ff085 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -141,6 +141,12 @@ jobs: make build make go-acc | richgo testfilter + - name: Build and run tests (static) + run: | + make clean build BUILD_STATIC=yes + make test \ + | richgo testfilter + - name: Upload unit coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/.github/workflows/release_publish-package.yml b/.github/workflows/release_publish-package.yml index 7a46b9523..8ef6fa552 100644 --- a/.github/workflows/release_publish-package.yml +++ b/.github/workflows/release_publish-package.yml @@ -48,3 +48,47 @@ jobs: args: crowdsec-release.tgz application/x-gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + build_static: + strategy: + matrix: + go-version: ["1.20.1"] + + name: Build and upload binary package + runs-on: ubuntu-latest + steps: + - name: "Set up Go ${{ matrix.go-version }}" + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: false + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Build the binaries + run: | + make release BUILD_STATIC=yes + mv crowdsec-release.tgz crowdsec-release-static.tgz + + - name: Upload to release + uses: JasonEtco/upload-to-release@master + with: + args: crowdsec-release-static.tgz application/x-gzip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 05eb0586b..8f266bfff 100644 --- a/Makefile +++ b/Makefile @@ -39,11 +39,12 @@ LD_OPTS_VARS += -X '$(GO_MODULE_NAME)/pkg/cwversion.System=docker' endif ifdef BUILD_STATIC -$(warning WARNING: The BUILD_STATIC variable is deprecated and has no effect. Builds are static by default since v1.5.0.) + export LD_OPTS=-ldflags "-s -w $(LD_OPTS_VARS) -extldflags '-static'" -tags netgo,osusergo,sqlite_omit_load_extension +else + export LD_OPTS=-ldflags "-s -w $(LD_OPTS_VARS)" endif -export LD_OPTS=-ldflags "-s -w -extldflags '-static' $(LD_OPTS_VARS)" \ - -trimpath -tags netgo,osusergo,sqlite_omit_load_extension +LD_OPTS += -trimpath ifneq (,$(TEST_COVERAGE)) LD_OPTS += -cover @@ -71,6 +72,7 @@ clean: testclean @$(RM) $(CSCLI_BIN) $(WIN_IGNORE_ERR) @$(RM) *.log $(WIN_IGNORE_ERR) @$(RM) crowdsec-release.tgz $(WIN_IGNORE_ERR) + @$(RM) crowdsec-release-static.tgz $(WIN_IGNORE_ERR) @$(RM) $(HTTP_PLUGIN_FOLDER)/$(HTTP_PLUGIN_BIN) $(WIN_IGNORE_ERR) @$(RM) $(SLACK_PLUGIN_FOLDER)/$(SLACK_PLUGIN_BIN) $(WIN_IGNORE_ERR) @$(RM) $(SPLUNK_PLUGIN_FOLDER)/$(SPLUNK_PLUGIN_BIN) $(WIN_IGNORE_ERR)