Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build images #15

Merged
merged 5 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
.PHONY: build

build:
cargo build --release
cargo build --release

image-amd64:
docker build -f image/Dockerfile --platform amd64 -t wasm-workers-server:latest-amd64 .

image-arm64:
docker build -f image/Dockerfile --platform arm64 -t wasm-workers-server:latest-arm64 .

push-image-multiarch:
docker buildx build -f image/Dockerfile --platform linux/arm64/v8,linux/amd64 --push -t projects.registry.vmware.com/wasmlabs/containers/wasm-workers-server:latest .

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ curl https://raw.githubusercontent.com/vmware-labs/wasm-workers-server/main/inst
./wws --help
```

### Running in a container

If you don't want to install anything locally you can just run `wws` from the `projects.registry.vmware.com/wasmlabs/containers/wasm-workers-server:latest` container image. All you need to do is:

- map a local folder with handlers to `/app` within the container
- expose port `8080` from the container

Here is how to quickly run a container with an ad-hoc handler from the /tmp/wws-app folder:

```bash
mkdir /tmp/wws-app 2>/dev/null;
echo 'addEventListener("fetch", (e) => { return e.respondWith(new Response("Hello from WWS\n"));});' > /tmp/wws-app/index.js;
docker run --rm -v /tmp/wws-app:/app -p 8080:8080 projects.registry.vmware.com/wasmlabs/containers/wasm-workers-server:latest
```
## Language Support

Wasm Workers Server focuses on simplicity. We want you to run handlers (written in different languages) safely in WebAssembly. For interpreted languages, we add different interpreters:
Expand Down
26 changes: 26 additions & 0 deletions docs/docs/containers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
sidebar_position: 3
---

# Running in a container

For convenience we have published a container image that contains Wasm Workers Server. It is available at `projects.registry.vmware.com/wasmlabs/containers/wasm-workers-server:latest`. Any container that runs it will get the `wws` binary, running and:

- looking for worker handlers in the `/app` folder
- listening on `0.0.0.0:8080` inside the container

The image is based on `debian:bullseye-slim` + the `wws` binary. It includes support for the `linux/amd64` and `linux/arm64/v8` platforms. The image size should be around `~100MiB`
assambar marked this conversation as resolved.
Show resolved Hide resolved

## Running a local container

A typical one-liner to run a local container for development purposes would look like:

```bash
docker run -v /path/to/handlers/on/host:/app -p 8080:8080 \
projects.registry.vmware.com/wasmlabs/containers/wasm-workers-server:latest
```

## Other usages

Wasm Workers Server is stateless as far as the loaded handers are stateless (i.e. when they don't use the [Key / Value store](../features/key-value.md)). This makes the image very useful if you want to setup your own auto-scaling deployment.

2 changes: 1 addition & 1 deletion docs/docs/how-it-works.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
---

# How it works?
Expand Down
31 changes: 31 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build wasm_runtime in release mode


FROM --platform=$TARGETPLATFORM rust:1.64.0-slim as build-wws
ARG WWS_BUILD_DIR=/usr/src/wws
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR $WWS_BUILD_DIR
COPY ./ $WWS_BUILD_DIR/
RUN echo "Running on ${BUILDPLATFORM}, building for ${TARGETPLATFORM}"
RUN set -eux; \
ls -l .; \
case "${TARGETPLATFORM}" in \
linux/amd64) bldArch='x86_64-unknown-linux-gnu' ;; \
linux/arm64) bldArch='aarch64-unknown-linux-gnu' ;; \
*) echo >&2 "unsupported architecture: $BUILDPLATFORM"; exit 1 ;; \
esac; \
rustup target add $bldArch; \
cargo build --release --target=$bldArch; \
mkdir ./build; \
cp ./target/$bldArch/release/wws ./build/wws


FROM --platform=$TARGETPLATFORM debian:bullseye-slim
ARG WWS_BUILD_DIR=/usr/src/wws
RUN mkdir -p /app
RUN mkdir -p /opt
COPY --from=build-wws ${WWS_BUILD_DIR}/build/wws /opt

CMD ["/opt/wws", "/app/", "--host", "0.0.0.0"]