Skip to content

Commit

Permalink
Wasm extension example.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmrigney committed Dec 14, 2022
1 parent 61c47e2 commit edfa585
Show file tree
Hide file tree
Showing 18 changed files with 29,092 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ui/node_modules
vm/target
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
ui/build
vm/target
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM --platform=$BUILDPLATFORM rust AS wasm-builder
WORKDIR /backend
RUN rustup target add wasm32-wasi
COPY vm/Cargo.toml ./
COPY vm/Cargo.lock ./
COPY vm/ ./
# build the wasm binary
RUN cargo build --target wasm32-wasi --release

FROM --platform=$BUILDPLATFORM node:17.7-alpine3.14 AS client-builder
WORKDIR /ui
# cache packages in layer
COPY ui/package.json /ui/package.json
COPY ui/package-lock.json /ui/package-lock.json
RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci
# install
COPY ui /ui
RUN npm run build

FROM scratch
LABEL org.opencontainers.image.title="Wasm extension" \
org.opencontainers.image.description="My awesome Wasm extension" \
org.opencontainers.image.vendor="Docker Inc." \
com.docker.desktop.extension.api.version="0.3.0" \
com.docker.extension.screenshots="" \
com.docker.extension.detailed-description="" \
com.docker.extension.publisher-url="" \
com.docker.extension.additional-urls="" \
com.docker.extension.changelog=""

COPY --from=wasm-builder /backend/target/wasm32-wasi/release/extension-server.wasm /service.wasm
COPY docker-compose.yaml .
COPY metadata.json .
COPY docker.svg .
COPY --from=client-builder /ui/build ui
EXPOSE 1234
ENTRYPOINT [ "service.wasm" ]
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
IMAGE?=crigneydocker/wasm-extension
TAG?=latest

BUILDER=buildx-multi-arch

INFO_COLOR = \033[0;36m
NO_COLOR = \033[m

build-extension: ## Build service image to be deployed as a desktop extension
docker buildx build --platform=wasi/wasm32 --tag=$(IMAGE):$(TAG) .

install-extension: build-extension ## Install the extension
docker extension install $(IMAGE):$(TAG)

update-extension: build-extension ## Update the extension
docker extension update $(IMAGE):$(TAG)

prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host

push-extension: prepare-buildx ## Build & Upload extension image to hub. Do not push if tag already exists: make push-extension tag=0.1
docker pull $(IMAGE):$(TAG) && echo "Failure: Tag already exists" || docker buildx build --push --builder=$(BUILDER) --platform=wasi/wasm32 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .

help: ## Show this help
@echo Please specify a build target. The choices are:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'

.PHONY: help
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
wasm-extension:
image: ${DESKTOP_PLUGIN_IMAGE}
platform: wasi/wasm32
runtime: io.containerd.wasmedge.v1
ports:
- 1234:1234

22 changes: 22 additions & 0 deletions docker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"icon": "docker.svg",
"vm": {
"composefile": "docker-compose.yaml"
},
"ui": {
"dashboard-tab": {
"title": "My Wasm Extension",
"src": "index.html",
"root": "ui"
}
}
}
1 change: 1 addition & 0 deletions ui/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Electron 17.1.1
1 change: 1 addition & 0 deletions ui/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BROWSER=none
Loading

0 comments on commit edfa585

Please sign in to comment.