FROM node:alpine as frontend-builder
WORKDIR /app
COPY frontend/package.json /app
COPY frontend/package-lock.json /app
RUN npm install
COPY frontend .
RUN npm run build

FROM alpine:latest as geoip-fetcher
RUN apk add --no-cache git
WORKDIR /app
RUN git clone https://github.com/geoacumen/geoacumen-country.git
RUN find .

FROM golang:latest as builder
WORKDIR /app
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
RUN go mod download
COPY . /app
COPY --from=geoip-fetcher /app/geoacumen-country/Geoacumen-Country.mmdb honeypot/ssh
COPY --from=frontend-builder /app/dist /app/web/frontend/dist
RUN CGO_ENABLED=0 go build -tags embed cmd/apiary/apiary.go

FROM alpine:latest
RUN apk add --no-cache curl
WORKDIR /app
COPY --from=builder /app/apiary.toml /app/apiary.toml
COPY --from=builder /app/apiary /app/apiary
EXPOSE 8080
EXPOSE 2222
CMD ["/app/apiary", "serve"]
