Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CGO-related Docker build issues #19

Merged
merged 7 commits into from
Feb 19, 2025
Merged

fix CGO-related Docker build issues #19

merged 7 commits into from
Feb 19, 2025

Conversation

peterldowns
Copy link
Owner

@peterldowns peterldowns commented Feb 19, 2025

I'm seeing cgo-related errors on the main branch:

https://github.com/peterldowns/pgmigrate/actions/runs/13402236158/job/37435471414

#41 [linux/arm64 builder 13/13] RUN go build   -ldflags "-X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Version=v0.2.0 -X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Commit=639e8e5"   -o /dist/pgmigrate   ./cmd/pgmigrate
#41 35.55 # runtime/cgo
#41 35.55 gcc: error: unrecognized command-line option '-fno-caret-diagnostics'
#41 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c go build   -ldflags \"-X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Version=${PGM_VERSION} -X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Commit=${PGM_COMMIT_SHA}\"   -o /dist/pgmigrate   ./cmd/pgmigrate" did not complete successfully: exit code: 1
------
 > [linux/arm64 builder 13/13] RUN go build   -ldflags "-X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Version=v0.2.0 -X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Commit=639e8e5"   -o /dist/pgmigrate   ./cmd/pgmigrate:
35.55 # runtime/cgo
35.55 gcc: error: unrecognized command-line option '-fno-caret-diagnostics'
------

This is absolutely terrible. I have no idea why gcc is failing. But, here's how I'm trying to fix it:

  • Update the development shell and the nix build to use go1.24
    • also update golangci-lint in CI to match the version used in development
    • we have to update it in CI for it to be able to work with code built with go1.24, anyway
  • Update CI to use go1.24, both for the golang workflows and the docker workflows
  • Update the Dockerfile to use go1.24 and alpine 3.21
  • Update the Dockerfile to set CGO_ENABLED=0
    • I don't know why it was set to CGO_ENABLED=1
    • The local development shell sets CGO_ENABLED=0 and pgmigrate still seems to work fine
    • The release binaries are built with CGO_ENABLED=0, and those are what people are brew installing, and everything seems to work fine.

I tested this change by running just docker-build and then running docker run --rm -it local-pgmigrate:latest pgmigrate version and it seemed to work correctly, so hopefully everything is cool.

@peterldowns peterldowns merged commit c0c7001 into main Feb 19, 2025
4 checks passed
@peterldowns peterldowns deleted the docker-fixes branch February 19, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant