Skip to content

Instantly share code, notes, and snippets.

@EwanValentine
Created March 27, 2017 09:39
Show Gist options
  • Save EwanValentine/8441ab15030b100f60bf3423bf9f7c8d to your computer and use it in GitHub Desktop.
Save EwanValentine/8441ab15030b100f60bf3423bf9f7c8d to your computer and use it in GitHub Desktop.
Go + Docker build script example
#!/bin/bash
source ~/.bashrc
echo "Building"
# Build Go binary in Docker image
docker run --rm \
-e "GOPATH=/go" \
-e "CGO_ENABLED=0" \
-e "GOOS=linux" \
-e "GOARCH=amd64" \
-v `pwd`/api:/go/src/bitbucket.org/ewanvalentine/test/api \
-w /go/src/bitbucket.org/ewanvalentine/test/api \
golang:1.8.0 \
bash -c "go get && go build -o api" -v
# Build docker image
docker build -t test/api:latest ./api
# Stop previous container
docker stop test-api || true && docker rm test-api || true
# Run new one
docker run --name test-api -d -p 8080:2000 \
-e ENV=production \
-e DB_HOST=mongodb://admin:pass@datastore:27017 \
-e DB_NAME=irs \
test/api:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment