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

Add Dockerfile #5

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
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
67 changes: 67 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Building this image will include the running of all benchmarks in a "cold
# cache" state, and thus will take quite a bit of time (roughly 30-60 minutes,
# with Ganache excluded). The cache will be retained in the built image, such
# that running the image will execute benchmarks with a "warm cache". For
# example:
mds1 marked this conversation as resolved.
Show resolved Hide resolved
#
# docker build --build-arg ETH_RPC_URL=... -t sim .
# docker run sim benchmark-hardhat
#
# To benchmark with a cleared cache, and without having to rebuild the entire
# tool environment, use something like:
#
# docker run --entrypoint /bin/bash sim -c "rm -rf cache && make benchmark-hardhat"
#
# BEWARE: This image should not be published because it will contain traces of
# your RPC url, which likely contains your private API key secret. (See
# https://stackoverflow.com/a/40762010/406289 .) Future work can take advantage
# of Docker's support for secrets, but unless/until there's a need to publish
# this image, that would be overkill.

FROM debian

ARG ETH_RPC_URL

RUN if [ -z "${ETH_RPC_URL}" ]; then \
echo build argument ETH_RPC_URL required; \
exit 1; \
fi && \
apt-get update && \
apt-get install --yes curl git make xz-utils yarnpkg && \
ln -s /usr/bin/yarnpkg /usr/bin/yarn

# nix/dapptools don't like to install/run as root
RUN useradd user && \
mkdir -p -m 0755 /home/user && \
chown user /home/user && \
mkdir -m 0755 /nix && \
chown user /nix
WORKDIR /home/user
USER user
# nix/dapptools install scripts require this environment:
ENV USER=user
ENV BASH_ENV=/home/user/.profile
ENV SHELL=/bin/bash
SHELL ["/bin/bash", "-c"]

RUN git clone https://github.com/mds1/convex-shutdown-simulation.git
WORKDIR convex-shutdown-simulation

RUN yarn && \
cp .env.example .env && \
sed -i "s!ETH_RPC_URL=.*!ETH_RPC_URL=${ETH_RPC_URL}!" .env && \
curl -L https://raw.githubusercontent.com/gakonst/foundry/master/foundryup/install | bash
# Don't combine these sequential RUN commands because we need fresh shell
# instances in order for each install script to take effect.
RUN foundryup && \
curl -L https://nixos.org/nix/install | bash
RUN curl -L https://dapp.tools/install | bash
RUN dapp update

# TODO: Benchmark ganache too, once it's fixed.
# (See https://github.com/mds1/convex-shutdown-simulation/pull/4)
RUN make benchmark-foundry && \
make benchmark-hardhat && \
make benchmark-dapptools

ENTRYPOINT ["make"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ uses about 16M gas and performs a number of token transfers
## Tips

- Set `export CLEAR_CACHE=1` in your `.env` file to clear the Ganache and Hardhat caches
- Consider running the benchmarks via Docker. See the comment header in [the Dockerfile](./Dockerfile) for details.