Skip to content
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
68 changes: 47 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ concurrency:
jobs:
check:
name: Check, test and build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: npm
- run: npm ci
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The JDK scripts/fetch-java.mjs builds Java's runtime files from (~210 MB),
# and the NuGet packages scripts/fetch-csharp.mjs builds C#'s from.
path: |
node_modules/.cache/opcode-java
node_modules/.cache/opcode-csharp
key: toolchains-${{ hashFiles('scripts/fetch-java.mjs', 'scripts/fetch-csharp.mjs') }}
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The Wasmer packages the terminals run (scripts/wasmer-packages.mjs, ~255 MB).
path: public/wasmer
Expand All @@ -43,31 +45,33 @@ jobs:
e2e:
name: End-to-end (Chromium)
needs: check
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: npm
- run: npm ci
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The JDK scripts/fetch-java.mjs builds Java's runtime files from (~210 MB),
# and the NuGet packages scripts/fetch-csharp.mjs builds C#'s from.
path: |
node_modules/.cache/opcode-java
node_modules/.cache/opcode-csharp
key: toolchains-${{ hashFiles('scripts/fetch-java.mjs', 'scripts/fetch-csharp.mjs') }}
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The Wasmer packages the terminals run (scripts/wasmer-packages.mjs, ~255 MB).
path: public/wasmer
key: wasmer-packages-${{ hashFiles('wasmer-packages.lock.json') }}
- run: npx playwright install --with-deps chromium
- run: npm run test:e2e
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: failure()
with:
name: playwright-results
Expand All @@ -78,15 +82,14 @@ jobs:
name: Docker image
# Only a main whose tests pass is published as :latest, which compose.yaml pulls.
needs: [check, e2e]
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
packages: write # to publish it, from main
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
load: true
Expand All @@ -102,13 +105,36 @@ jobs:
curl -sfI -H 'Accept-Encoding: br' "http://localhost:8080/assets/$llvm" | grep -i '^content-encoding: br'
- if: failure()
run: docker logs opcode
# What's on main is published as ghcr.io/<owner>/<repository>:latest
# (and :sha-<commit>), which compose.yaml runs.
# The image the publish job pushes, tested above (only from main).
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: docker save opcode:ci -o opcode.tar
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: docker-image
path: opcode.tar
retention-days: 1

publish:
# What's on main is published as ghcr.io/<owner>/<repository>:latest
# (and :sha-<commit>), which compose.yaml runs. A job of its own, so the
# token that can write packages never reaches the build or its actions.
name: Publish the Docker image
needs: [check, e2e, docker]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
packages: write
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: docker-image
- name: Publish to GitHub's container registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker load -i opcode.tar
image=ghcr.io/${GITHUB_REPOSITORY,,}
echo "$TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
for tag in latest "sha-${GITHUB_SHA::7}"; do
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ concurrency:
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: npm
- run: npm ci
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The JDK scripts/fetch-java.mjs builds Java's runtime files from (~210 MB),
# and the NuGet packages scripts/fetch-csharp.mjs builds C#'s from.
path: |
node_modules/.cache/opcode-java
node_modules/.cache/opcode-csharp
key: toolchains-${{ hashFiles('scripts/fetch-java.mjs', 'scripts/fetch-csharp.mjs') }}
- uses: actions/cache@v4
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# The Wasmer packages the terminals run (scripts/wasmer-packages.mjs, ~255 MB).
path: public/wasmer
Expand All @@ -47,15 +49,15 @@ jobs:
env:
# A Cloudflare Worker: deploy/preview-host.wrangler.toml.
VITE_PREVIEW_HOST: https://preview.opcode-dev.com/
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
- uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: dist

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
permissions:
pages: write
id-token: write
Expand All @@ -64,4 +66,4 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker/dockerfile:1
# syntax=docker/dockerfile:1@sha256:572cebbc2b15e6f84c077742952674889cb63cd5e9b80abdffcbe587b6f19183
#
# Opcode, ready to deploy: the app, its web preview host and an optional
# internet relay, served by one small Node server (scripts/server.mjs).
Expand All @@ -13,7 +13,12 @@
# The build. The toolchains `npm run build` downloads (pinned and checksummed:
# Rust, a JDK for Java, NuGet packages for C#, the Wasmer packages) are cached
# between builds.
FROM node:22-bookworm-slim AS build
#
# The base images (and the syntax line above) are pinned by digest, so a
# build uses exactly what was tested. To update one, take the digest from
# `docker buildx imagetools inspect node:22-bookworm-slim` (or node:22-alpine,
# docker/dockerfile:1).
FROM node:22-bookworm-slim@sha256:e9f565d32859f0cbfb52125eafe8be39390f24dac302dc3cdf566e8ba3ab21ee AS build
WORKDIR /opcode
# Stop if a toolchain can't be downloaded, rather than build without it.
ENV CI=1
Expand All @@ -28,7 +33,7 @@ RUN --mount=type=cache,target=/opcode/node_modules/.cache \
&& node scripts/precompress.mjs dist dist-compressed

