# This Dockerfile is for the main forest binary
#
# Build and run locally:
# ```
# docker build -t forest:alpine -f ./Dockerfile-alpine .
# docker run --init -it forest:alpine
# ```
#
# Build and manually push to Github Container Registry (see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry)
# ```
# docker build -t ghcr.io/chainsafe/forest:alpine .
# docker push ghcr.io/chainsafe/forest:alpine
# ```
##
# Build stage
# Use github action runner cached images to avoid being rate limited
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md#cached-docker-images
##
FROM alpine:3 AS build-env
# Install dependencies
RUN apk update && \
apk add --no-cache git curl make gcc clang clang-dev musl-dev
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /forest
COPY . .
# Install Forest. Move it out of the cache for the prod image.
RUN --mount=type=cache,sharing=private,target=/root/.cargo/registry \
--mount=type=cache,sharing=private,target=/root/.rustup \
--mount=type=cache,sharing=private,target=/forest/target \
make install-with-mimalloc && \
mkdir /forest_out && \
cp /root/.cargo/bin/forest* /forest_out
##
# Prod image for forest binary
# Use github action runner cached images to avoid being rate limited
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md#cached-docker-images
##
FROM alpine:3
# Install binary dependencies
RUN apk update && \
apk add --no-cache ca-certificates
RUN update-ca-certificates
# Copy forest daemon and cli binaries from the build-env
COPY --from=build-env /forest_out/* /usr/local/bin/
# Basic verification of dynamically linked dependencies
RUN forest -V && forest-cli -V && forest-tool -V && forest-wallet -V
ENTRYPOINT ["forest"]