FROM golang:1.17-alpine as builder
ARG ssh_prv_key
ARG ssh_pub_key
RUN apk update
RUN apk add git openssh

# Authorize SSH Host
RUN mkdir -p /root/.ssh && \
    chmod 0700 /root/.ssh && \
    ssh-keyscan github.com > /root/.ssh/known_hosts

# Add the keys and set permissions
RUN echo "${ssh_prv_key}" > /root/.ssh/id_rsa && \
    echo "${ssh_pub_key}" > /root/.ssh/id_rsa.pub && \
    chmod 600 /root/.ssh/id_rsa && \
    chmod 600 /root/.ssh/id_rsa.pub

# Set things up so that github works with go get.
RUN eval $(ssh-agent) && \
    ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts
RUN git config --global url.git@github.com:.insteadOf https://github.com/

RUN mkdir -p /app

WORKDIR /app 

COPY . .

RUN go get
RUN go build .

# Build done, so make our actual deployment container.

FROM alpine
EXPOSE 443
WORKDIR /app
COPY --from=builder /app/goose-backend /usr/bin/
ENTRYPOINT ["goose-backend"]
