FROM ubuntu:18.04 as builder

ENV DEBIAN_FRONTEND=noninteractive

RUN set -e -x ;\
    apt-get -y update ;\
    apt-get -y upgrade ;\
    apt-get -y install golang build-essential protobuf-compiler ;\
    rm -rf /var/lib/apt/lists

ENV GOPATH=/go
ENV PATH=/go/bin:$PATH

WORKDIR /go/src/code.hackerspace.pl/hscloud

ADD go/vendor go/vendor

RUN set -e -x ;\
    go install code.hackerspace.pl/hscloud/go/vendor/github.com/golang/protobuf/protoc-gen-go ;\
    go install code.hackerspace.pl/hscloud/go/vendor/github.com/gobuffalo/packr/packr

ADD . .

RUN set -e -x ;\
    go generate code.hackerspace.pl/hscloud/... ;\
    go install code.hackerspace.pl/hscloud/go/svc/...

FROM ubuntu:18.04

RUN set -e -x ;\
    useradd -rm svc

COPY --from=builder /go/bin/* /usr/local/bin/

USER svc
ENV PATH=/usr/local/bin:$PATH
