#!/bin/bash

"${ROOTDIR}/setup/x509pop/setup.sh" conf/server conf/upstream-agent conf/downstream-agent

LAST_ENVOY_RELEASE_WITH_V2=v1.16.0

cat > Dockerfile <<EOF
FROM spire-agent:latest-local as spire-agent

FROM envoyproxy/envoy:${LAST_ENVOY_RELEASE_WITH_V2} AS envoy-agent-mashup
COPY --from=spire-agent /opt/spire/bin/spire-agent /opt/spire/bin/spire-agent
RUN apt-get update
RUN apt-get install -y dumb-init
RUN apt-get install -y supervisor
COPY conf/supervisord.conf /etc/
ENTRYPOINT ["/usr/bin/dumb-init", "supervisord", "--nodaemon", "--configuration", "/etc/supervisord.conf"]
CMD []
EOF

docker build --target envoy-agent-mashup -t envoy-agent-mashup .
