Skip to content

Commit 7a970af

Browse files
pioveresjml
andauthored
Add a Dockerfile (#6)
* emcc using custom cache directory for permissions reasons * ignoring a build artifact * Dockerized! * little addition to readme * why is this in the repo?? * keep track of the validator compile product * this cache is temporary * json cleanup and no longer serving from devbox * now passing build artifacts to new image for serving * no longer using cache directory in repo * updated to match new docker build process * trimming down the devbox configuration * Dockerfile with multiple targets for flexibility * setting emscripten cache to writeable local directory - emscripten and nix don't play nice together; this seems to be a/the common workaround NixOS/nixpkgs#139943 * only installing rust stuff if necessary * simpler checks --------- Co-authored-by: Shane Liesegang <[email protected]>
1 parent 48fa483 commit 7a970af

File tree

6 files changed

+827
-3
lines changed

6 files changed

+827
-3
lines changed

β€Ž.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/.vscode
44
/.envrc
5+
/.emscripten_cache
56
/node_modules
67

78

β€ŽDockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM jetpackio/devbox:latest AS base
2+
WORKDIR /code
3+
USER root:root
4+
RUN mkdir -p /code && chown ${DEVBOX_USER}:${DEVBOX_USER} /code
5+
USER ${DEVBOX_USER}:${DEVBOX_USER}
6+
7+
FROM base as dev
8+
CMD ["devbox", "shell"]
9+
10+
FROM base as build
11+
WORKDIR /code
12+
COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} . .
13+
RUN devbox run build
14+
15+
FROM caddy:2-alpine as serve
16+
COPY --from=build /code/frontend/build/ /usr/share/caddy/

β€ŽREADME.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,47 @@ The [documentation can also be useful](./docs/), or maybe just [the development
1414

1515
It's a big ole monorepo. Sorry about that; it's what happens when a proof-of-concept just grows organically. I presumptively registered a [wasmbots org on GitHub](https://github.com/wasmbots) just in case this becomes A Thingβ„’ in which case I'll split things out more productively.
1616

17-
Prereqs on macOS; modify this appropriately if you're using something else:
17+
18+
### Devbox
19+
You can always build and run with [devbox](https://www.jetify.com/devbox). ([Installation instructions are here.](https://www.jetify.com/docs/devbox/installing_devbox/))
20+
21+
Run `devbox shell` to be in a usable environment where you can run
22+
23+
24+
### Docker
25+
The [Dockerfile](./Dockerfile) just pipes everything through devbox, but makes it a little more turnkey, especially if you're already a Docker user.
26+
27+
```sh
28+
# produces a container with a built frontend,
29+
# including example bots, served with Caddy
30+
docker build -t wasmbots .
31+
32+
# to actually get it serving:
33+
docker run -d -p 8080:80 wasmbots
34+
# Then look for it in your favorite browser at:
35+
# `http://localhost:8080`
36+
# (change out the port number to whatever you want)
1837
```
19-
brew install deno wabt rust zig emscripten node go tinygo-org/tools/tinygo
38+
39+
```sh
40+
# this will drop you into a shell within the container
41+
# where all the tools are installed and paths are set
42+
# and everything.
43+
docker build --target dev -t wasmbots-dev .
44+
docker run -it -v $PWD:/code wasmbots-dev
45+
```
46+
47+
48+
### Manual Installation
49+
If you don't want to install a whole other package manager, here's what I (used to) use to get up and running with [Homebrew](https://brew.sh/) on macOS. Modify appropriately if you're using something else.
50+
51+
52+
```sh
53+
brew install deno node wabt emscripten rust zig go tinygo-org/tools/tinygo
2054
```
2155

22-
At the moment you can verify everything is working as expected by running:
56+
### Simple Checks
57+
Regardless of how you get your dev environment running, you can verify everything is working as expected by running:
2358

2459
```
2560
./scripts/_build_wasms.sh

β€Ždevbox.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.7/.schema/devbox.schema.json",
3+
"packages": [
4+
"rsync@latest",
5+
"deno@latest",
6+
"gnumake@latest",
7+
"nodejs@latest",
8+
"wabt@latest",
9+
"binaryen@latest",
10+
"llvm@latest",
11+
"emscripten@latest",
12+
"rustup@latest",
13+
"libiconv@latest",
14+
"zig@latest",
15+
"go@latest",
16+
"tinygo@latest"
17+
],
18+
"env": {
19+
"EM_CACHE": "$DEVBOX_PROJECT_ROOT/.emscripten_cache"
20+
},
21+
"shell": {
22+
"init_hook": [
23+
"bash -c 'if [ ! -d $RUSTUP_HOME/toolchains/stable* ]; then rustup default stable; fi'",
24+
"bash -c 'if [ ! -d $RUSTUP_HOME/toolchains/stable*/lib/rustlib/wasm32-unknown-unknown ]; then rustup target add wasm32-unknown-unknown; fi'",
25+
"echo '\nπŸ€– WasmBots devbox environment loaded!'"
26+
],
27+
"scripts": {
28+
"build": [
29+
"cd validator && make install && cd ..",
30+
"/bin/bash scripts/_build_wasms.sh",
31+
"/bin/bash scripts/_validate_wasms.sh",
32+
"cd frontend && npm install && cd ..",
33+
"cd frontend && WASMBOTS_BASE=\"\" npm run build"
34+
]
35+
}
36+
}
37+
}

0 commit comments

Comments
Β (0)