Skip to content

Commit 2420564

Browse files
committed
update
1 parent 84dd838 commit 2420564

6 files changed

Lines changed: 217 additions & 8 deletions

File tree

README.md

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ You can read more about the importance of sandboxing, containers vs VMs, and mor
2121
- [Quickstart - VSCode and Foundry on a new project, unmounted](#quickstart---vscode-and-foundry-on-a-new-project-unmounted)
2222
- [Usage](#usage)
2323
- [VSCode](#vscode)
24+
- [Unmounted](#unmounted)
2425
- [Mounted](#mounted)
2526
- [Using on an existing project](#using-on-an-existing-project)
2627
- [Raw Docker](#raw-docker)
2728
- [Mounted](#mounted-1)
2829
- [Using on an existing project](#using-on-an-existing-project-1)
29-
- [Adding new projects](#adding-new-projects)
30-
- [Adding new tools/Dockerfiles/containers](#adding-new-toolsdockerfilescontainers)
31-
- [License](#license)
3230
- [Acknowledgements](#acknowledgements)
3331

3432
## Why are dev containers important?
@@ -91,7 +89,7 @@ cd web3-dev-containers
9189

9290
## Quickstart - VSCode and Foundry on a new project, unmounted
9391

94-
Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more detailed instructions.
92+
Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more instructions.
9593

9694
> **Note**
9795
> `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!
157155

158156
## VSCode
159157

160-
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.
158+
### Unmounted
159+
160+
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.
161161

162162
### Mounted
163163

164+
If you want to persist your code changes back to your host machine, take these steps instead of what you saw in the quickstart:
165+
166+
1. Open the `foundry/mounted` folder in VSCode
167+
2. Run `Dev Containers: Reopen in Container` from the command palette
168+
3. Work in the `projects` folder - any changes here will be saved to your host machine
169+
4. The container will still protect you from malicious scripts, but be careful what you save back to your machine
170+
171+
> **Note**
172+
> 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!
173+
164174
### Using on an existing project
165175

176+
To use these containers with an existing project:
177+
178+
1. Copy the `.devcontainer` folder to your project (mounted or unmounted):
179+
180+
```bash
181+
cp -r web3-dev-containers/foundry/MOUNTED_UNMOUNTED/.devcontainer /path/to/your/project/
182+
```
183+
184+
2. Open your project's folder in VSCode
185+
186+
3. Open in a new dev container
187+
188+
Run `Dev Containers: Reopen in Container`
189+
166190
## Raw Docker
167191

192+
For users who are not using VSCode.
193+
168194
### Mounted
169195

196+
To run on a mounted volume:
197+
198+
```bash
199+
# Build the container
200+
cd foundry/mounted/.devcontainer
201+
docker build -t foundry-dev .
202+
203+
# Run with your project mounted
204+
docker run -it -v /path/to/your/project:/workspace/projects foundry-dev
205+
```
206+
170207
### Using on an existing project
171208

172-
## Adding new projects
209+
1. Build the container:
210+
211+
```bash
212+
cd web3-dev-containers/foundry
213+
docker build -t foundry-dev .
214+
```
173215

174-
## Adding new tools/Dockerfiles/containers
216+
2. Run your project in the container
175217

176-
# License
218+
```bash
219+
docker run -it foundry-dev
220+
cd workspace
221+
git clone your-project-url
222+
```
177223

178224
# Acknowledgements
225+
- [The Red Guild](https://blog.theredguild.org/where-do-you-run-your-code/)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Base debian build (latest).
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
3+
4+
# Update packages.
5+
RUN apt-get update
6+
7+
# Set the default shell to zsh
8+
ENV SHELL=/usr/bin/zsh
9+
10+
# Running everything under zsh
11+
SHELL ["/usr/bin/zsh", "-c"]
12+
13+
# Dropping privileges
14+
USER vscode
15+
16+
# Install rust
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env
18+
19+
# Install uv and add to PATH
20+
# See https://docs.astral.sh/uv/guides/integration/docker/
21+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
22+
ENV PATH="/home/vscode/.local/bin:$PATH"
23+
24+
# Add uv to shell configuration
25+
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc
26+
27+
# Install tools using uv
28+
RUN uv tool install moccasin
29+
30+
# Clean up
31+
RUN sudo apt-get autoremove -y && sudo apt-get clean -y
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
// Inspired by https://blog.theredguild.org/where-do-you-run-your-code/
3+
// For format details, see https://aka.ms/devcontainer.json.
4+
"name": "Cyfrin's Vyper & Moccasin DevContainer",
5+
// You can use image or directly use a Dockerfile or Docker Compose file.
6+
// More info: https://containers.dev/guide/dockerfile
7+
// https://github.com/devcontainers/images/tree/main/src/base-alpine
8+
// "image": "mcr.microsoft.com/devcontainers/base:debian",
9+
"build": {
10+
"dockerfile": "Dockerfile"
11+
},
12+
// Features to add to the dev container. More info: https://containers.dev/features.
13+
"features": {},
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
"extensions": [
19+
"tintinweb.vscode-vyper",
20+
"trailofbits.weaudit",
21+
"ms-python.python"
22+
],
23+
"settings": {
24+
"terminal.integrated.defaultProfile.linux": "zsh",
25+
"terminal.integrated.profiles.linux": {
26+
"zsh": {
27+
"path": "/usr/bin/zsh"
28+
}
29+
}
30+
}
31+
}
32+
},
33+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
34+
// "forwardPorts": [3000],
35+
// Use 'portsAttributes' to set default properties for specific forwarded ports.
36+
// More info: https://containers.dev/implementors/json_reference/#port-attributes
37+
// "portsAttributes": {
38+
// "3000": {
39+
// "label": "Hello Remote World",
40+
// "onAutoForward": "notify"
41+
// }
42+
// },
43+
// Use 'postCreateCommand' to run commands after the container is created.
44+
// We're using a gist, but you can also reference the raw install-tool from your repo.
45+
// Unless you mount the scripts folder as
46+
"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"
47+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
48+
// "remoteUser": "root"
49+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Base debian build (latest).
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
3+
4+
# Update packages.
5+
RUN apt-get update
6+
7+
# Set the default shell to zsh
8+
ENV SHELL=/usr/bin/zsh
9+
10+
# Running everything under zsh
11+
SHELL ["/usr/bin/zsh", "-c"]
12+
13+
# Dropping privileges
14+
USER vscode
15+
16+
# Install rust
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env
18+
19+
# Install uv and add to PATH
20+
# See https://docs.astral.sh/uv/guides/integration/docker/
21+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
22+
ENV PATH="/home/vscode/.local/bin:$PATH"
23+
24+
# Add uv to shell configuration
25+
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc
26+
27+
# Install tools using uv
28+
RUN uv tool install moccasin
29+
30+
# Clean up
31+
RUN sudo apt-get autoremove -y && sudo apt-get clean -y
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
// Inspired by https://blog.theredguild.org/where-do-you-run-your-code/
3+
// For format details, see https://aka.ms/devcontainer.json.
4+
"name": "Cyfrin's Vyper & Moccasin DevContainer",
5+
// You can use image or directly use a Dockerfile or Docker Compose file.
6+
// More info: https://containers.dev/guide/dockerfile
7+
// https://github.com/devcontainers/images/tree/main/src/base-alpine
8+
// "image": "mcr.microsoft.com/devcontainers/base:debian",
9+
"build": {
10+
"dockerfile": "Dockerfile"
11+
},
12+
"workspaceMount": "type=tmpfs,target=/workspace",
13+
"workspaceFolder": "/workspace",
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
"features": {},
16+
// Configure tool-specific properties.
17+
"customizations": {
18+
// Configure properties specific to VS Code.
19+
"vscode": {
20+
"extensions": [
21+
"tintinweb.vscode-vyper",
22+
"trailofbits.weaudit",
23+
"ms-python.python"
24+
],
25+
"settings": {
26+
"terminal.integrated.defaultProfile.linux": "zsh",
27+
"terminal.integrated.profiles.linux": {
28+
"zsh": {
29+
"path": "/usr/bin/zsh"
30+
}
31+
}
32+
}
33+
}
34+
},
35+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
36+
// "forwardPorts": [3000],
37+
// Use 'portsAttributes' to set default properties for specific forwarded ports.
38+
// More info: https://containers.dev/implementors/json_reference/#port-attributes
39+
// "portsAttributes": {
40+
// "3000": {
41+
// "label": "Hello Remote World",
42+
// "onAutoForward": "notify"
43+
// }
44+
// },
45+
// Use 'postCreateCommand' to run commands after the container is created.
46+
// We're using a gist, but you can also reference the raw install-tool from your repo.
47+
// Unless you mount the scripts folder as
48+
"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"
49+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
50+
// "remoteUser": "root"
51+
}

0 commit comments

Comments
 (0)