FROM rust as rustls-base1
ARG VERSION
WORKDIR /src/
RUN git clone --branch=v/${VERSION} --depth=1 https://github.com/rustls/rustls
WORKDIR rustls/rustls-mio
RUN cargo build --bin tlsserver-mio --release
RUN cargo build --bin tlsclient-mio --release

FROM debian:stable-slim as rustls-base2
FROM entrypoint as entrypoint

FROM rustls-base2 as rustls-server
ARG VERSION
LABEL "tls_implementation"="rustls"
LABEL "tls_implementation_version"="${VERSION}"
LABEL "tls_implementation_connectionRole"="server"
COPY --from=rustls-base1 /src/rustls/target/release/tlsserver-mio /usr/local/bin/
COPY --from=entrypoint /bin/server-entrypoint /usr/local/bin/
ENTRYPOINT ["server-entrypoint", "tlsserver-mio"]

FROM rustls-base2 as rustls-client
ARG VERSION
LABEL "tls_implementation"="rustls"
LABEL "tls_implementation_version"="${VERSION}"
LABEL "tls_implementation_connectionRole"="client"
COPY --from=rustls-base1 /src/rustls/target/release/tlsclient-mio /usr/local/bin/
COPY --from=entrypoint /bin/client-entrypoint /usr/local/bin/
ENTRYPOINT ["client-entrypoint", "tlsclient-mio"]
