message_buffer: Add Dockerfile with caching (#778)

* message_buffer: Add Dockerfile with caching

This dockerfile ensures as little cache invalidation as possible
through layer-caching and BuildKit cache mounts.

* dockerignowe -> dockerignore

* message_buffer/Dockerfile: Fix the final cached target move
This commit is contained in:
Stanisław Drozd 2023-04-26 16:57:00 +02:00 committed by GitHub
parent 2bc98b426e
commit c210bf0f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,2 @@
target
node_modules

36
message_buffer/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
ARG RUST_VERSION=1.69
FROM rust:${RUST_VERSION}
RUN apt-get update && apt-get install -qq nodejs npm curl
RUN npm install --global yarn
RUN rustup default ${RUST_VERSION}
ARG SOLANA_VERSION=v1.14.11
RUN curl -sSfL https://release.solana.com/${SOLANA_VERSION}/install > install_solana.sh
RUN sh install_solana.sh
ENV PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
RUN --mount=type=cache,target=target cargo install --git https://github.com/coral-xyz/anchor avm --locked --force --target-dir target
ARG ANCHOR_VERSION=0.27.0
RUN --mount=type=cache,target=target CARGO_TARGET_DIR=target avm install ${ANCHOR_VERSION} && avm use ${ANCHOR_VERSION}
# Trigger Anchor's BPF tools download for caching
RUN anchor init decoy-crate
RUN cd decoy-crate && anchor build
RUN rm -rf decoy-crate
WORKDIR message_buffer
# layer-cache cargo deps
ADD Cargo.toml Cargo.lock ./
ADD programs/message_buffer/Cargo.toml programs/message_buffer/
RUN mkdir -p programs/message_buffer/src && touch programs/message_buffer/src/lib.rs
RUN cargo fetch --locked
ADD . .
RUN --mount=type=cache,target=target anchor build -p message_buffer && cp -r target target_tmp
RUN rm -rf target && mv target_tmp target