# What runs: Node, the server (whose relay needs the ws package) and the build.
FROM node:22-alpine
FROM node:22-alpine@sha256:1314fb30ec37592d5845e5a160d522c0e680972aa534549940b8d73bde88481a
LABEL org.opencontainers.image.title="Opcode" \
org.opencontainers.image.description="A browser IDE with a real terminal, running on WebAssembly" \
org.opencontainers.image.source="https://github.com/tks98/opcode" \
Expand Down
7 changes: 6 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
# OPCODE_DOMAIN=opcode.example.com docker compose up -d
#
# It runs the image published from this repository's main branch
# (`docker compose pull` updates it). To run your own build instead:
# (`docker compose pull` updates it). To stay on one tested build instead,
# use its :sha-<commit> tag (each push to main publishes one next to
# :latest), or pin a digest: ghcr.io/tks98/opcode@sha256:... To run your own
# build instead:
# `docker build -t ghcr.io/tks98/opcode .` first.
#
# Add OPCODE_RELAY=on to give terminals and Linux machines internet access
Expand All @@ -20,6 +23,8 @@ services:
restart: unless-stopped
environment:
OPCODE_PREVIEW_HOST: https://preview.${OPCODE_DOMAIN:?set OPCODE_DOMAIN to your domain}/
# Only the site's own pages may embed its preview host.
OPCODE_APP_ORIGINS: https://${OPCODE_DOMAIN}
OPCODE_RELAY: ${OPCODE_RELAY:-off}
OPCODE_RELAY_ARGS: ${OPCODE_RELAY_ARGS:-}

Expand Down
3 changes: 2 additions & 1 deletion deploy/preview-host.wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# opcode-dev.com's web preview host: a Cloudflare Worker on its own domain
# (see docs/deploying.md, "Web preview host"). Deploy it with
# npm run build:preview-host && npx wrangler deploy -c deploy/preview-host.wrangler.toml
# OPCODE_APP_ORIGINS=https://opcode-dev.com npm run build:preview-host && npx wrangler@4.158.0 deploy -c deploy/preview-host.wrangler.toml
# (OPCODE_APP_ORIGINS: only the app's own pages may then use the host)
# and again after updating @wasmer/sdk, whose files it serves. For your own
# site, change the name and the domain.
name = "opcode-preview"
Expand Down
8 changes: 6 additions & 2 deletions docs/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The image is configured with environment variables (`docker run -e`, or `environ
| `OPCODE_RELAY` | `off` | `on` gives terminals and Linux machines internet access through a relay on this server, at `/wisp/` (read [Internet relay](deploying.md#internet-relay) first). A `wss://` address uses that relay instead. With `off`, users can still pick a relay in the *Internet* settings. |
| `OPCODE_RELAY_ARGS` | | The built-in relay's options, as `scripts/wisp-server.mjs` takes them: `--max-streams 32 --via-proxy http://proxy:3128` |
| `OPCODE_RELAY_ORIGINS` | | Other sites whose pages may use the built-in relay (comma-separated). Pages of this site always may. |
| `OPCODE_APP_ORIGINS` | | The site's own address (`https://opcode.example.com`; comma-separate several). Only its pages may then embed the preview host served here. `compose.yaml` sets it. |
| `OPCODE_TRUST_PROXY` | `off` | `on` reads the host name from `X-Forwarded-Host`. Only for a proxy that sets that header itself and replaces any the client sent; Caddy, as in `compose.yaml`, passes `Host` on and doesn't need it. |
| `OPCODE_PREVIEW_HOST` | Wasmer's host | Serve the [web preview host](deploying.md#web-preview-host) here, to requests for that address: `https://preview.example.com/`, or `https://*.preview.example.com/` for one address per server (needs wildcard DNS and a wildcard certificate, which `compose.yaml`'s Caddy can't get by itself). Set it: Wasmer's host doesn't work at the moment (see [Web preview host](deploying.md#web-preview-host)). `compose.yaml` sets it to `preview.` your domain. |

Everything on one computer, with an address for each preview (Chrome and Firefox resolve every `*.localhost` name without DNS):
Expand Down Expand Up @@ -70,15 +72,17 @@ VITE_WISP_URL=wss://relay.your-site/ npm run build

(or set `relay: 'wss://relay.your-site/'` in `config.js`; the Docker image can also run the relay itself, with `OPCODE_RELAY=on`).

It listens on `127.0.0.1` unless given `--host`. Reachable from the internet, it is an open relay: `--origin` only stops other websites' pages from using it (any other program can send the header it expects), so run it where outgoing traffic from strangers is acceptable. It refuses private and local addresses (your network, cloud metadata endpoints) and outgoing mail ports by default (`--allow-private`, `--block-ports 25,465,587`), and limits streams per connection (`--max-streams`). `--via-proxy http://proxy:3128` sends connections through an HTTP proxy. Students or teachers can also point a copy of Opcode at a relay in the *Internet* settings in the status bar (saved in their browser). `npm run relay` starts one locally on port 8090 for development (`VITE_WISP_URL=ws://localhost:8090/ npm run dev`).
It listens on `127.0.0.1` unless given `--host`. Reachable from the internet, it is an open relay: `--origin` only stops other websites' pages from using it (any other program can send the header it expects), so run it where outgoing traffic from strangers is acceptable. It refuses private and local addresses (your network, cloud metadata endpoints) and outgoing mail ports by default (`--allow-private`, `--block-ports 25,465,587`), and limits streams per connection (`--max-streams`). `--via-proxy http://proxy:3128` sends connections through an HTTP proxy; the proxy is given host names and looks them up itself, so the relay's check of private addresses can't bind it: give the proxy its own rules against private, local and metadata addresses. A client that sends more than the Wisp protocol's window allows has that connection closed. Students or teachers can also point a copy of Opcode at a relay in the *Internet* settings in the status bar (saved in their browser). `npm run relay` starts one locally on port 8090 for development (`VITE_WISP_URL=ws://localhost:8090/ npm run dev`).

The production build includes the Wasmer SDK's own dependency for this, the Wisp client [`@mercuryworkshop/wisp-js`](https://github.com/MercuryWorkshop/wisp-client-js) (AGPL-3.0 in the version the SDK uses), bundled as `wasmer-sdk/deps/wisp-client.js`.

## Web preview host

The preview reaches servers inside the sandbox through a service worker on a separate origin. A server owns that whole origin, so one origin can show one server at a time. Opcode's default is Wasmer's `https://default.local.wasmer.site/`, but as of October 2026 that host no longer serves the page the preview loads (`/.wasmer/host.html` answers 404), so the preview only works with a host of your own. opcode-dev.com's is `https://preview.opcode-dev.com/`.

To host your own, run `npm run build:preview-host` and deploy `dist-preview-host/` to an origin other than the app's (it includes `_headers`, and `.nojekyll` for GitHub Pages):
To host your own, run `npm run build:preview-host` and deploy `dist-preview-host/` to an origin other than the app's (it includes `_headers`, and `.nojekyll` for GitHub Pages; the app refuses a preview host on its own origin, where a previewed page could read the user's projects). Build it with `OPCODE_APP_ORIGINS=https://opcode.example.com` (comma-separate several) and only that site's pages can use the host; without it, any site can.

