Skip to content

Commit cec4e6d

Browse files
committed
make working devcontainer and dockerfile
1 parent a1719bb commit cec4e6d

File tree

3 files changed

+120
-22
lines changed

3 files changed

+120
-22
lines changed

.devcontainer/Dockerfile

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,67 @@
44
# is released on GitHub.
55
#
66

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

99
ARG DEBIAN_FRONTEND=noninteractive
1010

11-
ARG SOLANA_CLI="1.14.7"
12-
ARG ANCHOR_CLI="0.26.0"
13-
ARG NODE_VERSION="v18.16.0"
11+
ARG SOLANA_CLI="1.16.27"
12+
ARG ANCHOR_CLI="0.29.0"
13+
ARG NODE_VERSION="20.18.x"
1414

15-
ENV HOME="/root"
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"
1628
ENV PATH="${HOME}/.cargo/bin:${PATH}"
1729
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
18-
ENV PATH="${HOME}/.nvm/versions/node/${NODE_VERSION}/bin:${PATH}"
1930

2031
# Install base utilities.
2132
RUN mkdir -p /workdir && mkdir -p /tmp && \
2233
apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
2334
build-essential git curl wget jq pkg-config python3-pip \
2435
libssl-dev libudev-dev
2536

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
37+
# libssl1.1 is not needed for newer versions
2838

2939
# Install rust.
3040
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
3141
sh rustup.sh -y && \
3242
rustup component add rustfmt clippy
3343

3444
# 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 && \
45+
RUN apt-get install -y nodejs npm && \
4146
npm install -g yarn && \
42-
yarn add ts-mocha
47+
npm install -g ts-mocha && \
48+
npm install -g typescript && \
49+
npm install -g mocha
4350

44-
# Install Solana tools.
45-
RUN sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_CLI}/install)"
51+
# Install Solana tools (x86_64 version).
52+
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 && \
53+
mv /tmp/solana-release/bin/* /usr/local/bin/ && \
54+
rm -rf /tmp/solana-release
4655

4756
# 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}
57+
RUN cargo install --git https://github.com/coral-xyz/anchor --tag v${ANCHOR_CLI} anchor-cli --locked
58+
59+
# Switch to the non-root user for the remaining setup
60+
USER $USERNAME
5061

5162
RUN solana-keygen new --no-bip39-passphrase
5263

64+
# Set up Solana config for local development
65+
RUN solana config set --url localhost
66+
67+
# Create necessary directories
68+
RUN mkdir -p $HOME/.config/solana
69+
5370
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: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
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": "vscode",
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": "sudo chown -R vscode:vscode /workdir/target 2>/dev/null || true && echo 'Dev container ready! You can now run: anchor build, anchor test, cargo build, etc.' && echo 'To run tests: bash test-scripts/run-anchor-tests.sh'",
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.cargo.buildScripts.enable": true,
23+
"rust-analyzer.procMacro.enable": true,
24+
"terminal.integrated.defaultProfile.linux": "bash"
25+
}
26+
}
27+
},
28+
"forwardPorts": [8899, 8900],
29+
"portsAttributes": {
30+
"8899": {
31+
"label": "Solana Test Validator",
32+
"onAutoForward": "notify"
33+
},
34+
"8900": {
35+
"label": "Solana Test Validator RPC",
36+
"onAutoForward": "notify"
37+
}
38+
},
39+
"containerEnv": {
40+
"ANCHOR_WALLET": "/home/vscode/.config/solana/id.json",
41+
"RUST_LOG": "solana_runtime::message_processor::stable_log=debug"
42+
}
43+
}

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)