Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gythialy/golang-cross
golang cross compiler with CGO
https://github.com/gythialy/golang-cross
cgo cross-compilation docker golang golang-cross goreleaser
Last synced: 4 days ago
JSON representation
golang cross compiler with CGO
- Host: GitHub
- URL: https://github.com/gythialy/golang-cross
- Owner: gythialy
- License: mit
- Created: 2019-08-22T02:13:33.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T13:32:53.000Z (11 days ago)
- Last Synced: 2024-10-29T16:07:27.340Z (10 days ago)
- Topics: cgo, cross-compilation, docker, golang, golang-cross, goreleaser
- Language: Shell
- Homepage: https://gythialy.github.io/goreleaser-cgo-cross-compile/
- Size: 699 KB
- Stars: 129
- Watchers: 4
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - gythialy/golang-cross - golang cross compiler with CGO (Shell)
README
# golang-cross [![Actions Status](https://github.com/gythialy/golang-cross/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/gythialy/golang-cross/actions)
Docker container to do cross compilation (Linux, windows, macOS, ARM, ARM64) of go packages including support for cgo.
## Docker images
### Pre-built Images
- golang-cross
```
docker pull ghcr.io/gythialy/golang-cross:latest
```
- golang-cross-builder
```
docker pull ghcr.io/gythialy/golang-cross-builder:v1.22.0-0-bullseye
docker pull ghcr.io/gythialy/golang-cross-builder:v1.17.1
```### Build your own
- Build base image (optional)
```
docker build -f Dockerfile_builder -t ghcr.io/gythialy/golang-cross-builder:v1.17.1 .
# if running docker on M1 (arm64) macOS:
docker build --platform linux/amd64 -f Dockerfile.builder -t ghcr.io/gythialy/golang-cross-builder:v1.18 .
```
> Note: [Pack the SDK](https://github.com/tpoechtrager/osxcross#packaging-the-sdk) first or use [GitHub Action](https://github.com/gythialy/golang-cross/actions/workflows/osx-sdk.yaml)- Build golang-cross image
```
docker build --build-arg GO_VERSION=1.22.0 \
--build-arg OS_CODENAME=bullseye \
--build-arg GOLANG_DIST_SHA=542e936b19542e62679766194364f45141fde55169db2d8d01046555ca9eb4b8 \
--build-arg GORELEASER_VERSION=1.24.0 \
--build-arg GORELEASER_SHA=4b7d2f1e59ead8047fcef795d66236ff6f8cfe7302c1ff8fb31bd360a3c6f32e \
-f Dockerfile \
-t ghcr.io/gythialy/golang-cross:latest .
```
> Override default arguments with `--build-arg`## Usage
- Prepare [GoReleaser](https://goreleaser.com/intro/) configuration
- Set up GPG signing (optional), if enable the [signing](https://goreleaser.com/customization/sign/) feature
```bash
export PRIVATE_KEY=$(cat ~/private_key.gpg | base64)
```- Build the binaries:
```bash
export GO_BUILDER_VERSION=v1.17.1;
docker run --rm --privileged \
-e PRIVATE_KEY=$(PRIVATE_KEY) \
-v $(CURDIR):/golang-cross-example \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(GOPATH)/src:/go/src \
-w /golang-cross-example \
ghcr.io/gythialy/golang-cross:$(GO_BUILDER_VERSION) --snapshot --rm-dist
```## Examples
- [.goreleaser.yml](example/.goreleaser.yml)
- [Makefile](example/Makefile#L35-L42)## Alternative projects
- [goreleaser/goreleaser-cross](https://github.com/goreleaser/goreleaser-cross)