FROM alpine:3.15 as intermediate

RUN mkdir /src
WORKDIR /src

# Install the build tools
RUN apk add git go make

# Fetch the Nebula source
RUN git clone https://github.com/slackhq/nebula.git

# Compile the Nebula GNU/Linux binaries for all platforms
WORKDIR /src/nebula
RUN make bin

RUN go install github.com/chrislusf/seaweedfs/weed@latest

# Start from a clean image
FROM alpine:3.15

# Install some required tools
RUN apk add fuse go jq
RUN go install github.com/square/certstrap@latest
ENV PATH=$PATH:/root/go/bin

RUN mkdir /app
WORKDIR /app

# Copy over the compiled binaries
COPY --from=intermediate /src/nebula/nebula .
COPY --from=intermediate /src/nebula/nebula-cert .
COPY --from=intermediate /root/go/bin/weed .

COPY nebula-start.sh .
COPY seaweedfs-start.sh .
COPY docker-entrypoint.sh ./entrypoint.sh

EXPOSE 4242/udp
EXPOSE 9333/tcp
EXPOSE 8080/tcp
EXPOSE 18080/tcp
EXPOSE 8888/tcp
EXPOSE 18888/tcp
ENTRYPOINT [ "/bin/sh", "/app/entrypoint.sh" ]