Pages a previewed server serves run on the host's origin. The host's own page is sandboxed so they can't navigate the Opcode tab through it, and each server is routed through a page of its own, so one project's pages don't see the next project's requests. With one origin they still share its cookies and storage: where people preview projects they didn't write, use a wildcard origin.

- **One origin** (one preview at a time): build the app with `VITE_PREVIEW_HOST=https://preview.example.com/ npm run build` (or set `previewHost` in `config.js`; the Docker image serves the host itself, with `OPCODE_PREVIEW_HOST`). On Cloudflare, `dist-preview-host/worker.js` serves it as a Worker on its own domain: `deploy/preview-host.wrangler.toml` is opcode-dev.com's.
- **A wildcard origin** (one address per server, any number at once): serve the same files on every subdomain, with wildcard DNS and a wildcard certificate, and build with `VITE_PREVIEW_HOST=https://*.preview.example.com/ npm run build`. Each server gets a random name such as `https://p3k9x0q2m.preview.example.com/`. On Cloudflare, deploy `dist-preview-host/worker.js` as a Worker routed to `*.preview.example.com/*` (it holds the files itself).
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ scripts/fetch-rust.mjs # Downloads the Rust toolchain (pinned, checksum
scripts/wasmer-packages.mjs # Locks and downloads the Wasmer packages (wasmer-packages.lock.json)
scripts/fetch-java.mjs # Builds Java's runtime files from a pinned Corretto JDK
scripts/fetch-csharp.mjs # Builds the C# toolchain from pinned NuGet packages
scripts/copy-npm-toolchains.mjs # Copies Ruby, TypeScript and webR (R) from their pinned npm packages
scripts/copy-npm-toolchains.mjs # Copies Ruby, TypeScript and webR (R) from their pinned npm packages; patches webR so R can't run JavaScript
scripts/make-mono-font.py # Builds the Recursive Mono code font
scripts/preview-host.mjs # Builds/serves a self-hosted web preview host (and its Cloudflare Worker)
scripts/wisp-server.mjs # Internet relay (Wisp + DNS-over-HTTPS)
Expand Down
Loading
Loading