# We need to specify the platforms below, otherwise platforms other than
# linux/amd64 will be forced to rebuild the contracts every time this
# image is used.

# This Dockerfile builds all the dependencies needed by the smart-contracts, excluding Go and Python.

FROM --platform=linux/amd64 us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:latest AS foundry

FROM --platform=linux/amd64 debian:bookworm-20240812-slim AS base

# Base: install deps
RUN apt-get update && apt-get install -y \
  curl \
  jq \
  ca-certificates \
  git \
  make \
  bash \
  --no-install-recommends

COPY --from=foundry /usr/local/bin/just /usr/local/bin/just
COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
COPY --from=foundry /usr/local/bin/cast /usr/local/bin/cast

WORKDIR /opt/optimism

COPY ./mise.toml ./mise.toml
COPY ./packages ./packages
COPY .git/ ./.git
COPY .gitmodules ./.gitmodules

RUN git submodule update --init --recursive \
    && cd packages/contracts-bedrock \
    && just forge-build \
    && echo $(git rev-parse HEAD) > .gitcommit
