Skip to content

Commit

Permalink
Reduce docker image size
Browse files Browse the repository at this point in the history
  • Loading branch information
wjthieme committed Oct 20, 2024
1 parent 4a08738 commit cd04291
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
--platform linux/x86_64 \
--build-arg RUSTC_VERSION=${{ matrix.config.rustc }} \
--build-arg NODE_VERSION=${{ matrix.config.node }} \
--build-arg SOLANA_CLI=${{ matrix.config.solana }} \
--build-arg ANCHOR_CLI=${{ matrix.config.anchor }} \
--build-arg SOLANA_VERSION=${{ matrix.config.solana }} \
--build-arg ANCHOR_VERSION=${{ matrix.config.anchor }} \
$tags .
- name: Push Docker Image
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
57 changes: 29 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
FROM ubuntu:24.04
FROM debian:bullseye-slim

ARG DEBIAN_FRONTEND=noninteractive
ARG RUSTC_VERSION="v1.78.0"
ARG NODE_VERSION="v22.8.0"
ARG SOLANA_CLI="v1.17.25"
ARG ANCHOR_CLI="v0.29.0"

ENV HOME="/root"
ENV PATH="${HOME}/.cargo/bin:${PATH}"
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
ENV PATH="${HOME}/.nvm/versions/node/${NODE_VERSION}/bin:${PATH}"
ARG SOLANA_VERSION="v1.17.25"
ARG ANCHOR_VERSION="v0.29.0"

# Install base utilities.
RUN apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
build-essential git curl wget jq pkg-config python3-pip \
libssl-dev libudev-dev
build-essential pkg-config libudev-dev curl

# Install rust.
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
sh rustup.sh --default-toolchain ${RUSTC_VERSION#v} -y && \
rustup component add rustfmt clippy

# Install node / npm / yarn.
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.40.1/install.sh | bash
ENV NVM_DIR="${HOME}/.nvm"
RUN . $NVM_DIR/nvm.sh && \
npm install -g yarn

# Install Solana tools.
RUN sh -c "$(curl -sSfL https://release.anza.xyz/${SOLANA_CLI}/install)"

# Install anchor.
RUN cargo install --git https://github.com/coral-xyz/anchor --tag ${ANCHOR_CLI} anchor-cli --locked
ENV PATH="/.cargo/bin:${PATH}"
RUN curl -O "https://static.rust-lang.org/dist/rust-${RUSTC_VERSION#v}-x86_64-unknown-linux-gnu.tar.xz" && \
tar -xvf rust-${RUSTC_VERSION#v}-x86_64-unknown-linux-gnu.tar.xz && \
sh ./rust-${RUSTC_VERSION#v}-x86_64-unknown-linux-gnu/install.sh && \
rm rust-${RUSTC_VERSION#v}-x86_64-unknown-linux-gnu.tar.xz && \
rm -r rust-${RUSTC_VERSION#v}-x86_64-unknown-linux-gnu

# Install node.
ENV PATH="/node-${NODE_VERSION}-linux-x64/bin:${PATH}"
RUN curl -O "https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.xz" && \
tar -xvf node-${NODE_VERSION}-linux-x64.tar.xz && \
rm node-${NODE_VERSION}-linux-x64.tar.xz

# Install Solana.
ENV PATH="/solana-release/bin:${PATH}"
RUN curl -O "https://release.anza.xyz/${SOLANA_VERSION}/solana-release-x86_64-unknown-linux-gnu.tar.bz2" && \
tar -xvf solana-release-x86_64-unknown-linux-gnu.tar.bz2 && \
rm solana-release-x86_64-unknown-linux-gnu.tar.bz2

# Install Anchor.
RUN npm install -g @coral-xyz/anchor-cli@${ANCHOR_VERSION#v}

# Install yarn.
RUN npm install -g yarn

# Build a dummy program to bootstrap the BPF SDK (doing this speeds up builds).
RUN anchor init dummy && cd dummy && (anchor build || true)
RUN rm -r dummy
RUN anchor init dummy && cd dummy && (anchor build || true) && cd .. && rm -r dummy

# Set up the working directory
RUN mkdir /workdir
Expand Down

0 comments on commit cd04291

Please sign in to comment.