Canvas's browser-side code (auth.ts, api.ts, billing.ts) all call fetch(PLATFORM_URL + /cp/*). PLATFORM_URL comes from NEXT_PUBLIC_PLATFORM_URL at build time; with the build arg unset, it falls back to http://localhost:8080 in the compiled bundle. That means on a tenant like hongmingwang.moleculesai.app, the user's browser actually tried to fetch http://localhost:8080/cp/ auth/me — which resolves to the USER'S OWN machine, not the tenant. Login redirect loops 404. Every tenant canvas has been unable to complete a fresh login on this path; existing sessions only worked because the cookie was already set domain-wide. Fix: pass NEXT_PUBLIC_PLATFORM_URL=https://api.moleculesai.app as a build arg in the tenant-image workflow. CP already allows CORS from *.moleculesai.app + credentials, and the session cookie is scoped to .moleculesai.app so tenant subdomains inherit it. Verified in prod by rebuilding canvas locally with the flag and hot-patching the hongmingwang instance via SSM. Baked chunks now contain api.moleculesai.app; browser auth redirects resolve cleanly to the CP. Self-hosted users override by rebuilding with their own URL — same pattern molecule-app uses with NEXT_PUBLIC_CP_ORIGIN. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
133 lines
5.4 KiB
YAML
133 lines
5.4 KiB
YAML
name: publish-workspace-server-image
|
|
|
|
# Builds and pushes Docker images to GHCR when staging is promoted to main.
|
|
# PRs target staging (default branch). Only main push triggers production builds.
|
|
# EC2 tenant instances pull the tenant image from GHCR.
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'workspace-server/**'
|
|
- 'canvas/**'
|
|
- 'manifest.json'
|
|
- '.github/workflows/publish-platform-image.yml'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
env:
|
|
IMAGE_NAME: ghcr.io/molecule-ai/platform
|
|
TENANT_IMAGE_NAME: ghcr.io/molecule-ai/platform-tenant
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: [self-hosted, macos, arm64]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Checkout sibling plugin repo
|
|
# workspace-server/Dockerfile expects
|
|
# ./molecule-ai-plugin-github-app-auth at build-context root because
|
|
# the Go module has a `replace` directive pointing at /plugin inside
|
|
# the image. Pre-repo-split the plugin lived in the monorepo; the
|
|
# 2026-04-18 restructure moved it out but didn't add this clone step
|
|
# — which is why publish has been failing since then.
|
|
#
|
|
# Uses a fine-grained PAT (PLUGIN_REPO_PAT) because the plugin repo
|
|
# is private and the default GITHUB_TOKEN is scoped to THIS repo.
|
|
# The PAT needs Contents:Read on Molecule-AI/molecule-ai-plugin-
|
|
# github-app-auth. Falls back to the default token for the (rare)
|
|
# case where an operator made the plugin repo public.
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: Molecule-AI/molecule-ai-plugin-github-app-auth
|
|
path: molecule-ai-plugin-github-app-auth
|
|
token: ${{ secrets.PLUGIN_REPO_PAT || secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Configure GHCR auth
|
|
shell: bash
|
|
env:
|
|
GHCR_USER: ${{ github.actor }}
|
|
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -eu
|
|
mkdir -p "${RUNNER_TEMP}/docker-config"
|
|
GHCR_AUTH=$(printf '%s:%s' "${GHCR_USER}" "${GHCR_TOKEN}" | base64)
|
|
umask 077
|
|
printf '{"auths":{"ghcr.io":{"auth":"%s"}}}' "${GHCR_AUTH}" > "${RUNNER_TEMP}/docker-config/config.json"
|
|
echo "DOCKER_CONFIG=${RUNNER_TEMP}/docker-config" >> "${GITHUB_ENV}"
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v4
|
|
with:
|
|
platforms: linux/amd64
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Compute tags
|
|
id: tags
|
|
run: |
|
|
echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
|
|
|
# Canary-gated release: we publish :staging-<sha> ONLY here. The
|
|
# :latest tag (which existing prod tenants auto-pull every 5 min)
|
|
# is promoted by .github/workflows/canary-verify.yml after the
|
|
# staging canary fleet green-lights this digest.
|
|
# That means:
|
|
# - Every main merge produces a :staging-<sha> image
|
|
# - Canary tenants (configured to pull :staging-<sha>) pick it up
|
|
# - canary-verify.yml runs smoke tests against them
|
|
# - On green → canary-verify retags :staging-<sha> → :latest
|
|
# - On red → :latest stays on the prior good digest, prod is safe
|
|
- name: Build & push platform image to GHCR (staging-<sha> only)
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./workspace-server/Dockerfile
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_NAME }}:staging-${{ steps.tags.outputs.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
labels: |
|
|
org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.description=Molecule AI platform (Go API server) — pending canary verify
|
|
|
|
- name: Build & push tenant image to GHCR (staging-<sha> only)
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./workspace-server/Dockerfile.tenant
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: |
|
|
${{ env.TENANT_IMAGE_NAME }}:staging-${{ steps.tags.outputs.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
# Bake the SaaS control-plane URL into the canvas bundle.
|
|
# Canvas's browser-side code uses PLATFORM_URL for every
|
|
# /cp/* call (auth, orgs, billing, terms). Leaving this empty
|
|
# made PLATFORM_URL fall back to http://localhost:8080 in the
|
|
# built bundle — which fails from the user's browser because
|
|
# localhost resolves to their own machine, not the tenant
|
|
# instance. Baking the CP origin here fixes browser-side auth
|
|
# for every tenant.
|
|
#
|
|
# Self-hosted / private-label deployments override this by
|
|
# rebuilding the image with a different NEXT_PUBLIC_PLATFORM_URL
|
|
# build-arg (e.g. https://api.their-domain.com). Same pattern
|
|
# molecule-app uses with NEXT_PUBLIC_CP_ORIGIN.
|
|
build-args: |
|
|
NEXT_PUBLIC_PLATFORM_URL=https://api.moleculesai.app
|
|
labels: |
|
|
org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.description=Molecule AI tenant platform + canvas — pending canary verify
|