AI-native design editor. Open-source Figma alternative.
build(cloud): publish a Cloud image to ghcr.io (#1497)
Danila Poyarkovfd8714f794d1
diff --git a/.github/workflows/cloud-image.yml b/.github/workflows/cloud-image.ymlnew file mode 100644index 000000000..4decd4fb5--- /dev/null+++ b/.github/workflows/cloud-image.yml@@ -0,0 +1,89 @@+name: Cloud image++# Publishes ghcr.io/open-pencil/cloud, the server with the editor and pages it serves, for each+# published release, and builds it without publishing when its inputs change in a pull request.+on:+ release:+ types: [published]+ workflow_dispatch:+ inputs:+ tag:+ description: Published release tag to rebuild the image for (vX.Y.Z or vX.Y.Z-beta.N).+ required: true+ type: string+ pull_request:+ paths:+ - 'packages/cloud/deploy/Dockerfile'+ - 'packages/cloud/deploy/Dockerfile.dockerignore'+ - '.github/workflows/cloud-image.yml'++permissions:+ contents: read++concurrency:+ group: cloud-image-${{ github.event.release.tag_name || inputs.tag || github.ref }}+ cancel-in-progress: false++jobs:+ image:+ name: Build Cloud image+ runs-on: ubuntu-24.04+ timeout-minutes: 45+ permissions:+ contents: read+ packages: write+ env:+ RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}+ PUBLISH: ${{ github.event_name != 'pull_request' }}+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1+ with:+ ref: ${{ env.RELEASE_TAG || github.sha }}+ persist-credentials: false++ # A rebuild of an older release must not move latest back to it.+ - name: Find the latest release+ id: latest+ if: env.PUBLISH == 'true'+ env:+ GH_TOKEN: ${{ github.token }}+ run: echo "tag=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName)" >> "$GITHUB_OUTPUT"++ # vX.Y.Z is tagged X.Y.Z, X.Y, and latest if it is the latest release; a prerelease only its+ # version and next.+ - uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302+ id: meta+ with:+ images: ghcr.io/open-pencil/cloud+ tags: |+ type=semver,pattern={{version}},value=${{ env.RELEASE_TAG }}+ type=semver,pattern={{major}}.{{minor}},value=${{ env.RELEASE_TAG }}+ type=raw,value=next,enable=${{ contains(env.RELEASE_TAG, '-') }}+ type=ref,event=pr+ flavor: latest=${{ env.PUBLISH == 'true' && steps.latest.outputs.tag == env.RELEASE_TAG }}+ labels: |+ org.opencontainers.image.licenses=Apache-2.0 AND MIT++ - uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567+ if: env.PUBLISH == 'true'+ with:+ registry: ghcr.io+ username: ${{ github.actor }}+ password: ${{ secrets.GITHUB_TOKEN }}++ - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435++ - uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83+ id: build+ with:+ context: .+ file: packages/cloud/deploy/Dockerfile+ platforms: linux/amd64,linux/arm64+ push: ${{ env.PUBLISH == 'true' }}+ tags: ${{ steps.meta.outputs.tags }}+ labels: ${{ steps.meta.outputs.labels }}+ provenance: mode=max+ sbom: true+ cache-from: type=gha,scope=cloud-image+ cache-to: type=gha,scope=cloud-image,mode=max+diff --git a/changes/1497/added.md b/changes/1497/added.mdnew file mode 100644index 000000000..14f191e4a--- /dev/null+++ b/changes/1497/added.md@@ -0,0 +1 @@+- Self-hosted OpenPencil Cloud runs from a published image, `ghcr.io/open-pencil/cloud`, with the server and the editor it serves, and `compose.self-hosted.yml` starts it on one machine with a database, storage, and email.diff --git a/packages/cloud/deploy/Dockerfile b/packages/cloud/deploy/Dockerfilenew file mode 100644index 000000000..d5c29f048--- /dev/null+++ b/packages/cloud/deploy/Dockerfile@@ -0,0 +1,34 @@+# syntax=docker/dockerfile:1+# OpenPencil Cloud: the server and the editor and pages it serves. Build from the repository root:+# docker build -f packages/cloud/deploy/Dockerfile -t openpencil-cloud .+# The image also runs the AI relay: `docker run … openpencil-cloud node ai-relay.mjs`.++# The build's output is JavaScript and static files, so it runs on the builder's own platform+# once, whichever platforms the image is for, with Bun for that platform too. Playwright's+# Chromium draws the demo document.+FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS bun++FROM --platform=$BUILDPLATFORM mcr.microsoft.com/playwright:v1.63.0-noble AS build+COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun+RUN ln -s /usr/local/bin/bun /usr/local/bin/bunx+WORKDIR /src+COPY . .+RUN bun install --frozen-lockfile+RUN bun run build:packages+RUN bun run build:cloud+RUN bun --filter @open-pencil/cloud build:standalone++FROM node:22-bookworm-slim+ENV NODE_ENV=production \+ OPENPENCIL_CLOUD_SITE_DIR=/app/site \+ HOST=0.0.0.0 \+ PORT=8787+WORKDIR /app+COPY --from=build /src/packages/cloud/dist-standalone ./+COPY --from=build /src/dist-cloud ./site+COPY packages/cloud/LICENSE packages/cloud/NOTICE ./+USER node+EXPOSE 8787+HEALTHCHECK --interval=10s --timeout=3s --start-period=30s \+ CMD ["node", "-e", "fetch(`http://127.0.0.1:${process.env.PORT}/ready`).then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]+CMD ["node", "server.mjs"]diff --git a/packages/cloud/deploy/Dockerfile.dockerignore b/packages/cloud/deploy/Dockerfile.dockerignorenew file mode 100644index 000000000..7a2796641--- /dev/null+++ b/packages/cloud/deploy/Dockerfile.dockerignore@@ -0,0 +1,13 @@+# The build installs and builds everything itself, so only sources go in.+**/node_modules+**/dist+**/dist-*+**/.cache+**/.publish+**/.npm-packages+**/test-results+**/playwright-report+.git+desktop/target+packages/cloud/deploy/generated+scratchdiff --git a/packages/cloud/deploy/README.md b/packages/cloud/deploy/README.mdindex 6207caf11..b71a36e52 100644--- a/packages/cloud/deploy/README.md+++ b/packages/cloud/deploy/README.md@@ -33,6 +33,9 @@ commands, email, storage, backups, and upgrades are covered in the[self-hosting guide](https://openpencil.dev/reference/self-hosting-cloud)(`packages/docs/reference/self-hosting-cloud.md`). The example files it refers to are here:[`openpencil-cloud.example.toml`](./openpencil-cloud.example.toml) and [`.env.example`](./.env.example).+[`Dockerfile`](./Dockerfile) builds the published image, `ghcr.io/open-pencil/cloud`, from the+repository root, and [`compose.self-hosted.yml`](./compose.self-hosted.yml) runs it on one machine+with [`self-hosted/openpencil-cloud.toml`](./self-hosted/openpencil-cloud.toml).## End-to-end testsdiff --git a/packages/cloud/deploy/compose.self-hosted.yml b/packages/cloud/deploy/compose.self-hosted.ymlnew file mode 100644index 000000000..e6658c1c1--- /dev/null+++ b/packages/cloud/deploy/compose.self-hosted.yml@@ -0,0 +1,85 @@+# OpenPencil Cloud on one machine, from the published image, to try it out:+# BETTER_AUTH_SECRET=$(openssl rand -hex 32) docker compose -f compose.self-hosted.yml up+# Open http://localhost:8787 and sign up; sign-up mail lands at http://localhost:8025.+# Browsers upload straight to object storage, at the same address the server uses, so SeaweedFS+# shares the server's network and both reach it at localhost:8333. For a server others use, see+# https://openpencil.dev/reference/self-hosting-cloud.+name: openpencil-cloud++services:+ openpencil:+ image: ghcr.io/open-pencil/cloud:${OPENPENCIL_CLOUD_VERSION:-latest}+ depends_on:+ postgres:+ condition: service_healthy+ environment:+ OPENPENCIL_CLOUD_CONFIG: /etc/openpencil/openpencil-cloud.toml+ DATABASE_URL: postgresql://openpencil:${POSTGRES_PASSWORD:-openpencil}@postgres:5432/openpencil+ BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:?Set BETTER_AUTH_SECRET to at least 32 random characters}+ S3_ACCESS_KEY_ID: openpencil+ S3_SECRET_ACCESS_KEY: openpencil-development-secret+ ports:+ - '127.0.0.1:8787:8787'+ - '127.0.0.1:8333:8333'+ volumes:+ - ./self-hosted/openpencil-cloud.toml:/etc/openpencil/openpencil-cloud.toml:ro++ seaweedfs:+ image: chrislusf/seaweedfs:4.41+ network_mode: service:openpencil+ command:+ - server+ - -dir=/data+ - -s3+ - -s3.port=8333+ - -s3.config=/etc/seaweedfs/s3.json+ volumes:+ - storage:/data+ - ./seaweedfs/s3.json:/etc/seaweedfs/s3.json:ro+ healthcheck:+ test: ['CMD', 'nc', '-z', '127.0.0.1', '8333']+ interval: 2s+ timeout: 3s+ retries: 30++ bucket:+ image: amazon/aws-cli:2.27.49+ network_mode: service:openpencil+ depends_on:+ seaweedfs:+ condition: service_healthy+ environment:+ AWS_ACCESS_KEY_ID: openpencil+ AWS_SECRET_ACCESS_KEY: openpencil-development-secret+ AWS_DEFAULT_REGION: us-east-1+ entrypoint: ['/bin/sh', '-c']+ command:+ - >-+ aws --endpoint-url http://127.0.0.1:8333 s3api head-bucket --bucket openpencil+ || aws --endpoint-url http://127.0.0.1:8333 s3api create-bucket --bucket openpencil++ postgres:+ image: postgres:17-alpine+ environment:+ POSTGRES_DB: openpencil+ POSTGRES_USER: openpencil+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-openpencil}+ healthcheck:+ test: ['CMD-SHELL', 'pg_isready -U openpencil -d openpencil']+ interval: 2s+ timeout: 3s+ retries: 30+ volumes:+ - database:/var/lib/postgresql/data++ mailpit:+ image: axllent/mailpit:v1.31.0+ environment:+ MP_DISABLE_VERSION_CHECK: 'true'+ MP_SMTP_DISABLE_RDNS: 'true'+ ports:+ - '127.0.0.1:8025:8025'++volumes:+ database:+ storage:diff --git a/packages/cloud/deploy/self-hosted/openpencil-cloud.toml b/packages/cloud/deploy/self-hosted/openpencil-cloud.tomlnew file mode 100644index 000000000..5ba26436d--- /dev/null+++ b/packages/cloud/deploy/self-hosted/openpencil-cloud.toml@@ -0,0 +1,94 @@+# Settings for compose.self-hosted.yml: one machine, open email sign-up, mail captured by Mailpit.+# openpencil-cloud.example.toml documents every setting.+schema_version = 2++[deployment]+mode = "self-hosted"+public_url = "http://localhost:8787"+indexing = "deny"+local_editor = true++[database]++[authentication.enrollment]+mode = "open"+notification_emails = []++[authentication.email_password]+enabled = true+sign_up = true+minimum_password_length = 8+maximum_password_length = 128+verification_link_lifetime_minutes = 60+password_reset_link_lifetime_minutes = 60+compromised_password_check = false++[authentication.mfa]+required_for_admins = false+totp = true+recovery_codes = true+trusted_device_lifetime_days = 14++[authentication.passkeys]+enabled = true+rp_name = "OpenPencil Cloud"++[authentication.trusted_proxies]+headers = []+addresses = []++[object_storage]+endpoint = "http://localhost:8333"+region = "us-east-1"+bucket = "openpencil"+force_path_style = true+checksum_verification = "metadata"+maximum_upload_bytes = 1073741824++[collaboration]+maximum_message_bytes = 1048576+maximum_connections_per_room = 1000++[documents]+retention_days = 30++[email]+transport = "smtp"+from = "OpenPencil Cloud <cloud@localhost>"++[email.smtp]+host = "mailpit"+port = 1025+secure = false++[workers.email]+batch_size = 50+interval_ms = 5000+lease_ms = 300000+maximum_attempts = 5++[workers.cleanup]+enabled = true+batch_size = 100+interval_ms = 60000+lease_ms = 300000++[entitlements]+source = "static"++[entitlements.documents]+maximum_file_bytes = 1073741824+revision_history = true++[entitlements.storage]+maximum_bytes = 1099511627776++[entitlements.sharing]+links = true+guest_view = true+guest_edit = true+guest_presence = true++[entitlements.collaboration]+enabled = true+maximum_participants = 100diff --git a/packages/docs/reference/self-hosting-cloud.md b/packages/docs/reference/self-hosting-cloud.mdindex 3a9452cb5..8d055e53e 100644--- a/packages/docs/reference/self-hosting-cloud.md+++ b/packages/docs/reference/self-hosting-cloud.md@@ -9,15 +9,34 @@ OpenPencil Cloud is one Node 22+ process in front of PostgreSQL 15 or later and## Install-The server is published to npm as `@open-pencil/cloud`, released with the editor, and runs on Node 22 or later:+Each release publishes an image, `ghcr.io/open-pencil/cloud`, with the server and the editor and pages it serves, for `linux/amd64` and `linux/arm64`. It is tagged with the version (`0.16.0`), the minor version (`0.16`), and `latest`; prereleases are tagged with their version and `next`. Give it the [configuration](#configure) through a mounted TOML file and the environment:++```sh+docker run -p 8787:8787 \+ -v ./openpencil-cloud.toml:/etc/openpencil/openpencil-cloud.toml:ro \+ -e OPENPENCIL_CLOUD_CONFIG=/etc/openpencil/openpencil-cloud.toml \+ --env-file .env \+ ghcr.io/open-pencil/cloud:0.16+```++The image serves its own editor and pages from `/app/site`, so leave `OPENPENCIL_CLOUD_SITE_DIR` out of the `.env` it is given, or the variable points the server somewhere the container does not have. It listens on port 8787, and reports health from `GET /ready`. `docker run … ghcr.io/open-pencil/cloud node ai-relay.mjs` runs the [AI relay](#ai) instead.++To try it on one machine, [`compose.self-hosted.yml`](https://github.com/open-pencil/open-pencil/blob/master/packages/cloud/deploy/compose.self-hosted.yml) runs the image with PostgreSQL, SeaweedFS for storage, and Mailpit for email, configured by [`self-hosted/openpencil-cloud.toml`](https://github.com/open-pencil/open-pencil/blob/master/packages/cloud/deploy/self-hosted/openpencil-cloud.toml):++```sh+cd packages/cloud/deploy+BETTER_AUTH_SECRET=$(openssl rand -hex 32) docker compose -f compose.self-hosted.yml up+```++Open `http://localhost:8787` and sign up; the confirmation email is at `http://localhost:8025`. Its storage keys and passwords are fixed development values, and it answers only on this machine, so set up your own database, storage, and email for a server other people use.++The server alone is also published to npm as `@open-pencil/cloud` and runs on Node 22 or later. It does not include the editor and pages, `dist-cloud/`, which are built from a checkout as below; without them the server runs its API alone.```shnpm install -g @open-pencil/cloudopenpencil-cloud --help```-The package is the server only. The editor and the server's own pages are a separate build, `dist-cloud/`, made from a checkout as below; without it the server runs its API alone.-## Build from sourceFrom a checkout of the repository: