From 523267e55bc4d7cab113fc06772a1b29e80a34e8 Mon Sep 17 00:00:00 2001 From: Stavros Date: Wed, 11 Jun 2025 10:11:23 +0300 Subject: [PATCH] fix: disable CGO in binary builds --- .github/workflows/nightly.yml | 4 ++++ .github/workflows/release.yml | 4 ++++ Dockerfile | 2 +- air.toml | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 2df55a4..31fa8ad 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -79,6 +79,8 @@ jobs: run: | cp -r frontend/dist internal/assets/dist go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${{ needs.generate-metadata.outputs.VERSION }} -X tinyauth/internal/constants.CommitHash=${{ needs.generate-metadata.outputs.COMMIT_HASH }} -X tinyauth/internal/constants.BuildTimestamp=${{ needs.generate-metadata.outputs.BUILD_TIMESTAMP }}" -o tinyauth-amd64 + env: + CGO_ENABLED: 0 - name: Upload artifact uses: actions/upload-artifact@v4 @@ -123,6 +125,8 @@ jobs: run: | cp -r frontend/dist internal/assets/dist go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${{ needs.generate-metadata.outputs.VERSION }} -X tinyauth/internal/constants.CommitHash=${{ needs.generate-metadata.outputs.COMMIT_HASH }} -X tinyauth/internal/constants.BuildTimestamp=${{ needs.generate-metadata.outputs.BUILD_TIMESTAMP }}" -o tinyauth-arm64 + env: + CGO_ENABLED: 0 - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59a2238..6f6ae9b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,6 +59,8 @@ jobs: run: | cp -r frontend/dist internal/assets/dist go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${{ needs.generate-metadata.outputs.VERSION }} -X tinyauth/internal/constants.CommitHash=${{ needs.generate-metadata.outputs.COMMIT_HASH }} -X tinyauth/internal/constants.BuildTimestamp=${{ needs.generate-metadata.outputs.BUILD_TIMESTAMP }}" -o tinyauth-amd64 + env: + CGO_ENABLED: 0 - name: Upload artifact uses: actions/upload-artifact@v4 @@ -100,6 +102,8 @@ jobs: run: | cp -r frontend/dist internal/assets/dist go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${{ needs.generate-metadata.outputs.VERSION }} -X tinyauth/internal/constants.CommitHash=${{ needs.generate-metadata.outputs.COMMIT_HASH }} -X tinyauth/internal/constants.BuildTimestamp=${{ needs.generate-metadata.outputs.BUILD_TIMESTAMP }}" -o tinyauth-arm64 + env: + CGO_ENABLED: 0 - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/Dockerfile b/Dockerfile index d90db32..bef09ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ COPY ./cmd ./cmd COPY ./internal ./internal COPY --from=frontend-builder /frontend/dist ./internal/assets/dist -RUN go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${VERSION} -X tinyauth/internal/constants.CommitHash=${COMMIT_HASH} -X tinyauth/internal/constants.BuildTimestamp=${BUILD_TIMESTAMP}" +RUN CGO_ENABLED=0 go build -ldflags "-s -w -X tinyauth/internal/constants.Version=${VERSION} -X tinyauth/internal/constants.CommitHash=${COMMIT_HASH} -X tinyauth/internal/constants.BuildTimestamp=${BUILD_TIMESTAMP}" # Runner FROM alpine:3.22 AS runner diff --git a/air.toml b/air.toml index 58e2132..d9c0f27 100644 --- a/air.toml +++ b/air.toml @@ -3,7 +3,7 @@ tmp_dir = "tmp" [build] pre_cmd = ["mkdir -p internal/assets/dist", "echo 'backend running' > internal/assets/dist/index.html"] -cmd = "go build -o ./tmp/tinyauth ." +cmd = "CGO_ENABLED=0 go build -o ./tmp/tinyauth ." bin = "tmp/tinyauth" include_ext = ["go"] exclude_dir = ["internal/assets/dist"]