8000 GitHub - hinshun/go-cross: Cross-compile golang to linux and darwin
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hinshun/go-cross

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cross

hinshun/go-cross is a Docker image to cross compile golang binaries and plugins to linux/darwin. It is based off work from docker/cli:

Cross-compiling using docker build

Using hinshun/go-cross:mod to cache go modules and hinshun/go-cross:build that has ONBUILD triggers you can define a Dockerfile with only the following:

FROM hinshun/go-cross:mod AS mod
FROM hinshun/go-cross:build

For example, if my project looks like this:

❯ tree
.
├── cmd
│   └── program
│       └── main.go
├── Dockerfile
├── go.mod
└── go.sum

Then you can cross-compile the program like so (BUILDMODE and LDFLAGS are optional):

docker build -t my-cross-compile --build-arg PKG="./cmd/program" --build-arg BUILDMODE="default" --build-arg LDFLAGS="" .

Extract the binaries by creating a temporary container and docker cp them out.

mkdir bin
docker create --name tmp my-cross-compile bash
docker cp tmp:/root/go/bin/. bin
docker rm tmp

Private go modules

If you have private go modules, you can use that as long as the following are true:

  • The stage is set to AS mod
  • The go module cache is in /root/.cache/go-build and /root/go/pkg/mod
FROM golang:1.11-alpine AS mod
ENV GOPATH=/root/go
ENV GOCACHE=/root/.cache/go-build
# Copy or mount in SSH, certificates, etc...
RUN go mod download

FROM hinshun/go-cross:build

About

Cross-compile golang to linux and darwin

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0