This is a container to build golang static binaries with cgo musl for amd64, glibc for freebsd, and windows
Check out your source files to a GOPATH compatible directory:
mkdir -p src/github.com/user
git clone https://github.com/user/repo.git src/github.com/user/repo
Then build!
docker run --rm -it -v "$PWD:/go" -u "$UID:$GID" storjlabs/golang github.com/user/repo
For when another repo is included in a src
directory, for instance, a submodule:
tar c src \
| docker run --rm -i -e TAR=1 storjlabs/golang github.com/user/repo \
| tar -x ./main
For when there's just source files in a diretory:
tar c . \
| docker run --rm -i -e TAR=1 storjlabs/golang -o main \
| tar -x ./main
VERBOSE
This makes the loader script more verbose
This image supports docker multistage builds. Simply use this as template for your Dockerfile:
ARG REPOSITORY=github.com/storjlabs/example
FROM storjlabs/golang as builder
FROM scratch
ENV ADDRESS=
EXPOSE 80
ENTRYPOINT ["/repo", "serve"]
COPY --from=builder /app /repo
Then build with this:
docker build -t user/repo --build-arg PACKAGE=github.com/user/repo .