diff --git a/README.md b/README.md index 8617f10..20bdea9 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,12 @@ You can read more about the importance of sandboxing, containers vs VMs, and mor - [Quickstart - VSCode and Foundry on a new project, unmounted](#quickstart---vscode-and-foundry-on-a-new-project-unmounted) - [Usage](#usage) - [VSCode](#vscode) + - [Unmounted](#unmounted) - [Mounted](#mounted) - [Using on an existing project](#using-on-an-existing-project) - [Raw Docker](#raw-docker) - [Mounted](#mounted-1) - [Using on an existing project](#using-on-an-existing-project-1) - - [Adding new projects](#adding-new-projects) - - [Adding new tools/Dockerfiles/containers](#adding-new-toolsdockerfilescontainers) -- [License](#license) - [Acknowledgements](#acknowledgements) ## Why are dev containers important? @@ -91,7 +89,7 @@ cd web3-dev-containers ## Quickstart - VSCode and Foundry on a new project, unmounted -Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more detailed instructions. +Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more instructions. > **Note** > `unmounted`: This means that all the code we work with will be destroyed once we stop the container. This is the safest way to work with code. There are times when we want to save our code, you can see those instructions in the `mounted` section in the [Usage](#Usage) section. @@ -157,22 +155,71 @@ This will delete all traces of the code you worked on in that container! ## VSCode -Please see the [Quickstart](#Quickstart---VSCode-and-Foundry-on-a-new-project) for a quick guide on how to use this with VSCode on a new project. +### Unmounted + +Please see the [Quickstart](#Quickstart---VSCode-and-Foundry-on-a-new-project-unmounted) for a quick guide on how to use this with VSCode on a new project. ### Mounted +If you want to persist your code changes back to your host machine, take these steps instead of what you saw in the quickstart: + +1. Open the `foundry/mounted` folder in VSCode +2. Run `Dev Containers: Reopen in Container` from the command palette +3. Work in the `projects` folder - any changes here will be saved to your host machine +4. The container will still protect you from malicious scripts, but be careful what you save back to your machine + +> **Note** +> The code will be saved to your host machine's file structure, so just remember to not run anything from that folder before you're sure it's safe! + ### Using on an existing project +To use these containers with an existing project: + +1. Copy the `.devcontainer` folder to your project (mounted or unmounted): + +```bash +cp -r web3-dev-containers/foundry/MOUNTED_UNMOUNTED/.devcontainer /path/to/your/project/ +``` + +2. Open your project's folder in VSCode + +3. Open in a new dev container + +Run `Dev Containers: Reopen in Container` + ## Raw Docker +For users who are not using VSCode. + ### Mounted +To run on a mounted volume: + +```bash +# Build the container +cd foundry/mounted/.devcontainer +docker build -t foundry-dev . + +# Run with your project mounted +docker run -it -v /path/to/your/project:/workspace/projects foundry-dev +``` + ### Using on an existing project -## Adding new projects +1. Build the container: + +```bash +cd web3-dev-containers/foundry +docker build -t foundry-dev . +``` -## Adding new tools/Dockerfiles/containers +2. Run your project in the container -# License +```bash +docker run -it foundry-dev +cd workspace +git clone your-project-url +``` # Acknowledgements +- [The Red Guild](https://blog.theredguild.org/where-do-you-run-your-code/) diff --git a/moccasin/mounted/.devcontainer/Dockerfile b/moccasin/mounted/.devcontainer/Dockerfile new file mode 100644 index 0000000..1c44cc0 --- /dev/null +++ b/moccasin/mounted/.devcontainer/Dockerfile @@ -0,0 +1,31 @@ +# Base debian build (latest). +FROM mcr.microsoft.com/vscode/devcontainers/base:debian + +# Update packages. +RUN apt-get update + +# Set the default shell to zsh +ENV SHELL=/usr/bin/zsh + +# Running everything under zsh +SHELL ["/usr/bin/zsh", "-c"] + +# Dropping privileges +USER vscode + +# Install rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env + +# Install uv and add to PATH +# See https://docs.astral.sh/uv/guides/integration/docker/ +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +ENV PATH="/home/vscode/.local/bin:$PATH" + +# Add uv to shell configuration +RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc + +# Install tools using uv +RUN uv tool install moccasin + +# Clean up +RUN sudo apt-get autoremove -y && sudo apt-get clean -y \ No newline at end of file diff --git a/moccasin/mounted/.devcontainer/devcontainer.json b/moccasin/mounted/.devcontainer/devcontainer.json new file mode 100644 index 0000000..bf34611 --- /dev/null +++ b/moccasin/mounted/.devcontainer/devcontainer.json @@ -0,0 +1,49 @@ +{ + // Inspired by https://blog.theredguild.org/where-do-you-run-your-code/ + // For format details, see https://aka.ms/devcontainer.json. + "name": "Cyfrin's Vyper & Moccasin DevContainer", + // You can use image or directly use a Dockerfile or Docker Compose file. + // More info: https://containers.dev/guide/dockerfile + // https://github.com/devcontainers/images/tree/main/src/base-alpine + // "image": "mcr.microsoft.com/devcontainers/base:debian", + "build": { + "dockerfile": "Dockerfile" + }, + // Features to add to the dev container. More info: https://containers.dev/features. + "features": {}, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "extensions": [ + "tintinweb.vscode-vyper", + "trailofbits.weaudit", + "ms-python.python" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + } + } + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000], + // Use 'portsAttributes' to set default properties for specific forwarded ports. + // More info: https://containers.dev/implementors/json_reference/#port-attributes + // "portsAttributes": { + // "3000": { + // "label": "Hello Remote World", + // "onAutoForward": "notify" + // } + // }, + // Use 'postCreateCommand' to run commands after the container is created. + // We're using a gist, but you can also reference the raw install-tool from your repo. + // Unless you mount the scripts folder as + "postCreateCommand": "echo Welcome to Cyfrin's dev-container. If you'd like to build your own, you can check out an article The Red Guild have created for you at their blog under https://blog.theredguild.org/where-do-you-run-your-code;zsh" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/moccasin/projects/.gitkeep b/moccasin/mounted/projects/.gitkeep similarity index 100% rename from moccasin/projects/.gitkeep rename to moccasin/mounted/projects/.gitkeep diff --git a/moccasin/unmounted/.devcontainer/Dockerfile b/moccasin/unmounted/.devcontainer/Dockerfile new file mode 100644 index 0000000..1c44cc0 --- /dev/null +++ b/moccasin/unmounted/.devcontainer/Dockerfile @@ -0,0 +1,31 @@ +# Base debian build (latest). +FROM mcr.microsoft.com/vscode/devcontainers/base:debian + +# Update packages. +RUN apt-get update + +# Set the default shell to zsh +ENV SHELL=/usr/bin/zsh + +# Running everything under zsh +SHELL ["/usr/bin/zsh", "-c"] + +# Dropping privileges +USER vscode + +# Install rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env + +# Install uv and add to PATH +# See https://docs.astral.sh/uv/guides/integration/docker/ +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +ENV PATH="/home/vscode/.local/bin:$PATH" + +# Add uv to shell configuration +RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc + +# Install tools using uv +RUN uv tool install moccasin + +# Clean up +RUN sudo apt-get autoremove -y && sudo apt-get clean -y \ No newline at end of file diff --git a/moccasin/unmounted/.devcontainer/devcontainer.json b/moccasin/unmounted/.devcontainer/devcontainer.json new file mode 100644 index 0000000..7ef7fa1 --- /dev/null +++ b/moccasin/unmounted/.devcontainer/devcontainer.json @@ -0,0 +1,51 @@ +{ + // Inspired by https://blog.theredguild.org/where-do-you-run-your-code/ + // For format details, see https://aka.ms/devcontainer.json. + "name": "Cyfrin's Vyper & Moccasin DevContainer", + // You can use image or directly use a Dockerfile or Docker Compose file. + // More info: https://containers.dev/guide/dockerfile + // https://github.com/devcontainers/images/tree/main/src/base-alpine + // "image": "mcr.microsoft.com/devcontainers/base:debian", + "build": { + "dockerfile": "Dockerfile" + }, + "workspaceMount": "type=tmpfs,target=/workspace", + "workspaceFolder": "/workspace", + // Features to add to the dev container. More info: https://containers.dev/features. + "features": {}, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "extensions": [ + "tintinweb.vscode-vyper", + "trailofbits.weaudit", + "ms-python.python" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + } + } + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000], + // Use 'portsAttributes' to set default properties for specific forwarded ports. + // More info: https://containers.dev/implementors/json_reference/#port-attributes + // "portsAttributes": { + // "3000": { + // "label": "Hello Remote World", + // "onAutoForward": "notify" + // } + // }, + // Use 'postCreateCommand' to run commands after the container is created. + // We're using a gist, but you can also reference the raw install-tool from your repo. + // Unless you mount the scripts folder as + "postCreateCommand": "echo Welcome to Cyfrin's dev-container. If you'd like to build your own, you can check out an article The Red Guild have created for you at their blog under https://blog.theredguild.org/where-do-you-run-your-code;zsh" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file