diff --git a/.gitignore b/.gitignore index 722d5e7..a684b47 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode +.vscode/ +out/ diff --git a/build b/build new file mode 100755 index 0000000..5efd0f2 --- /dev/null +++ b/build @@ -0,0 +1,47 @@ +#!/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 + else + image=1-alpine + fi + + if echo $i | grep -q server; then + os=windows + exe=C:/build/listen/listen.exe + else + os=linux + exe=/usr/src/listen/listen + fi + + echo building with $os image golang:$image + mkdir -p out/docker + docker build -t listen-build --build-arg IMAGE=$image -f docker/build.$os.Dockerfile . + docker create --name listen-build-tmp listen-build + docker cp listen-build-tmp:$exe out/docker + docker rm listen-build-tmp +} + +mkdir -p out +# if an arg is specified, force building with the specified method +[ $1 ] && build_$1 + +# 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 diff --git a/docker/build.linux.Dockerfile b/docker/build.linux.Dockerfile new file mode 100644 index 0000000..1a4c55a --- /dev/null +++ b/docker/build.linux.Dockerfile @@ -0,0 +1,14 @@ +# This Dockerfile is meant for building listen for Linux ONLY +# listen is currently not intended to run in a Docker container + +ARG IMAGE + +FROM golang:${IMAGE} AS build + +WORKDIR /usr/src/listen +COPY . . + +RUN apk upgrade --no-cache +RUN go build . + +CMD ["tail", "-f", "/dev/null"] diff --git a/docker/build.windows.Dockerfile b/docker/build.windows.Dockerfile new file mode 100644 index 0000000..c308e78 --- /dev/null +++ b/docker/build.windows.Dockerfile @@ -0,0 +1,13 @@ +# This Dockerfile is meant for building listen for Windows ONLY +# listen is currently not intended to run in a Docker container + +ARG IMAGE + +FROM golang:${IMAGE} AS build + +WORKDIR C:/build/listen +COPY . . + +RUN go build . + +CMD ["ping.exe", "-t", "localhost"]