Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Jan 8, 2025
1 parent 84dd838 commit 2420564
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 8 deletions.
63 changes: 55 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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/)
31 changes: 31 additions & 0 deletions moccasin/mounted/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions moccasin/mounted/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
File renamed without changes.
31 changes: 31 additions & 0 deletions moccasin/unmounted/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions moccasin/unmounted/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 2420564

Please sign in to comment.