Created
February 2, 2015 15:28
-
-
Save ngauthier/ed3deeea8bd2cb038293 to your computer and use it in GitHub Desktop.
Static Golang Container via Tar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Makes a docker container for a static golang application. | |
# For a small app, this container is usually about 7mb. | |
# | |
# Usage: | |
# build-container myapp myuser/myapp cmd/myapp/main.go | |
set -e | |
# Version is the git sha for HEAD | |
version=$(git log -1 --format=format:%H) | |
mkdir -p tmp | |
# Statically linked binary for golang 1.4 | |
CGO_ENABLED=0 go build -a -installsuffix cgo -o tmp/$1 $3 | |
cd tmp | |
# Make tar containing the binary and import into docker under repo and tag | |
tar cv $1 | docker import - $2:$version | |
# Also retag latest | |
docker tag -f $2:$version $2:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can: