Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discuss: refactor: docker builds #360

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 /
Comment on lines +109 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be tested but to remove. We have default values in the code and user can set their own environment variables/mount .env if he wants


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" ]
Loading