FROM golang:1.10.3-alpine

# Update packages and install dependency packages for services
RUN apk update && apk add --no-cache bash git

EXPOSE {{port}}
EXPOSE {{debugPort}}

# Disables C compilation
ENV CGO_ENABLED=0

# Change working directory
WORKDIR $GOPATH/src/{{applicationName}}/

# Install dependencies
RUN go get -u github.com/golang/dep/...
RUN go get -u github.com/derekparker/delve/cmd/dlv/...
COPY . ./
RUN if test -e "Gopkg.toml"; then dep ensure -v; fi

RUN if test -e "run-dev"; then cp run-dev $GOPATH/bin; chmod 777 $GOPATH/bin/run-dev; fi
RUN chmod 777 $GOPATH/src/{{applicationName}}/

CMD ["/bin/bash"]

ARG bx_dev_user=root
ARG bx_dev_userid=1000
RUN BX_DEV_USER=$bx_dev_user
RUN BX_DEV_USERID=$bx_dev_userid
RUN if [ "$bx_dev_user" != root ]; then adduser -D -s /bin/bash -u $bx_dev_userid $bx_dev_user; fi
