ph / golang-crossbuild

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

golang-crossbuild

golang-crossbuild is a set of Docker images containing the requisite cross-compilers for cross compiling Go applications. The cross-compilers are needed when the application uses cgo.

The base image used is Debian 9 (stretch) unless otherwise specified.

Docker Repo

docker.elastic.co/beats-dev/golang-crossbuild:[TAG]

Build Tags

  • 1.10.5-main, 1.11.2-main - linux/{amd64,386} and windows/{amd64,386}
  • 1.10.5-arm, 1.11.2-arm - linux/{armv5,armv6,armv7,arm64}
  • 1.10.5-darwin, 1.11.2-darwin - darwin/{amd64,386}
  • 1.10.5-ppc, 1.11.2-ppc - linux/{ppc64,ppc64le}
  • 1.10.5-mips, 1.11.2-mips - linux/{mips,mipsle,mips64,mips64le}
  • 1.10.5-s390x, 1.11.2-s390x - linux/s390x
  • 1.10.5-main-debian7, 1.11.2-main-debian7 - linux/{amd64,386} and windows/{amd64,386} (Debian 7 uses glibc 2.13 so the resulting binaries (if dynamically linked) have greater compatibility.)
  • 1.10.5-main-debian8, 1.11.2-main-debian8 - linux/{amd64,386} and windows/{amd64,386} (Debian 8 uses glibc 2.19)

Usage Example

docker run -it --rm \
  -v $GOPATH/src/github.com/user/go-project:/go/src/github.com/user/go-project \
  -w /go/src/github.com/user/go-project \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.10.5-arm \
  --build-cmd "make build" \
  -p "linux/armv7"

This will execute your projects make build target. While executing the build command the following variables with be added to the environment: GOOS, GOARCH, GOARM, PLATFORM_ID, CC, and CXX.

Releasing images for a new Go version

  1. Update the Docker tag in Makefile.common and/or Makefile.common.
  2. Update the Go version and SHA256 in the Dockerfile. The SHA256 must be obtained from https://golang.org/dl/.
  3. Commit the changes. git add -u && git commit -m 'Update to Go 1.x.y'.
  4. Build the images from the project's root with make.
  5. Get a logon token for the container registry by visiting https://docker.elastic.co:7000. In the provided login command change docker.elastic.co to push.docker.elastic.co.
  6. Publish the images with make push.

About


Languages

Language:Dockerfile 57.5%Language:Go 33.7%Language:Makefile 8.0%Language:Shell 0.9%