FROM golang:1.17-alpine AS build_base

RUN apk add --no-cache git

# Set the Current Working Directory inside the container
WORKDIR /tmp/app

# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

# Build the Go app
RUN go build main.go

FROM alpine as final

WORKDIR /app

COPY --from=build_base /tmp/app/main .
COPY --from=build_base /tmp/app/static ./static
COPY --from=build_base /tmp/app/templates ./templates
COPY --from=build_base /tmp/app/signature/public.pem ./signature/

# This container exposes port 8080 to the outside world
EXPOSE 8080

# Run the binary program produced by `go install`
CMD ["./main"]