# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.13-alpine AS build
WORKDIR /magnetico

RUN export PATH=$PATH:/go/bin
RUN apk add --no-cache build-base curl git
RUN go get -u github.com/kevinburke/go-bindata/...

# Copy the local package files to the container's workspace.
ADD ./Makefile        /magnetico/
ADD ./pkg             /magnetico/pkg
ADD ./go.mod          /magnetico/go.mod
ADD ./cmd/magneticow  /magnetico/cmd/magneticow

RUN     make magneticow

FROM alpine:latest
LABEL maintainer="bora@boramalper.org"
# the service listens on port 8080
EXPOSE 8080
WORKDIR /
VOLUME /root/.local/share/magneticod

RUN mkdir -p "/root/.config/magneticow/"
RUN echo 'magnetico:$2y$06$8VzJvXegA2X/tfmTXN7NM.FH5HRh8fbvXUmrtW52xLH5JNDhldexG' > "/root/.config/magneticow/credentials"

COPY --from=build /go/bin/magneticow /magneticow

ENTRYPOINT ["/magneticow"]
