diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 2d4688614c..39d1ca340f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,54 +1,49 @@ # -# Docker image to generate deterministic, verifiable builds of Anchor programs. -# This must be run *after* a given ANCHOR_CLI version is published and a git tag -# is released on GitHub. +# Drift Protocol Dev Container # -FROM rust:1.75 +FROM --platform=linux/amd64 rust:1.70.0 ARG DEBIAN_FRONTEND=noninteractive - -ARG SOLANA_CLI="1.14.7" -ARG ANCHOR_CLI="0.26.0" -ARG NODE_VERSION="v18.16.0" +ARG SOLANA_CLI="1.16.27" +ARG ANCHOR_CLI="0.29.0" +ARG NODE_VERSION="20.18.1" 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}" - -# Install base utilities. -RUN mkdir -p /workdir && mkdir -p /tmp && \ - 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 - -RUN wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb -RUN dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb - -# Install rust. -RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \ - sh rustup.sh -y && \ - rustup component add rustfmt clippy - -# Install node / npm / yarn. -RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash -ENV NVM_DIR="${HOME}/.nvm" -RUN . $NVM_DIR/nvm.sh && \ - nvm install ${NODE_VERSION} && \ - nvm use ${NODE_VERSION} && \ - nvm alias default node && \ - npm install -g yarn && \ - yarn add ts-mocha - -# Install Solana tools. -RUN sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_CLI}/install)" - -# Install anchor. -RUN cargo install --git https://github.com/coral-xyz/anchor avm --locked --force -RUN avm install ${ANCHOR_CLI} && avm use ${ANCHOR_CLI} - -RUN solana-keygen new --no-bip39-passphrase +ENV PATH="/usr/local/cargo/bin:${PATH}" +ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}" + +RUN mkdir -p /workdir /tmp && \ + apt-get update -qq && apt-get upgrade -qq && apt-get install -y --no-install-recommends \ + build-essential git curl wget jq pkg-config python3-pip xz-utils ca-certificates \ + libssl-dev libudev-dev bash && \ + rm -rf /var/lib/apt/lists/* + +RUN rustup install 1.78.0 \ + && rustup component add rustfmt clippy --toolchain 1.78.0 + +RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -o /tmp/node.tar.xz \ + && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \ + && rm /tmp/node.tar.xz \ + && corepack enable \ + && npm install -g ts-mocha typescript mocha \ + && node -v && npm -v && yarn -v + +# Solana CLI (x86_64 build) +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 \ + && mv /tmp/solana-release/bin/* /usr/local/bin/ \ + && rm -rf /tmp/solana-release + +# Anchor CLI +RUN cargo install --git https://github.com/coral-xyz/anchor --tag "v${ANCHOR_CLI}" anchor-cli --locked + +# Set up Solana key + config for root +RUN solana-keygen new --no-bip39-passphrase --force \ + && solana config set --url localhost + +RUN apt-get update && apt-get install -y zsh curl git \ + && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended \ + && chsh -s /usr/bin/zsh root WORKDIR /workdir -#be sure to add `/root/.avm/bin` to your PATH to be able to run the installed binaries diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d5aa4e718b..3228a43367 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,3 +1,54 @@ { - "build": { "dockerfile": "Dockerfile" }, - } \ No newline at end of file + "name": "Drift Protocol Development", + "build": { + "dockerfile": "Dockerfile", + "platform": "linux/amd64" + }, + "workspaceFolder": "/workdir", + "remoteUser": "root", + "mounts": [ + "source=${localWorkspaceFolder},target=/workdir,type=bind,consistency=cached", + "source=drift-target,target=/workdir/target,type=volume,consistency=delegated" + ], + "postCreateCommand": "yarn config set ignore-package-manager true && echo 'Dev container ready! You can now run: anchor build, anchor test, cargo build, etc.'", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer", + "ms-vscode.vscode-json", + "tamasfe.even-better-toml" + ], + "settings": { + "rust-analyzer.cachePriming.numThreads": 1, + "rust-analyzer.cargo.buildScripts.enable": true, + "rust-analyzer.procMacro.enable": true, + "rust-analyzer.checkOnSave": true, + "rust-analyzer.check.command": "clippy", + "rust-analyzer.server.extraEnv": { + "NODE_OPTIONS": "--max-old-space-size=4096", + "RUSTUP_TOOLCHAIN": "1.78.0-x86_64-unknown-linux-gnu" + }, + "editor.formatOnSave": true, + "git.ignoreLimitWarning": true + } + } + }, + "forwardPorts": [ + 8899, + 8900 + ], + "portsAttributes": { + "8899": { + "label": "Solana Test Validator", + "onAutoForward": "notify" + }, + "8900": { + "label": "Solana Test Validator RPC", + "onAutoForward": "notify" + } + }, + "containerEnv": { + "ANCHOR_WALLET": "/root/.config/solana/id.json", + "RUST_LOG": "solana_runtime::message_processor::stable_log=debug" + } +} \ No newline at end of file diff --git a/README.md b/README.md index 28e340d853..0bb99c9b0a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,48 @@ cargo test bash test-scripts/run-anchor-tests.sh ``` +# Development (with devcontainer) + +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. + +Build the container and tag it `drift-dev`: +``` +cd .devcontainer && docker build -t drift-dev . +``` + +Open a shell to the container: +``` +# Find the container ID first +docker ps + +# Then exec into it +docker exec -it /bin/bash +``` + +Alternatively use an extension provided by your IDE to make use of the dev container. For example on vscode/cursor: + +``` +1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac) +2. Type "Dev Containers: Reopen in Container" +3. Select it and wait for the container to build +4. The IDE terminal should be targeting the dev container now +``` + +Use the dev container as you would a local build environment: +``` +# build program +anchor build + +# update idl +anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json + +# run cargo tests +cargo test + +# run typescript tests +bash test-scripts/run-anchor-tests.sh +``` + # Bug Bounty Information about the Bug Bounty can be found [here](./bug-bounty/README.md)