Skip to content

Commit

Permalink
feat(dev): setup devcontainer (windmill-labs#549)
Browse files Browse the repository at this point in the history
Co-authored-by: ex0ns <[email protected]>
  • Loading branch information
ex0ns and ex0ns authored Sep 19, 2022
1 parent dfe473d commit b78f2d1
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 8 deletions.
42 changes: 42 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM python:3.10-slim-bullseye as nsjail

WORKDIR /nsjail

RUN apt-get -y update \
&& apt-get install -y \
bison \
flex \
g++ \
gcc \
git \
libprotobuf-dev \
libnl-route-3-dev \
make \
pkg-config \
protobuf-compiler \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

RUN git clone -b master --single-branch https://github.com/google/nsjail.git . \
&& git checkout dccf911fd2659e7b08ce9507c25b2b38ec2c5800
RUN make

FROM mcr.microsoft.com/vscode/devcontainers/rust:bullseye as rust-deps

RUN cargo install sqlx-cli --no-default-features --features native-tls,postgres
RUN cargo install deno --locked

FROM mcr.microsoft.com/vscode/devcontainers/rust:bullseye

RUN apt update \
&& apt-get install -y \
lld \
python3 \
libprotobuf-dev \
libnl-route-3-dev \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

USER vscode

COPY --from=rust-deps /usr/local/cargo/bin/sqlx /usr/local/cargo/bin/sqlx
COPY --from=rust-deps /usr/local/cargo/bin/deno /usr/local/cargo/bin/deno
COPY --from=nsjail /nsjail/nsjail /bin/nsjail
25 changes: 25 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.7'
services:
windmill:
build:
context: .
dockerfile: .devcontainer/Dockerfile
# image: mcr.microsoft.com/vscode/devcontainers/rust:bullseye
environment:
- DENO_PATH=/usr/local/cargo/bin/deno
- PYTHON_PATH=/usr/bin/python3
- NSJAIL_PATH=/bin/nsjail
volumes:
- .:/workspace:cached
- ~/.ssh:/home/vscode/.ssh:ro

command: /bin/sh -c "while sleep 1000; do :; done"


front:
image: mcr.microsoft.com/vscode/devcontainers/typescript-node:16
volumes:
- .:/workspace:cached
- ~/.ssh:/home/node/.ssh:ro

command: /bin/sh -c "while sleep 1000; do :; done"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target/
.DS_Store
nohup.out
local/
frontend/src/routes/test.svelte
CaddyfileRemoteMalo
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ with hot-code reloading.

1. Install [caddy](https://caddyserver.com)
2. Go to `frontend/`:
1. `npm run install`, `npm run generate-backend-client` then `npm run dev`
1. `npm install`, `npm run generate-backend-client` then `npm run dev`
2. In another shell `sudo caddy run --config CaddyfileRemote`
3. Et voilà, windmill should be available at `http://localhost/`

Expand All @@ -248,17 +248,20 @@ running options.

1. Create a Postgres Database for Windmill and create an admin role inside your
Postgres setup.
The easiest way to get a working postgres is running `cargo install sqlx-cli && sqlx migrate run`.
This will also avoid compile time issue with sqlx's `query!` macro
2. Install [nsjail](https://github.com/google/nsjail) and have it accessible in
your PATH
3. Install deno and python3, have the bins at `/usr/bin/deno` and
`/usr/local/bin/python3`
4. Install [caddy](https://caddyserver.com)
5. Install the [lld linker](https://lld.llvm.org/)
6. Go to `backend/`:
6. Go to `frontend/`:
1. `npm install`, `npm run generate-backend-client` then `npm run dev`
2. In another shell `npm run build` otherwise the backend will not find the `frontend/build` folder and will crash
3. In another shell `sudo caddy run --config Caddyfile`
7. Go to `backend/`:
`DATABASE_URL=<DATABASE_URL_TO_YOUR_WINDMILL_DB> RUST_LOG=info cargo run`
7. Go to `frontend/`:
1. `npm run install`, `npm run generate-backend-client` then `npm run dev`
2. In another shell `sudo caddy run --config Caddyfile`
8. Et voilà, windmill should be available at `http://localhost/`

## Contributors
Expand Down
27 changes: 27 additions & 0 deletions backend/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Backend Container",
"dockerComposeFile": [
"../docker-compose.yml",
"../.devcontainer/docker-compose.yml"
],
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"yzhang.markdown-all-in-one"
]
}
},
"service": "windmill",
"workspaceFolder": "/workspace",
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8000
],
// "postCreateCommand": "sudo apt-get update && sudo apt-get install -y lld python3 && cargo install sqlx-cli --no-default-features --features native-tls,postgres && (cd backend && sqlx migrate run) && cargo install deno --locked && rustup toolchain install nightly-2022-05-23 -c rust-src -c rustc-dev -c llvm-tools-preview",
"postCreateCommand": "cd backend && sqlx migrate run",
"remoteUser": "vscode"
}
25 changes: 25 additions & 0 deletions frontend/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Frontend container",
"dockerComposeFile": [
"../docker-compose.yml",
"../.devcontainer/docker-compose.yml"
],
"customizations": {
"vscode": {
"extensions": []
}
},
"service": "front",
"workspaceFolder": "/workspace",
"forwardPorts": [
8080
],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
"postCreateCommand": "cd frontend && npm install && npm run generate-backend-client && wget https://github.com/caddyserver/caddy/releases/download/v2.6.0-beta.3/caddy_2.6.0-beta.3_linux_amd64.deb -O /tmp/caddy.deb && sudo dpkg -i /tmp/caddy.deb && rm /tmp/caddy.deb",
"postStartCommand": "nohup bash -c 'cd frontend && npm run dev &' && nohup bash -c 'caddy run --config frontend/CaddyfileDev &'",
"remoteUser": "node"
}
6 changes: 3 additions & 3 deletions frontend/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
auto_https off
auto_https off
}

:80 {
bind {$ADDRESS}
reverse_proxy /api/* http://localhost:8000
reverse_proxy /* http://localhost:3000
reverse_proxy /ws/* http://localhost:3001 {
lb_policy header "Authorization"
}

}
}
12 changes: 12 additions & 0 deletions frontend/CaddyfileDev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
auto_https off
}

:8080 {
bind {$ADDRESS}
reverse_proxy /api/* http://windmill:8000
reverse_proxy /* http://localhost:3000
reverse_proxy /ws/* http://lsp:3001 {
lb_policy header "Authorization"
}
}

0 comments on commit b78f2d1

Please sign in to comment.