From 475d1180754aacd59772c8437a330ff499f5c85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Thu, 17 Oct 2024 10:40:11 -0700 Subject: [PATCH] Improve Dockerfile (#203) * Improve Dockerfile * chore: Add better comments * chore: Add .dockerignore * chore: Use entrypoint instead of command --- .dockerignore | 13 ++++++++++ Dockerfile | 72 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..5ec836ef --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Git metafiles +.git* + +# Editor metafiles +.vscode + +# Docker metafiles +Dockerfile + +# Project metafiles +docs +examples +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7d26032d..e729ee5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,77 @@ -FROM golang:1.22 +# The base image for the supersim image can be modified +# by specifying BASE_IMAGE build argument +ARG BASE_IMAGE=golang:1.22 -RUN apt-get update && apt-get install -y curl git +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# This stage builds the foundry binaries +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM $BASE_IMAGE AS foundry -WORKDIR /app +# Make sure foundryup is available +ENV PATH="/root/.foundry/bin:${PATH}" +# Install required system packages +RUN \ + apt-get update && \ + apt-get install -y curl git + +# Install foundry RUN curl -L https://foundry.paradigm.xyz | bash +RUN foundryup -ENV PATH="/root/.foundry/bin:${PATH}" +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# This stage builds the project +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM $BASE_IMAGE AS builder -RUN foundryup +WORKDIR /app COPY . . RUN go mod tidy - RUN go build -o supersim cmd/main.go -CMD ["./supersim"] +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# This stage exposes the supersim binary +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM $BASE_IMAGE AS runner + +# Add foundry & supersim directories to the system PATH +ENV PATH="/root/.foundry/bin:/root/.supersim/bin:${PATH}" + +WORKDIR /app + +# Get the supersim binary from the builder +COPY --from=builder /app/supersim /root/.supersim/bin/supersim + +# Get the anvil binary +COPY --from=foundry /root/.foundry/bin/anvil /root/.foundry/bin/anvil + +# Make sure the required binaries exist +RUN anvil --version +RUN supersim --help + +# We'll use supersim as the entrypoint to our image +# +# This allows the consumers to pass CLI options as the command to docker run: +# +# docker run supersim --help +ENTRYPOINT [ "supersim" ]