Giter Club home page Giter Club logo

go-cross's Introduction

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

go-cross's People

Contributors

hinshun avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.