|
1 | 1 | # |
2 | | -# Docker image to generate deterministic, verifiable builds of Anchor programs. |
3 | | -# This must be run *after* a given ANCHOR_CLI version is published and a git tag |
4 | | -# is released on GitHub. |
| 2 | +# Drift Protocol Dev Container |
5 | 3 | # |
6 | 4 |
|
7 | 5 | FROM --platform=linux/amd64 rust:1.70.0 |
8 | 6 |
|
9 | 7 | ARG DEBIAN_FRONTEND=noninteractive |
10 | | - |
11 | 8 | ARG SOLANA_CLI="1.16.27" |
12 | 9 | ARG ANCHOR_CLI="0.29.0" |
13 | 10 | ARG NODE_VERSION="20.18.1" |
14 | 11 |
|
15 | | -# Create a non-root user |
16 | | -ARG USERNAME=vscode |
17 | | -ARG USER_UID=1000 |
18 | | -ARG USER_GID=$USER_UID |
19 | | - |
20 | | -RUN groupadd --gid $USER_GID $USERNAME \ |
21 | | - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ |
22 | | - && apt-get update \ |
23 | | - && apt-get install -y sudo \ |
24 | | - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ |
25 | | - && chmod 0440 /etc/sudoers.d/$USERNAME |
26 | | - |
27 | | -ENV HOME="/home/$USERNAME" |
28 | | -ENV PATH="${HOME}/.cargo/bin:${PATH}" |
29 | | -ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}" |
30 | | - |
31 | | -# Install base utilities. |
32 | | -RUN mkdir -p /workdir && mkdir -p /tmp && \ |
33 | | - apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \ |
34 | | - build-essential git curl wget jq pkg-config python3-pip xz-utils \ |
35 | | - libssl-dev libudev-dev |
36 | | - |
37 | | -# libssl1.1 is not needed for newer versions |
38 | | - |
39 | | -# Install rust. |
40 | | -RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \ |
41 | | - sh rustup.sh -y && \ |
42 | | - rustup component add rustfmt clippy |
43 | | - |
44 | | -# Install node / npm / yarn (pinned) |
45 | | -RUN curl -fsSLO https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz && \ |
46 | | - tar -xJf node-v${NODE_VERSION}-linux-x64.tar.xz -C /usr/local --strip-components=1 && \ |
47 | | - rm node-v${NODE_VERSION}-linux-x64.tar.xz && \ |
48 | | - corepack enable && \ |
49 | | - npm install -g ts-mocha typescript mocha yarn |
50 | | - |
51 | | -RUN node -v && npm -v |
52 | | - |
53 | | -# Install Solana tools (x86_64 version). |
54 | | -RUN curl -sSfL https://github.com/solana-labs/solana/releases/download/v${SOLANA_CLI}/solana-release-x86_64-unknown-linux-gnu.tar.bz2 | tar -xjC /tmp && \ |
55 | | - mv /tmp/solana-release/bin/* /usr/local/bin/ && \ |
56 | | - rm -rf /tmp/solana-release |
57 | | - |
58 | | -# Install anchor. |
59 | | -RUN cargo install --git https://github.com/coral-xyz/anchor --tag v${ANCHOR_CLI} anchor-cli --locked |
60 | | - |
61 | | -# Switch to the non-root user for the remaining setup |
62 | | -USER $USERNAME |
63 | | - |
64 | | -RUN solana-keygen new --no-bip39-passphrase |
65 | | - |
66 | | -# Set up Solana config for local development |
67 | | -RUN solana config set --url localhost |
68 | | - |
69 | | -# Create necessary directories |
70 | | -RUN mkdir -p $HOME/.config/solana |
| 12 | +ENV HOME="/root" |
| 13 | +ENV PATH="/usr/local/cargo/bin:${PATH}" |
| 14 | +ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}" |
| 15 | + |
| 16 | +RUN mkdir -p /workdir /tmp && \ |
| 17 | + apt-get update -qq && apt-get upgrade -qq && apt-get install -y --no-install-recommends \ |
| 18 | + build-essential git curl wget jq pkg-config python3-pip xz-utils ca-certificates \ |
| 19 | + libssl-dev libudev-dev bash && \ |
| 20 | + rm -rf /var/lib/apt/lists/* |
| 21 | + |
| 22 | +RUN rustup component add rustfmt clippy |
| 23 | + |
| 24 | +RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -o /tmp/node.tar.xz \ |
| 25 | + && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \ |
| 26 | + && rm /tmp/node.tar.xz \ |
| 27 | + && corepack enable \ |
| 28 | + && npm install -g ts-mocha typescript mocha \ |
| 29 | + && node -v && npm -v && yarn -v |
| 30 | + |
| 31 | +# Solana CLI (x86_64 build) |
| 32 | +RUN curl -sSfL "https://github.com/solana-labs/solana/releases/download/v${SOLANA_CLI}/solana-release-x86_64-unknown-linux-gnu.tar.bz2" \ |
| 33 | + | tar -xjC /tmp \ |
| 34 | + && mv /tmp/solana-release/bin/* /usr/local/bin/ \ |
| 35 | + && rm -rf /tmp/solana-release |
| 36 | + |
| 37 | +# Anchor CLI |
| 38 | +RUN cargo install --git https://github.com/coral-xyz/anchor --tag "v${ANCHOR_CLI}" anchor-cli --locked |
| 39 | + |
| 40 | +# Set up Solana key + config for root |
| 41 | +RUN solana-keygen new --no-bip39-passphrase --force \ |
| 42 | + && solana config set --url localhost |
| 43 | + |
| 44 | +RUN apt-get update && apt-get install -y zsh curl git \ |
| 45 | + && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended \ |
| 46 | + && chsh -s /usr/bin/zsh vscode |
71 | 47 |
|
72 | 48 | WORKDIR /workdir |
0 commit comments