FROM golang:1.14 AS builder

COPY . /go/kuiper

WORKDIR /go/kuiper

RUN apt update && apt install -y pkg-config libczmq-dev
RUN go build  -o kuiper_conf_util deploy/docker/conf_util.go \
    && if [ "$(uname -m)" != "aarch64" ]; then apt install -y upx && upx ./kuiper_conf_util; fi
RUN make build_with_edgex

FROM debian:10

COPY ./deploy/docker/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
COPY --from=builder /go/kuiper/kuiper_conf_util /usr/bin/kuiper_conf_util
COPY --from=builder /go/kuiper/_build/kuiper-* /kuiper/

RUN apt update && apt install -y pkg-config libczmq-dev

WORKDIR /kuiper

ENV MAINTAINER="emqx.io"
ENV KUIPER_HOME /kuiper
ENV KUIPER__BASIC__CONSOLELOG true

VOLUME ["/kuiper/etc", "/kuiper/data", "/kuiper/plugins", "/kuiper/log"]
EXPOSE 9081 20498

ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

CMD ["./bin/server"]
