55 lines
1.3 KiB
Bash
Executable file
55 lines
1.3 KiB
Bash
Executable file
#!/bin/sh
|
|
# Create all the different builds for listen
|
|
|
|
# verify we are at root of repository
|
|
if ! [ -d .git ]; then
|
|
echo build: this script must be run at the root of the repo
|
|
exit 1
|
|
fi
|
|
|
|
build_go() {
|
|
go build -o out/$(go env GOOS)/listen .
|
|
}
|
|
|
|
build_docker() {
|
|
if [ $DOCKER_IMAGE ]; then
|
|
image=$DOCKER_IMAGE
|
|
if echo $image | grep -q server; then
|
|
os=windows
|
|
exe=C:/build/listen/listen.exe
|
|
else
|
|
os=linux
|
|
exe=/usr/src/listen/listen
|
|
fi
|
|
else
|
|
if [ -f /c/Program\ Files/Docker/Docker/DockerCli.exe ]; then
|
|
os=windows
|
|
exe=C:/build/listen/listen.exe
|
|
image=1-nanoserver
|
|
else
|
|
os=linux
|
|
exe=/usr/src/listen/listen
|
|
image=1-alpine
|
|
fi
|
|
fi
|
|
|
|
echo building with $os image golang:$image
|
|
mkdir -p out/docker
|
|
if docker build -t listen-build --build-arg IMAGE=$image -f docker/build.$os.Dockerfile .; then
|
|
docker create --name listen-build-tmp listen-build
|
|
docker cp listen-build-tmp:$exe out/docker
|
|
docker rm listen-build-tmp
|
|
fi
|
|
}
|
|
|
|
mkdir -p out
|
|
# if an arg is specified, force building with the specified method
|
|
[ $1 ] && build_$1 && exit
|
|
|
|
# prefer building with local go install if it exists on path
|
|
if which go &> /dev/null; then
|
|
build_go
|
|
# otherwise, try building with docker
|
|
elif which docker &> /dev/null; then
|
|
build_docker
|
|
fi
|