Skip to content

Commit 4a17883

Browse files
wphanmoosecat2
andauthored
make working devcontainer and dockerfile (#1919)
* make working devcontainer and dockerfile * fix node version * run as root * use final verison of devcontainer and dockerfile --------- Co-authored-by: Nour Alharithi <[email protected]>
1 parent 1f63c6e commit 4a17883

File tree

3 files changed

+135
-47
lines changed

3 files changed

+135
-47
lines changed

.devcontainer/Dockerfile

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
#
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
53
#
64

7-
FROM rust:1.75
5+
FROM --platform=linux/amd64 rust:1.70.0
86

97
ARG DEBIAN_FRONTEND=noninteractive
10-
11-
ARG SOLANA_CLI="1.14.7"
12-
ARG ANCHOR_CLI="0.26.0"
13-
ARG NODE_VERSION="v18.16.0"
8+
ARG SOLANA_CLI="1.16.27"
9+
ARG ANCHOR_CLI="0.29.0"
10+
ARG NODE_VERSION="20.18.1"
1411

1512
ENV HOME="/root"
16-
ENV PATH="${HOME}/.cargo/bin:${PATH}"
17-
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
18-
ENV PATH="${HOME}/.nvm/versions/node/${NODE_VERSION}/bin:${PATH}"
19-
20-
# Install base utilities.
21-
RUN mkdir -p /workdir && mkdir -p /tmp && \
22-
apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
23-
build-essential git curl wget jq pkg-config python3-pip \
24-
libssl-dev libudev-dev
25-
26-
RUN wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
27-
RUN dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
28-
29-
# Install rust.
30-
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
31-
sh rustup.sh -y && \
32-
rustup component add rustfmt clippy
33-
34-
# Install node / npm / yarn.
35-
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
36-
ENV NVM_DIR="${HOME}/.nvm"
37-
RUN . $NVM_DIR/nvm.sh && \
38-
nvm install ${NODE_VERSION} && \
39-
nvm use ${NODE_VERSION} && \
40-
nvm alias default node && \
41-
npm install -g yarn && \
42-
yarn add ts-mocha
43-
44-
# Install Solana tools.
45-
RUN sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_CLI}/install)"
46-
47-
# Install anchor.
48-
RUN cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
49-
RUN avm install ${ANCHOR_CLI} && avm use ${ANCHOR_CLI}
50-
51-
RUN solana-keygen new --no-bip39-passphrase
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 install 1.78.0 \
23+
&& rustup component add rustfmt clippy --toolchain 1.78.0
24+
25+
RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -o /tmp/node.tar.xz \
26+
&& tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \
27+
&& rm /tmp/node.tar.xz \
28+
&& corepack enable \
29+
&& npm install -g ts-mocha typescript mocha \
30+
&& node -v && npm -v && yarn -v
31+
32+
# Solana CLI (x86_64 build)
33+
RUN curl -sSfL "https://github.com/solana-labs/solana/releases/download/v${SOLANA_CLI}/solana-release-x86_64-unknown-linux-gnu.tar.bz2" \
34+
| tar -xjC /tmp \
35+
&& mv /tmp/solana-release/bin/* /usr/local/bin/ \
36+
&& rm -rf /tmp/solana-release
37+
38+
# Anchor CLI
39+
RUN cargo install --git https://github.com/coral-xyz/anchor --tag "v${ANCHOR_CLI}" anchor-cli --locked
40+
41+
# Set up Solana key + config for root
42+
RUN solana-keygen new --no-bip39-passphrase --force \
43+
&& solana config set --url localhost
44+
45+
RUN apt-get update && apt-get install -y zsh curl git \
46+
&& sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended \
47+
&& chsh -s /usr/bin/zsh root
5248

5349
WORKDIR /workdir
54-
#be sure to add `/root/.avm/bin` to your PATH to be able to run the installed binaries

.devcontainer/devcontainer.json

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
11
{
2-
"build": { "dockerfile": "Dockerfile" },
3-
}
2+
"name": "Drift Protocol Development",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"platform": "linux/amd64"
6+
},
7+
"workspaceFolder": "/workdir",
8+
"remoteUser": "root",
9+
"mounts": [
10+
"source=${localWorkspaceFolder},target=/workdir,type=bind,consistency=cached",
11+
"source=drift-target,target=/workdir/target,type=volume,consistency=delegated"
12+
],
13+
"postCreateCommand": "yarn config set ignore-package-manager true && echo 'Dev container ready! You can now run: anchor build, anchor test, cargo build, etc.'",
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"rust-lang.rust-analyzer",
18+
"ms-vscode.vscode-json",
19+
"tamasfe.even-better-toml"
20+
],
21+
"settings": {
22+
"rust-analyzer.cachePriming.numThreads": 1,
23+
"rust-analyzer.cargo.buildScripts.enable": true,
24+
"rust-analyzer.procMacro.enable": true,
25+
"rust-analyzer.checkOnSave": true,
26+
"rust-analyzer.check.command": "clippy",
27+
"rust-analyzer.server.extraEnv": {
28+
"NODE_OPTIONS": "--max-old-space-size=4096",
29+
"RUSTUP_TOOLCHAIN": "1.78.0-x86_64-unknown-linux-gnu"
30+
},
31+
"editor.formatOnSave": true,
32+
"git.ignoreLimitWarning": true
33+
}
34+
}
35+
},
36+
"forwardPorts": [
37+
8899,
38+
8900
39+
],
40+
"portsAttributes": {
41+
"8899": {
42+
"label": "Solana Test Validator",
43+
"onAutoForward": "notify"
44+
},
45+
"8900": {
46+
"label": "Solana Test Validator RPC",
47+
"onAutoForward": "notify"
48+
}
49+
},
50+
"containerEnv": {
51+
"ANCHOR_WALLET": "/root/.config/solana/id.json",
52+
"RUST_LOG": "solana_runtime::message_processor::stable_log=debug"
53+
}
54+
}

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,48 @@ cargo test
5555
bash test-scripts/run-anchor-tests.sh
5656
```
5757

58+
# Development (with devcontainer)
59+
60+
We've provided a devcontainer `Dockerfile` to help you spin up a dev environment with the correct versions of Rust, Solana, and Anchor for program development.
61+
62+
Build the container and tag it `drift-dev`:
63+
```
64+
cd .devcontainer && docker build -t drift-dev .
65+
```
66+
67+
Open a shell to the container:
68+
```
69+
# Find the container ID first
70+
docker ps
71+
72+
# Then exec into it
73+
docker exec -it <CONTAINER_ID> /bin/bash
74+
```
75+
76+
Alternatively use an extension provided by your IDE to make use of the dev container. For example on vscode/cursor:
77+
78+
```
79+
1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
80+
2. Type "Dev Containers: Reopen in Container"
81+
3. Select it and wait for the container to build
82+
4. The IDE terminal should be targeting the dev container now
83+
```
84+
85+
Use the dev container as you would a local build environment:
86+
```
87+
# build program
88+
anchor build
89+
90+
# update idl
91+
anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json
92+
93+
# run cargo tests
94+
cargo test
95+
96+
# run typescript tests
97+
bash test-scripts/run-anchor-tests.sh
98+
```
99+
58100
# Bug Bounty
59101

60102
Information about the Bug Bounty can be found [here](./bug-bounty/README.md)

0 commit comments

Comments
 (0)