Skip to content

Commit 916112f

Browse files
committed
run as root
1 parent 55b530d commit 916112f

File tree

2 files changed

+43
-73
lines changed

2 files changed

+43
-73
lines changed

.devcontainer/Dockerfile

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,48 @@
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

75
FROM --platform=linux/amd64 rust:1.70.0
86

97
ARG DEBIAN_FRONTEND=noninteractive
10-
118
ARG SOLANA_CLI="1.16.27"
129
ARG ANCHOR_CLI="0.29.0"
1310
ARG NODE_VERSION="20.18.1"
1411

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
7147

7248
WORKDIR /workdir

.devcontainer/devcontainer.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": "Drift Protocol Development",
2+
"name": "Drift Protocol Development (amd64, root)",
33
"build": {
44
"dockerfile": "Dockerfile",
55
"platform": "linux/amd64"
66
},
77
"workspaceFolder": "/workdir",
8-
"remoteUser": "vscode",
8+
"remoteUser": "root",
99
"mounts": [
1010
"source=${localWorkspaceFolder},target=/workdir,type=bind,consistency=cached",
1111
"source=drift-target,target=/workdir/target,type=volume,consistency=delegated"
1212
],
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'",
13+
"postCreateCommand": "echo 'Dev container ready. Run: anchor build / anchor test / cargo build'",
1414
"customizations": {
1515
"vscode": {
1616
"extensions": [
@@ -27,17 +27,11 @@
2727
},
2828
"forwardPorts": [8899, 8900],
2929
"portsAttributes": {
30-
"8899": {
31-
"label": "Solana Test Validator",
32-
"onAutoForward": "notify"
33-
},
34-
"8900": {
35-
"label": "Solana Test Validator RPC",
36-
"onAutoForward": "notify"
37-
}
30+
"8899": { "label": "Solana Test Validator", "onAutoForward": "notify" },
31+
"8900": { "label": "Solana Test Validator RPC", "onAutoForward": "notify" }
3832
},
3933
"containerEnv": {
40-
"ANCHOR_WALLET": "/home/vscode/.config/solana/id.json",
34+
"ANCHOR_WALLET": "/root/.config/solana/id.json",
4135
"RUST_LOG": "solana_runtime::message_processor::stable_log=debug"
4236
}
43-
}
37+
}

0 commit comments

Comments
 (0)