FROM centos:7

RUN yum install -y make wget git which rpm-build gcc

ARG GO_VERSION=1.14.4

RUN case $(arch) in \
        x86_64) \
            case $(getconf LONG_BIT) in \
                64) \
                    ARCH=amd64; \
                    yum install -y epel-release; \
                    yum install -y upx \
                ;; \
                32) ARCH=386;; \
            esac \
        ;; \
        aarch64) \
            ARCH=arm64 \
        ;; \
        arm) \
            ARCH=armv6l \
        ;; \
        ppc64le) \
            ARCH=ppc64le\
        ;; \
        s390x) \
            ARCH=s390x \
        ;; \
    esac \
    && wget https://golang.org/dl/go$GO_VERSION.linux-$ARCH.tar.gz \
    && tar -C /usr/local -xzf go$GO_VERSION.linux-$ARCH.tar.gz

ENV PATH=$PATH:/usr/local/go/bin

COPY . /go/kuiper

WORKDIR /go/kuiper

ENV KUIPER_SOURCE=/go/kuiper

RUN make -C deploy/packages

RUN rpm -ivh _packages/*.rpm \
    && [ ! -z $(rpm -q emqx | grep -o emqx) ] \
    && rpm -e kuiper \
    && [ "$(rpm -q emqx)" == "package emqx is not installed" ]

