-
-
Save sbusso/d6b98aea35367b34cdb89e9f9cec739e to your computer and use it in GitHub Desktop.
Go + Docker build script example
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
#!/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