Skip to content

Instantly share code, notes, and snippets.

@ardyantohermawan
Created August 24, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardyantohermawan/23653f5af381427b7333bbb7f72cd34f to your computer and use it in GitHub Desktop.
Save ardyantohermawan/23653f5af381427b7333bbb7f72cd34f to your computer and use it in GitHub Desktop.
Docker image builder
#!/bin/bash
NAMESPACE="$1"
NAME="$2"
TAG="$3"
echo "=================================="
echo "|| ||"
echo "|| Docker image builder ||"
echo "|| ||"
echo "=================================="
printf "\n\n"
if [[ -z "$NAMESPACE" ]]; then
echo "Please insert the namespace";
echo "Usage: /bin/bash builder.sh [namespace] [name] [tag]";
exit 1;
fi
if [[ -z "$NAME" ]]; then
echo "Please insert the name";
echo "Usage: /bin/bash builder.sh [namespace] [name] [tag]";
exit 1;
fi
if [[ -z "$TAG" ]]; then
echo "Please insert the tag";
echo "Usage: /bin/bash builder.sh [namespace] [name] [tag]";
exit 1;
fi
compile() {
echo "start compiling application...";
printf "\n\n"
docker run --rm -it -v "$GOPATH":/gopath -v "$(pwd)":/app \
-e "GOPATH=/gopath" -w /app golang:latest \
sh -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o '"$NAME";
echo "compile finished";
printf "\n\n"
}
buildImage() {
printf "\n\n"
echo "start building docker image...";
docker build -t $NAMESPACE/$NAME:$TAG .
echo $NAMESPACE/$NAME:$TAG "build finished";
printf "\n\n"
}
compile
buildImage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment