Skip to content

Commit

Permalink
feat: build target for each binary
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaatif committed Jul 3, 2024
1 parent 06cab94 commit c3246ba
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# This is loosely based on `docker init`'s rust template.
# For a completely clean build, run something like this:
# ```
# docker build --build-arg=PROFILE=dev --build-arg=ENTRYPOINT=leader --no-cache
# docker build --build-arg=PROFILE=dev --no-cache
# ```
#
# There is a build target[^1] for each artifact we want.
#
# [^1]: https://docs.docker.com/build/building/multi-stage/

#############
# Build stage
Expand Down Expand Up @@ -71,10 +75,10 @@ find "/artifacts/$SUBDIR" \

EOF

##################
# Final executable
##################
FROM debian:bullseye-slim AS final
##########################
# Base for the final image
##########################
FROM debian:bullseye-slim AS base

# Install runtime dependencies.
RUN apt-get update && apt-get install -y \
Expand All @@ -84,23 +88,6 @@ RUN apt-get update && apt-get install -y \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build /output/* /usr/local/bin/
RUN <<EOF
set -eux
: smoke test executables
find /usr/local/bin -type f -executable -print0 \
| xargs --null --replace --verbose tini -- {} --help
EOF

# can't refer to docker args in an ENTRYPOINT directive, so go through a symlink
ARG ENTRYPOINT
RUN ln --symbolic --verbose -- "$(which ${ENTRYPOINT})" /entrypoint
ENTRYPOINT [ "tini", "--", "/entrypoint" ]

# TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/356
# this is bad practice
COPY .env /

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
Expand All @@ -114,3 +101,22 @@ RUN adduser \
user
USER user

####################################
# Final executables with entrypoints
####################################
FROM base AS leader

# TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/356
# this is bad practice
COPY .env /

COPY --from=build /output/leader /usr/local/bin/
COPY --from=build /output/rpc /usr/local/bin/
RUN leader --help && rpc --help
ENTRYPOINT [ "tini", "--", "leader" ]

FROM base AS worker

COPY --from=build /output/worker /usr/local/bin/
RUN worker --help
ENTRYPOINT [ "tini", "--", "worker" ]

0 comments on commit c3246ba

Please sign in to comment.