ARG httpEchoServerVersion="latest"
ARG alpineVersion=3.7
FROM hashicorp/http-echo:${httpEchoServerVersion} as echo

EXPOSE 2379

FROM golang:alpine${alpineVersion}

ENV HTTPTEXT=${HTTPTEXT:-"Hello word"}
ENV ETCDCTL_API=${etcdApiVersion:-3}
ENV ETCD_VERSION=${etcdVersion:-3.3.11}

COPY --from=echo /http-echo /usr/local/bin/http-echo
ADD ./etcdWait.sh /usr/bin/etcdWait

ARG etcdFolder=etcd-v$ETCD_VERSION-linux-amd64

RUN apk add --no-cache wget && \
    wget https://github.com/kelseyhightower/confd/releases/download/v0.16.0/confd-0.16.0-darwin-amd64 -o /usr/local/bin/confd && \
    wget https://github.com/coreos/etcd/releases/download/v$ETCD_VERSION/${etcdFolder}.tar.gz && \
    tar -zxvf ${etcdFolder}.tar.gz && \
    mv $(pwd)/${etcdFolder}/etcdctl /usr/local/bin/etcdctl && \
    chmod +x /usr/bin/etcdWait

# confd -onetime -backend etcd && cat /tmp/myScript.conf && 
CMD etcdWait && http-echo -text="$HTTPTEXT"
