FROM docker.io/golang:1.18 as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main .

FROM docker.io/debian:bookworm-slim
RUN apt update; apt -y upgrade; apt install -y wget; wget "https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-linux-amd64.deb"; dpkg -i "litestream-v0.3.13-linux-amd64.deb"

WORKDIR /root/
COPY --from=builder /app/main .
COPY ./web/ web/
COPY ./assets/ assets/
COPY ./etc/litestream.yml .

EXPOSE 8080

ENV  FIBER_PROD=true

# run restore first in case db exists, then run main process
COPY ./start.sh .
CMD ["./start.sh"]