Skip to content

Commit

Permalink
Improve Dockerfile (#203)
Browse files Browse the repository at this point in the history
* Improve Dockerfile

* chore: Add better comments

* chore: Add .dockerignore

* chore: Use entrypoint instead of command
  • Loading branch information
janjakubnanista authored Oct 17, 2024
1 parent b9be2fd commit 475d118
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Git metafiles
.git*

# Editor metafiles
.vscode

# Docker metafiles
Dockerfile

# Project metafiles
docs
examples
README.md
72 changes: 65 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]

0 comments on commit 475d118

Please sign in to comment.