FROM golang:1.14-alpine AS builder

COPY . /go/kuiper

WORKDIR /go/kuiper

RUN apk add gcc make git libc-dev binutils-gold pkgconfig zeromq-dev 
RUN go build  -o kuiper_conf_util deploy/docker/conf_util.go \
    && if [ "$(uname -m)" == "x86_64" ]; then apk add upx && upx ./kuiper_conf_util; fi
RUN make build_with_edgex

FROM alpine:3.12

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 apk add sed libzmq

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"]
