# syntax=docker/dockerfile:1
FROM ghcr.io/romange/alpine-dev as builder

WORKDIR /build
COPY src/  ./src/
COPY helio/  ./helio/
COPY patches/  ./patches/
COPY CMakeLists.txt ./
RUN ./helio/blaze.sh -release -DBoost_USE_STATIC_LIBS=ON

WORKDIR build-opt
RUN ninja dragonfly

FROM alpine:latest

RUN addgroup -S -g 1000 dfly && adduser -S -G dfly -u 999 dfly
RUN apk --no-cache add libgcc libstdc++ libunwind boost-context \
    'su-exec>=0.2' netcat-openbsd openssl

RUN mkdir /data && chown dfly:dfly /data
VOLUME /data
WORKDIR /data
COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY tools/docker/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY --from=builder /build/build-opt/dragonfly /usr/local/bin/
RUN dragonfly -version

HEALTHCHECK CMD /usr/local/bin/healthcheck.sh
ENTRYPOINT ["entrypoint.sh"]

EXPOSE 6380

USER dfly

CMD ["dragonfly", "--logtostderr"]
