Compare commits

...

20 Commits

Author SHA1 Message Date
jkunz 4a76e520e7 v2.1.2
Release / build-and-release (push) Successful in 2m45s
2026-05-25 11:42:48 +00:00
jkunz d9e1fc17f8 chore(changelog): deduplicate upgrade release notes 2026-05-25 11:42:29 +00:00
jkunz 3b179075a8 fix(upgrade): keep self-upgrades alive after stopping the service 2026-05-25 11:41:52 +00:00
jkunz a3327cdd98 v2.1.1
Release / build-and-release (push) Successful in 2m43s
2026-05-25 10:58:25 +00:00
jkunz 432a5c2264 fix(pnpm-workspace): disable dees-catalog build scripts in workspace config 2026-05-25 10:54:15 +00:00
jkunz f36d20b8dd v2.1.0 2026-05-25 10:42:28 +00:00
jkunz baba892353 chore(changelog): consolidate pending release notes 2026-05-25 10:41:18 +00:00
jkunz d2c1bed82c feat(appstore,workspace): add App Store upgrade progress tracking and interactive workspace processes 2026-05-25 06:24:29 +00:00
jkunz 3e68e875ac v2.0.0
Release / build-and-release (push) Successful in 2m38s
2026-05-25 03:12:29 +00:00
jkunz a30260e336 feat(appstore): use shared resolver 2026-05-25 03:10:18 +00:00
jkunz be53f179ab v1.31.0
Release / build-and-release (push) Successful in 2m29s
2026-05-25 01:40:38 +00:00
jkunz db52934f35 feat(appstore): resolve repo manifests and docker digest-tracked images 2026-05-25 01:39:59 +00:00
jkunz d29257dcf7 v1.30.2 2026-05-24 21:23:33 +00:00
jkunz 3b2b806165 fix(smartproxy): clean up legacy reverse proxy naming for SmartProxy 2026-05-24 21:20:46 +00:00
jkunz 070c936a69 v1.30.1
Release / build-and-release (push) Successful in 2m26s
2026-05-24 17:42:02 +00:00
jkunz 3f15cbda80 fix(settings-ui): align settings gateway cards with dees-tile footer actions 2026-05-24 17:41:34 +00:00
jkunz 4b48f0056e v1.30.0
Release / build-and-release (push) Successful in 2m29s
2026-05-24 14:46:51 +00:00
jkunz d91fda084b feat(admin-ui): add configurable Admin UI domain routing 2026-05-24 14:46:35 +00:00
jkunz a86d83f835 v1.29.0
Release / build-and-release (push) Successful in 2m33s
2026-05-24 11:50:10 +00:00
jkunz 05235ec284 feat(update): add Onebox self-upgrade flow 2026-05-24 11:49:43 +00:00
43 changed files with 2696 additions and 794 deletions
+91
View File
@@ -3,6 +3,97 @@
## Pending
## 2026-05-25 - 2.1.2
### Fixes
- keep self-upgrades alive after stopping the service (upgrade)
- Launch dashboard-triggered upgrades as transient systemd units outside the service cgroup.
- Download and validate installer binaries before stopping the running service.
- Restart the previous service if installation fails after it was stopped.
## 2026-05-25 - 2.1.1
### Fixes
- disable dees-catalog build scripts in workspace config (pnpm-workspace)
- Adds @design.estate/dees-catalog to pnpm allowBuilds with a false value to explicitly prevent its build scripts from running.
## 2026-05-25 - 2.1.0
### Features
- add App Store upgrade progress tracking and interactive workspace processes (appstore,workspace)
- Track App Store upgrade operations with async start/list requests and streamed progress updates.
- Show running and failed upgrade status in App Store and service detail views while preventing duplicate upgrade actions.
- Route App Store upgrades through the shared service update flow to restore service routes before gateway sync.
- Add backend workspace shell discovery plus interactive process start/input/kill/output/exit APIs backed by Docker exec streams.
- Bump Docker and workspace UI dependencies for interactive stdin streaming and shell selection support.
## 2026-05-25 - 2.0.0
### Breaking Changes
- switch Onebox App Store resolution to the shared appstore client
- Uses `@serve.zone/appstore` and `@serve.zone/interfaces` for App Store metadata, parsing, and Docker digest resolution
- Renames App Store typed request methods to `getAppStoreTemplates`, `getAppStoreConfig`, `installAppStoreApp`, and `getUpgradeableAppStoreServices`
- Removes local duplicated App Store DTO and resolver code while preserving Onebox install and upgrade behavior
## 2026-05-25 - 1.31.0
### Features
- resolve repo manifests and docker digest-tracked images (appstore)
- Add catalog source, resolved source, channel, runtime, upgrade strategy, and version metadata types for appstore manifests.
- Resolve catalog entries from repo manifests and pin digest-tracked Docker images using registry digests.
- Propagate resolved image digests into app version configs and service creation options.
- Add runtime coverage for repo manifest resolution and digest-tracked latest images.
## 2026-05-24 - 1.30.2
### Fixes
- reduce remaining reverse proxy wording to required legacy SmartProxy cleanup and migration identifiers
- clean up legacy reverse proxy naming for SmartProxy (smartproxy)
- Update legacy reverse proxy service naming and logs used during SmartProxy startup cleanup.
- Clarify migration and documentation wording for the legacy reverse proxy to SmartProxy transition.
- Bump @serve.zone/catalog to ^2.12.6 and add pnpm workspace build dependency settings.
## 2026-05-24 - 1.30.1
### Fixes
- align Onebox settings gateway cards with the dees-tile footer action pattern
- align settings gateway cards with dees-tile footer actions (settings-ui)
- Replaces custom gateway card wrappers with dees-tile header and footer slots.
- Uses tile-styled action buttons for Admin UI and dcrouter settings saves.
## 2026-05-24 - 1.30.0
### Features
- add configurable Onebox Admin UI domain
- expose Admin UI domain in settings
- sync the Admin UI route as a first-class dcrouter gateway route
- keep Admin UI routing separate from app service routes
- add configurable Admin UI domain routing (admin-ui)
- Expose and validate the Admin UI domain in settings
- Sync the Admin UI as a dedicated dcrouter gateway route and SmartProxy route
- Preserve configured and legacy Admin UI routes during stale-route reconciliation
### Fixes
- preserve Onebox Admin UI routes during external gateway stale-route reconciliation
## 2026-05-24 - 1.29.0
### Features
- add Onebox runtime update prompts and admin-triggered self-upgrades
- expose Onebox update status through system status
- reuse the CLI upgrade logic for web-triggered detached upgrades
- show an update banner and guided DeesUpdater flow in the dashboard
## 2026-05-24 - 1.28.0
### Features
+5 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@serve.zone/onebox",
"version": "1.28.0",
"version": "2.1.2",
"exports": "./mod.ts",
"tasks": {
"test": "deno test --allow-all test/",
@@ -15,7 +15,7 @@
"@std/assert": "jsr:@std/assert@^1.0.19",
"@std/encoding": "jsr:@std/encoding@^1.0.10",
"@db/sqlite": "jsr:@db/sqlite@0.13.0",
"@apiclient.xyz/docker": "npm:@apiclient.xyz/docker@^5.1.4",
"@apiclient.xyz/docker": "npm:@apiclient.xyz/docker@^5.1.5",
"@apiclient.xyz/cloudflare": "npm:@apiclient.xyz/cloudflare@7.1.0",
"@push.rocks/smartacme": "npm:@push.rocks/smartacme@^9.5.0",
"@push.rocks/smartregistry": "npm:@push.rocks/smartregistry@^2.9.2",
@@ -27,7 +27,9 @@
"@push.rocks/smartguard": "npm:@push.rocks/smartguard@^3.1.0",
"@push.rocks/smartjwt": "npm:@push.rocks/smartjwt@^2.2.2",
"@api.global/typedsocket": "npm:@api.global/typedsocket@^4.1.3",
"@serve.zone/containerarchive": "npm:@serve.zone/containerarchive@^0.1.3"
"@serve.zone/containerarchive": "npm:@serve.zone/containerarchive@^0.1.3",
"@serve.zone/interfaces": "npm:@serve.zone/interfaces@^6.0.0",
"@serve.zone/appstore": "npm:@serve.zone/appstore@^0.2.0"
},
"compilerOptions": {
"lib": [
+51 -41
View File
@@ -170,14 +170,55 @@ DOWNLOAD_URL="${GITEA_BASE_URL}/${GITEA_REPO}/releases/download/${VERSION}/${BIN
echo "Download URL: $DOWNLOAD_URL"
echo ""
# Check if service is running and stop it
# Check whether the service should be restarted after a successful install.
SERVICE_WAS_RUNNING=0
if systemctl is-enabled --quiet "$SERVICE_NAME" 2>/dev/null || systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
SERVICE_WAS_RUNNING=1
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
echo "Stopping Onebox service..."
systemctl stop "$SERVICE_NAME"
fi
# Download and validate the new binary before touching the running service.
echo "Downloading Onebox binary..."
TEMP_DIR=$(mktemp -d)
TEMP_FILE="$TEMP_DIR/$BINARY_NAME"
cleanup_temp() {
rm -rf "$TEMP_DIR"
}
trap cleanup_temp EXIT
if ! curl -fSL "$DOWNLOAD_URL" -o "$TEMP_FILE"; then
echo "Error: Failed to download binary from $DOWNLOAD_URL"
echo ""
echo "Please check:"
echo " 1. Your internet connection"
echo " 2. The specified version exists: ${GITEA_BASE_URL}/${GITEA_REPO}/releases"
echo " 3. The platform binary is available for this release"
exit 1
fi
if [ ! -s "$TEMP_FILE" ]; then
echo "Error: Downloaded file is empty or does not exist"
exit 1
fi
chmod +x "$TEMP_FILE"
if ! "$TEMP_FILE" --version >/dev/null 2>&1; then
echo "Error: Downloaded file is not an executable Onebox binary"
exit 1
fi
SERVICE_STOPPED=0
restart_previous_service_on_error() {
if [ $SERVICE_STOPPED -eq 1 ]; then
echo "Installation failed after stopping Onebox; restarting previous service..."
systemctl start "$SERVICE_NAME" || true
fi
}
trap 'restart_previous_service_on_error; cleanup_temp' ERR
if [ $SERVICE_WAS_RUNNING -eq 1 ] && systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
echo "Stopping Onebox service..."
systemctl stop "$SERVICE_NAME"
SERVICE_STOPPED=1
fi
# Clean installation directory - ensure only binary exists
@@ -190,44 +231,10 @@ fi
echo "Creating installation directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
# Download binary
echo "Downloading Onebox binary..."
TEMP_FILE="$INSTALL_DIR/onebox.download"
curl -sSL "$DOWNLOAD_URL" -o "$TEMP_FILE"
if [ $? -ne 0 ]; then
echo "Error: Failed to download binary from $DOWNLOAD_URL"
echo ""
echo "Please check:"
echo " 1. Your internet connection"
echo " 2. The specified version exists: ${GITEA_BASE_URL}/${GITEA_REPO}/releases"
echo " 3. The platform binary is available for this release"
rm -f "$TEMP_FILE"
exit 1
fi
# Check if download was successful (file exists and not empty)
if [ ! -s "$TEMP_FILE" ]; then
echo "Error: Downloaded file is empty or does not exist"
rm -f "$TEMP_FILE"
exit 1
fi
# Move to final location
# Install binary
BINARY_PATH="$INSTALL_DIR/onebox"
mv "$TEMP_FILE" "$BINARY_PATH"
if [ $? -ne 0 ] || [ ! -f "$BINARY_PATH" ]; then
echo "Error: Failed to move binary to $BINARY_PATH"
rm -f "$TEMP_FILE" 2>/dev/null
exit 1
fi
# Make executable
chmod +x "$BINARY_PATH"
if [ $? -ne 0 ]; then
echo "Error: Failed to make binary executable"
if ! install -m 0755 "$TEMP_FILE" "$BINARY_PATH" || [ ! -f "$BINARY_PATH" ]; then
echo "Error: Failed to install binary to $BINARY_PATH"
exit 1
fi
@@ -256,10 +263,13 @@ if [ $SERVICE_WAS_RUNNING -eq 1 ]; then
onebox systemd enable
echo "Restarting Onebox service..."
systemctl restart "$SERVICE_NAME"
SERVICE_STOPPED=0
echo "Service restarted successfully."
echo ""
fi
trap - ERR
echo "================================================"
echo " Onebox Installation Complete!"
echo "================================================"
+7 -8
View File
@@ -1,6 +1,6 @@
{
"name": "@serve.zone/onebox",
"version": "1.28.0",
"version": "2.1.2",
"description": "Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers",
"main": "mod.ts",
"type": "module",
@@ -52,21 +52,20 @@
"x64",
"arm64"
],
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34",
"packageManager": "pnpm@11.1.2",
"dependencies": {
"@api.global/typedrequest-interfaces": "^3.0.19",
"@api.global/typedsocket": "^4.1.3",
"@design.estate/dees-catalog": "^3.81.0",
"@design.estate/dees-catalog": "^3.82.0",
"@design.estate/dees-element": "^2.2.4",
"@serve.zone/catalog": "^2.12.5"
"@serve.zone/appstore": "^0.2.0",
"@serve.zone/catalog": "^2.12.6",
"@serve.zone/interfaces": "^6.0.0"
},
"devDependencies": {
"@git.zone/tsbundle": "^2.10.4",
"@git.zone/tsdeno": "^1.3.2",
"@git.zone/tswatch": "^3.3.5"
},
"private": true,
"pnpm": {
"overrides": {}
}
"private": true
}
+69 -8
View File
@@ -15,14 +15,20 @@ importers:
specifier: ^4.1.3
version: 4.1.3(@push.rocks/smartserve@2.0.4)
'@design.estate/dees-catalog':
specifier: ^3.81.0
version: 3.81.0(@tiptap/pm@2.27.2)
specifier: ^3.82.0
version: 3.82.0(@tiptap/pm@2.27.2)
'@design.estate/dees-element':
specifier: ^2.2.4
version: 2.2.4
'@serve.zone/appstore':
specifier: ^0.2.0
version: 0.2.0
'@serve.zone/catalog':
specifier: ^2.12.5
version: 2.12.5(@tiptap/pm@2.27.2)
specifier: ^2.12.6
version: 2.12.6(@tiptap/pm@2.27.2)
'@serve.zone/interfaces':
specifier: ^6.0.0
version: 6.0.0
devDependencies:
'@git.zone/tsbundle':
specifier: ^2.10.4
@@ -75,6 +81,9 @@ packages:
'@design.estate/dees-catalog@3.81.0':
resolution: {integrity: sha512-N7ocwSKVdjDQWmVV2XWiyg3dotGEuxP4/jhyB6duH8zJ3k63wmGm8+FeoP+LzRc8/U0Bl8w7UZrewlkIEMstUA==}
'@design.estate/dees-catalog@3.82.0':
resolution: {integrity: sha512-OvPglDHI8J8K8+hmtxHyvVLzKMr8rQSFXVxf6xT60q/om3QoQacwS8cPI/RmnEKT+mzvDk/vnNpt9/Tw0cTmWA==}
'@design.estate/dees-comms@1.0.30':
resolution: {integrity: sha512-KchMlklJfKAjQiJiR0xmofXtQ27VgZtBIxcMwPE9d+h3jJRv+lPZxzBQVOM0eyM0uS44S5vJMZ11IeV4uDXSHg==}
@@ -977,8 +986,14 @@ packages:
'@sec-ant/readable-stream@0.4.1':
resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==}
'@serve.zone/catalog@2.12.5':
resolution: {integrity: sha512-0AgHnxonJ7xyYdA02s4tN9/aZG8yBYml4sAA7AUt9fYpRtKYMuZXUcUOS3Rz/FvUu1PrKe7QLtex9VK5IqZDPw==}
'@serve.zone/appstore@0.2.0':
resolution: {integrity: sha512-qt2LVaRpzfJdUywllm+F0njwnN3aHc2aZHEcjc9REn1VDT47UuUEGaKkfNiosGK0GJqb1hPI/GwyuGMe4H4q7w==}
'@serve.zone/catalog@2.12.6':
resolution: {integrity: sha512-FjieZNCHTCHufMre8OSP8bFP9L4DPL9yNtd7UMwD1yQ8wublgAq6eWrx6Tfb+3k8Hyof33BBt4rbFyrvIEBk+A==}
'@serve.zone/interfaces@6.0.0':
resolution: {integrity: sha512-nCidhOH0XlX+7e6xaJDq6fwnwaWasB/4w2LHkV7A96G+m+7EXZqbbaKSboUlaiGDly0dWNajk2FrYFo64ZucPA==}
'@tempfix/lenis@1.3.20':
resolution: {integrity: sha512-ypeB0FuHLHOCQXW4d0RQ69txPJJH+1CHcpsZIUdcv2t1vR0IVyQr2vHihtde9UOXhjzqEnUphWon/UcJNsa0YA==}
@@ -2534,6 +2549,42 @@ snapshots:
- supports-color
- vue
'@design.estate/dees-catalog@3.82.0(@tiptap/pm@2.27.2)':
dependencies:
'@design.estate/dees-domtools': 2.5.6
'@design.estate/dees-element': 2.2.4
'@design.estate/dees-wcctools': 3.9.0
'@fortawesome/fontawesome-svg-core': 7.2.0
'@fortawesome/free-brands-svg-icons': 7.2.0
'@fortawesome/free-regular-svg-icons': 7.2.0
'@fortawesome/free-solid-svg-icons': 7.2.0
'@push.rocks/smarti18n': 1.1.0
'@push.rocks/smartpromise': 4.2.4
'@push.rocks/smartstring': 4.1.1
'@tempfix/webcontainer__api': 1.6.1
'@tiptap/core': 2.27.2(@tiptap/pm@2.27.2)
'@tiptap/extension-link': 2.27.2(@tiptap/core@2.27.2(@tiptap/pm@2.27.2))(@tiptap/pm@2.27.2)
'@tiptap/extension-text-align': 2.27.2(@tiptap/core@2.27.2(@tiptap/pm@2.27.2))
'@tiptap/extension-typography': 2.27.2(@tiptap/core@2.27.2(@tiptap/pm@2.27.2))
'@tiptap/extension-underline': 2.27.2(@tiptap/core@2.27.2(@tiptap/pm@2.27.2))
'@tiptap/starter-kit': 2.27.2
'@tsclass/tsclass': 9.5.1
echarts: 5.6.0
highlight.js: 11.11.1
ibantools: 4.5.4
lightweight-charts: 5.2.0
lucide: 1.14.0
monaco-editor: 0.55.1
pdfjs-dist: 4.10.38
xterm: 5.3.0
xterm-addon-fit: 0.8.0(xterm@5.3.0)
transitivePeerDependencies:
- '@nuxt/kit'
- '@tiptap/pm'
- react
- supports-color
- vue
'@design.estate/dees-comms@1.0.30':
dependencies:
'@api.global/typedrequest': 3.3.0
@@ -2543,7 +2594,7 @@ snapshots:
'@design.estate/dees-domtools@2.5.6':
dependencies:
'@api.global/typedrequest': 3.3.0
'@api.global/typedrequest': 3.3.1
'@design.estate/dees-comms': 1.0.30
'@push.rocks/lik': 6.4.1
'@push.rocks/smartdelay': 3.1.0
@@ -3572,7 +3623,11 @@ snapshots:
'@sec-ant/readable-stream@0.4.1': {}
'@serve.zone/catalog@2.12.5(@tiptap/pm@2.27.2)':
'@serve.zone/appstore@0.2.0':
dependencies:
'@serve.zone/interfaces': 6.0.0
'@serve.zone/catalog@2.12.6(@tiptap/pm@2.27.2)':
dependencies:
'@design.estate/dees-catalog': 3.81.0(@tiptap/pm@2.27.2)
'@design.estate/dees-domtools': 2.5.6
@@ -3585,6 +3640,12 @@ snapshots:
- supports-color
- vue
'@serve.zone/interfaces@6.0.0':
dependencies:
'@api.global/typedrequest-interfaces': 3.0.19
'@push.rocks/smartlog-interfaces': 3.0.2
'@tsclass/tsclass': 9.5.1
'@tempfix/lenis@1.3.20': {}
'@tempfix/webcontainer__api@1.6.1': {}
+5
View File
@@ -0,0 +1,5 @@
allowBuilds:
'@design.estate/dees-catalog': false
esbuild: true
ignoredBuiltDependencies:
- '@design.estate/dees-catalog'
+1 -1
View File
@@ -46,7 +46,7 @@ ts/database/
## Current Migration Version: 15
Migration 15 renames the core reverse proxy platform service from `caddy` to `smartproxy`.
Migration 15 renames the legacy core reverse proxy platform service type to `smartproxy`.
## Reverse Proxy (April 2026 - SmartProxy Docker Service)
+1 -1
View File
@@ -183,7 +183,7 @@ onebox config set cloudflareZoneId zone-id
## App Store
The App Store manager fetches catalog data from `serve.zone/appstore-apptemplates` and caches it briefly. Templates can declare platform requirements, so installing an app can automatically provision MongoDB, S3-compatible storage, ClickHouse, Redis, or MariaDB resources and inject the resulting credentials as environment variables.
The App Store manager fetches metadata from `serve.zone/appstore` through `@serve.zone/appstore` and caches it briefly. Templates can declare platform requirements, so installing an app can automatically provision MongoDB, S3-compatible storage, ClickHouse, Redis, or MariaDB resources and inject the resulting credentials as environment variables.
```bash
onebox appstore list
+94 -2
View File
@@ -2,12 +2,14 @@ import { assertEquals, assertThrows } from '@std/assert';
import { AppStoreManager } from '../ts/classes/appstore.ts';
import { OneboxDockerManager } from '../ts/classes/docker.ts';
import type { IAppVersionConfig } from '../ts/classes/appstore-types.ts';
import type * as servezoneInterfaces from '@serve.zone/interfaces';
import type { IService } from '../ts/types.ts';
type IAppStoreVersionConfig = servezoneInterfaces.appstore.IAppStoreVersionConfig;
const createAppStore = () => new AppStoreManager({} as any);
const baseConfig: IAppVersionConfig = {
const baseConfig: IAppStoreVersionConfig = {
image: 'example/app:1.0.0',
port: 3000,
envVars: [
@@ -81,6 +83,96 @@ Deno.test('appstore rejects invalid template ports and volumes', () => {
);
});
Deno.test('appstore resolves repo manifests and docker digest-tracked latest images', async () => {
const appStoreBaseUrl = 'https://appstore.example.test';
const manifestUrl = 'https://code.example.test/cloudly/servezone.appstore.json';
const digest = 'sha256:1234567890abcdef';
const fakeFetch: typeof fetch = async (input, init) => {
const url = input instanceof Request ? input.url : input.toString();
const method = init?.method || 'GET';
if (url === `${appStoreBaseUrl}/appstore.resolved.json`) {
return new Response('not found', { status: 404 });
}
if (url === `${appStoreBaseUrl}/appstore.json`) {
return Response.json({
schemaVersion: 1,
updatedAt: '2026-05-24T00:00:00Z',
apps: [
{
id: 'cloudly',
name: 'Cloudly',
description: 'Central metadata can stay curated.',
category: 'Dev Tools',
latestVersion: '1.0.0',
source: {
type: 'repoManifest',
url: manifestUrl,
ref: 'main',
},
},
],
});
}
if (url === manifestUrl) {
return Response.json({
schemaVersion: 1,
app: {
id: 'cloudly',
name: 'Cloudly',
description: 'Manifest-owned app metadata.',
category: 'Dev Tools',
maintainer: 'serve.zone',
},
latestVersion: 'latest',
source: {
type: 'dockerImage',
image: 'registry.example.test/serve.zone/cloudly:latest',
tracking: 'digest',
},
runtime: {
image: 'registry.example.test/serve.zone/cloudly:latest',
port: 80,
},
});
}
if (
url === 'https://registry.example.test/v2/serve.zone/cloudly/manifests/latest' &&
method === 'HEAD'
) {
return new Response(null, {
status: 200,
headers: { 'docker-content-digest': digest },
});
}
return new Response(`unexpected ${method} ${url}`, { status: 500 });
};
const appStore = new AppStoreManager({} as any, {
baseUrl: appStoreBaseUrl,
fetch: fakeFetch,
});
const appStoreIndex = await appStore.getAppStore();
assertEquals(appStoreIndex.apps[0].latestVersion, `latest@${digest}`);
assertEquals(appStoreIndex.apps[0].resolvedSource?.manifestHash?.length, 64);
assertEquals(appStoreIndex.apps[0].upgradeStrategy, 'dockerDigest');
const appMeta = await appStore.getAppMeta('cloudly');
assertEquals(appMeta.latestVersion, `latest@${digest}`);
assertEquals(appMeta.versions, [`latest@${digest}`]);
const config = await appStore.getAppVersionConfig('cloudly', appMeta.latestVersion);
assertEquals(config.image, 'registry.example.test/serve.zone/cloudly:latest');
assertEquals(config.appStoreVersion, `latest@${digest}`);
assertEquals(config.resolvedImageDigest, digest);
});
Deno.test('docker service spec validation rejects unsafe volume and port declarations', () => {
const dockerManager = new OneboxDockerManager();
+241
View File
@@ -173,6 +173,47 @@ Deno.test('ExternalGatewayManager syncs service routes to dcrouter gatewayClient
assertEquals(syncRequest.requestData.enabled, true);
});
Deno.test('ExternalGatewayManager syncs Admin UI route to dcrouter gatewayClient API', async () => {
const oneboxRef = makeOneboxRef();
oneboxRef.database.settings.set('adminUiDomain', 'Onebox.Example.com');
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
oneboxRef.database.settings.set('httpPort', '8080');
const requests: Array<{ method: string; requestData: Record<string, unknown> }> = [];
const manager = new ExternalGatewayManager(oneboxRef as any);
(manager as any).fireDcRouterRequest = async (
method: string,
requestData: Record<string, unknown>,
) => {
if (method === 'getGatewayClientContext') {
return {
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
};
}
requests.push({ method, requestData });
if (method === 'exportCertificate') {
return { success: false };
}
return { success: true, action: 'created', routeId: 'admin-route' };
};
await manager.syncAdminUiRoute();
const syncRequest = requests.find((request) => request.method === 'syncGatewayClientRoute')!;
const route = syncRequest.requestData.route as any;
const ownership = syncRequest.requestData.ownership as any;
assertEquals(ownership, {
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'onebox-admin-ui',
hostname: 'onebox.example.com',
});
assertEquals(route.match, { ports: [443], domains: ['onebox.example.com'] });
assertEquals(route.action.targets, [{ host: '203.0.113.10', port: 8080 }]);
assertEquals(syncRequest.requestData.enabled, true);
});
Deno.test('ExternalGatewayManager uses managed dcrouter local target in managed mode', async () => {
const oneboxRef = makeOneboxRef();
(oneboxRef as any).managedDcRouter = {
@@ -322,6 +363,206 @@ Deno.test('ExternalGatewayManager removes stale gateway routes during reconcilia
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
});
Deno.test('ExternalGatewayManager preserves configured Admin UI route during reconciliation', async () => {
const oneboxRef = makeOneboxRef();
oneboxRef.database.settings.set('adminUiDomain', 'onebox.example.com');
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
oneboxRef.database.services.push({
id: 1,
name: 'active',
image: 'nginx:latest',
envVars: {},
port: 3000,
domain: 'active.example.com',
status: 'running',
createdAt: 1,
updatedAt: 1,
});
const deletes: Record<string, unknown>[] = [];
const manager = new ExternalGatewayManager(oneboxRef as any);
(manager as any).fireDcRouterRequest = async (method: string, requestData: Record<string, unknown>) => {
if (method === 'getGatewayClientContext') {
return { context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } } };
}
if (method === 'syncGatewayClientRoute') {
if (requestData.delete) {
deletes.push(requestData);
return { success: true, action: 'deleted' };
}
return { success: true, action: 'updated' };
}
if (method === 'exportCertificate') {
return { success: false };
}
if (method === 'getGatewayClientDnsRecords') {
return {
records: [
{
id: 'admin-record',
domainId: 'domain-1',
name: 'onebox',
type: 'A',
value: '203.0.113.10',
ttl: 300,
source: 'route',
status: 'active',
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'onebox-admin-ui',
hostname: 'onebox.example.com',
routeId: 'admin-route',
},
{
id: 'stale-record',
domainId: 'domain-1',
name: 'stale',
type: 'A',
value: '203.0.113.10',
ttl: 300,
source: 'route',
status: 'active',
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'stale',
hostname: 'stale.example.com',
routeId: 'stale-route',
},
],
};
}
throw new Error(`Unexpected method: ${method}`);
};
await manager.syncServiceRoutes();
assertEquals(deletes.length, 1);
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
});
Deno.test('ExternalGatewayManager preserves legacy Admin UI route when setting is absent', async () => {
const oneboxRef = makeOneboxRef();
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
const deletes: Record<string, unknown>[] = [];
const manager = new ExternalGatewayManager(oneboxRef as any);
(manager as any).fireDcRouterRequest = async (
method: string,
requestData: Record<string, unknown>,
) => {
if (method === 'getGatewayClientContext') {
return {
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
};
}
if (method === 'syncGatewayClientRoute') {
if (requestData.delete) {
deletes.push(requestData);
return { success: true, action: 'deleted' };
}
return { success: true, action: 'updated' };
}
if (method === 'getGatewayClientDnsRecords') {
return {
records: [
{
id: 'legacy-admin-record',
domainId: 'domain-1',
name: 'onebox',
type: 'A',
value: '203.0.113.10',
ttl: 300,
source: 'route',
status: 'active',
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'onebox',
hostname: 'onebox.example.com',
routeId: 'legacy-admin-route',
},
{
id: 'stale-record',
domainId: 'domain-1',
name: 'stale',
type: 'A',
value: '203.0.113.10',
ttl: 300,
source: 'route',
status: 'active',
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'stale',
hostname: 'stale.example.com',
routeId: 'stale-route',
},
],
};
}
throw new Error(`Unexpected method: ${method}`);
};
await manager.syncServiceRoutes();
assertEquals(deletes.length, 1);
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
});
Deno.test('ExternalGatewayManager deletes old Admin UI route after domain change', async () => {
const oneboxRef = makeOneboxRef();
oneboxRef.database.settings.set('adminUiDomain', 'new.example.com');
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
const deletes: Record<string, unknown>[] = [];
const manager = new ExternalGatewayManager(oneboxRef as any);
(manager as any).fireDcRouterRequest = async (
method: string,
requestData: Record<string, unknown>,
) => {
if (method === 'getGatewayClientContext') {
return {
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
};
}
if (method === 'syncGatewayClientRoute') {
if (requestData.delete) {
deletes.push(requestData);
return { success: true, action: 'deleted' };
}
return { success: true, action: 'updated' };
}
if (method === 'exportCertificate') {
return { success: false };
}
if (method === 'getGatewayClientDnsRecords') {
return {
records: [
{
id: 'old-admin-record',
domainId: 'domain-1',
name: 'onebox',
type: 'A',
value: '203.0.113.10',
ttl: 300,
source: 'route',
status: 'active',
gatewayClientType: 'onebox',
gatewayClientId: 'onebox-token',
appId: 'onebox-admin-ui',
hostname: 'old.example.com',
routeId: 'old-admin-route',
},
],
};
}
throw new Error(`Unexpected method: ${method}`);
};
await manager.syncServiceRoutes();
assertEquals(deletes.length, 1);
assertEquals((deletes[0].ownership as any).hostname, 'old.example.com');
});
Deno.test('ExternalGatewayManager imports exported dcrouter certificates into Onebox', async () => {
const oneboxRef = makeOneboxRef();
const manager = new ExternalGatewayManager(oneboxRef as any);
+50
View File
@@ -0,0 +1,50 @@
import { assertEquals } from '@std/assert';
import { OneboxReverseProxy } from '../ts/classes/reverseproxy.ts';
import type { IService } from '../ts/types.ts';
class FakeDatabase {
public settings = new Map<string, string>();
public services: IService[] = [];
getSetting(key: string): string | null {
return this.settings.get(key) ?? null;
}
getAllServices(): IService[] {
return this.services;
}
getServiceByID(id: number): IService | null {
return this.services.find((service) => service.id === id) ?? null;
}
getAllSSLCertificates(): [] {
return [];
}
}
Deno.test('OneboxReverseProxy loads Admin UI domain as local SmartProxy route', async () => {
const database = new FakeDatabase();
database.settings.set('adminUiDomain', 'onebox.example.com');
database.settings.set('serverIP', '203.0.113.10');
const reverseProxy = new OneboxReverseProxy({ database } as any);
const routes: Array<{ domain: string; upstream: string }> = [];
(reverseProxy as any).smartProxy = {
clear: () => routes.splice(0, routes.length),
addRoute: async (domain: string, upstream: string) => {
routes.push({ domain, upstream });
},
getCertificates: () => [],
};
await reverseProxy.reloadRoutes();
assertEquals(routes, [
{
domain: 'onebox.example.com',
upstream: '203.0.113.10:3000',
},
]);
});
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/onebox',
version: '1.28.0',
version: '2.1.2',
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
}
-109
View File
@@ -1,109 +0,0 @@
/**
* App Store type definitions
*/
export interface ICatalog {
schemaVersion: number;
updatedAt: string;
apps: ICatalogApp[];
}
export interface ICatalogApp {
id: string;
name: string;
description: string;
category: string;
iconName?: string;
iconUrl?: string;
latestVersion: string;
tags?: string[];
}
export interface IAppCatalogVolume {
name?: string;
source?: string;
mountPath: string;
driver?: string;
readOnly?: boolean;
backup?: boolean;
options?: Record<string, string>;
}
export type TAppCatalogVolumeSpec = string | IAppCatalogVolume;
export interface IAppCatalogPublishedPort {
targetPort: number;
targetPortEnd?: number;
publishedPort?: number;
publishedPortEnd?: number;
protocol?: 'tcp' | 'udp';
hostIp?: string;
}
export interface IAppMeta {
id: string;
name: string;
description: string;
category: string;
iconName?: string;
latestVersion: string;
versions: string[];
maintainer?: string;
links?: Record<string, string>;
}
export interface IAppVersionConfig {
image: string;
port: number;
envVars?: Array<{ key: string; value: string; description: string; required?: boolean }>;
volumes?: TAppCatalogVolumeSpec[];
publishedPorts?: IAppCatalogPublishedPort[];
platformRequirements?: {
mongodb?: boolean;
s3?: boolean;
clickhouse?: boolean;
redis?: boolean;
mariadb?: boolean;
};
minOneboxVersion?: string;
}
export interface IAppInstallOptions {
appId: string;
version?: string;
serviceName: string;
domain?: string;
port?: number;
publishedPorts?: IAppCatalogPublishedPort[];
envVars?: Record<string, string>;
autoDNS?: boolean;
}
export interface IMigrationContext {
service: {
name: string;
image: string;
envVars: Record<string, string>;
port: number;
};
fromVersion: string;
toVersion: string;
}
export interface IMigrationResult {
success: boolean;
envVars?: Record<string, string>;
image?: string;
port?: number;
volumes?: IAppCatalogVolume[];
publishedPorts?: IAppCatalogPublishedPort[];
warnings: string[];
}
export interface IUpgradeableService {
serviceName: string;
appTemplateId: string;
currentVersion: string;
latestVersion: string;
hasMigration: boolean;
}
+191 -305
View File
@@ -1,117 +1,148 @@
/**
* App Store Manager
* Fetches, caches, and serves app templates from the remote appstore-apptemplates repo.
* The remote repo is the single source of truth — no fallback catalog.
* Fetches, caches, and serves app templates from the remote App Store repo.
*/
import type {
ICatalog,
ICatalogApp,
IAppMeta,
IAppCatalogVolume,
IAppInstallOptions,
IAppVersionConfig,
IMigrationContext,
IMigrationResult,
IUpgradeableService,
} from './appstore-types.ts';
import * as plugins from '../plugins.ts';
import { logger } from '../logging.ts';
import { getErrorMessage } from '../utils/error.ts';
import type { Onebox } from './onebox.ts';
import type { IService, IServiceVolume } from '../types.ts';
import type { IService, IServicePublishedPort, IServiceVolume } from '../types.ts';
import { projectInfo } from '../info.ts';
export class AppStoreManager {
private oneboxRef: Onebox;
private catalogCache: ICatalog | null = null;
private lastFetchTime = 0;
private readonly repoBaseUrl = 'https://code.foss.global/serve.zone/appstore-apptemplates/raw/branch/main';
private readonly cacheTtlMs = 5 * 60 * 1000; // 5 minutes
type IAppStoreIndex = plugins.servezoneInterfaces.appstore.IAppStoreIndex;
type IAppStoreApp = plugins.servezoneInterfaces.appstore.IAppStoreApp;
type IAppStoreAppMeta = plugins.servezoneInterfaces.appstore.IAppStoreAppMeta;
type IAppStoreVersionConfig = plugins.servezoneInterfaces.appstore.IAppStoreVersionConfig;
type IAppStoreInstallOptions = plugins.servezoneInterfaces.appstore.IAppStoreInstallRequest & {
autoDNS?: boolean;
};
type IUpgradeableAppStoreService = plugins.servezoneInterfaces.appstore.IUpgradeableAppStoreService;
constructor(oneboxRef: Onebox) {
this.oneboxRef = oneboxRef;
export interface IAppStoreManagerOptions {
baseUrl?: string;
fetch?: typeof fetch;
resolveDockerDigests?: boolean;
}
export interface IMigrationContext {
service: {
name: string;
image: string;
envVars: Record<string, string>;
port: number;
};
fromVersion: string;
toVersion: string;
}
export interface IMigrationResult {
success: boolean;
envVars?: Record<string, string>;
image?: string;
imageDigest?: string;
port?: number;
volumes?: IServiceVolume[];
publishedPorts?: IServicePublishedPort[];
warnings: string[];
}
export interface IAppStoreUpgradeApplyOptions {
onProgress?: (progressArg: { step: string; message: string }) => void | Promise<void>;
}
export class AppStoreManager {
private appStoreCache: IAppStoreIndex | null = null;
private appStoreResolver: plugins.servezoneAppstore.AppStoreResolver;
private lastFetchTime = 0;
private readonly appStoreBaseUrl: string;
private readonly fetchRef: typeof fetch;
private readonly resolveDockerDigests: boolean;
private readonly cacheTtlMs = 5 * 60 * 1000;
constructor(
private oneboxRef: Onebox,
optionsArg: IAppStoreManagerOptions = {},
) {
this.appStoreBaseUrl = optionsArg.baseUrl || 'https://code.foss.global/serve.zone/appstore/raw/branch/main';
this.fetchRef = optionsArg.fetch || fetch;
this.resolveDockerDigests = optionsArg.resolveDockerDigests ?? true;
this.appStoreResolver = this.createAppStoreResolver();
}
async init(): Promise<void> {
public async init(): Promise<void> {
try {
await this.getCatalog();
logger.info(`App Store initialized with ${this.catalogCache?.apps.length || 0} templates`);
await this.getAppStore();
logger.info(`App Store initialized with ${this.appStoreCache?.apps.length || 0} templates`);
} catch (error) {
logger.warn(`App Store initialization failed: ${getErrorMessage(error)}`);
logger.warn('App Store will retry on next request');
}
}
/**
* Get the catalog (cached, refreshes after TTL)
*/
async getCatalog(): Promise<ICatalog> {
public async getAppStore(): Promise<IAppStoreIndex> {
const now = Date.now();
if (this.catalogCache && (now - this.lastFetchTime) < this.cacheTtlMs) {
return this.catalogCache;
if (this.appStoreCache && (now - this.lastFetchTime) < this.cacheTtlMs) {
return this.appStoreCache;
}
try {
const catalog = await this.fetchJson('catalog.json') as ICatalog;
if (catalog && catalog.apps && Array.isArray(catalog.apps)) {
this.catalogCache = catalog;
this.lastFetchTime = now;
return catalog;
}
throw new Error('Invalid catalog format');
const resolver = this.createAppStoreResolver();
const appStore = await resolver.getAppStoreIndex();
this.appStoreResolver = resolver;
this.appStoreCache = appStore;
this.lastFetchTime = now;
return appStore;
} catch (error) {
logger.warn(`Failed to fetch remote catalog: ${getErrorMessage(error)}`);
// Return cached if available, otherwise return empty catalog
if (this.catalogCache) {
return this.catalogCache;
logger.warn(`Failed to fetch remote App Store: ${getErrorMessage(error)}`);
if (this.appStoreCache) {
return this.appStoreCache;
}
return { schemaVersion: 1, updatedAt: '', apps: [] };
}
}
/**
* Get the catalog apps list (convenience method for the API)
*/
async getApps(): Promise<ICatalogApp[]> {
const catalog = await this.getCatalog();
return catalog.apps;
public async getApps(): Promise<IAppStoreApp[]> {
return (await this.getAppStore()).apps;
}
/**
* Fetch app metadata (versions list, etc.)
*/
async getAppMeta(appId: string): Promise<IAppMeta> {
public async getAppMeta(appIdArg: string): Promise<IAppStoreAppMeta> {
try {
return await this.fetchJson(`apps/${appId}/app.json`) as IAppMeta;
await this.getAppStore();
return await this.appStoreResolver.getAppMeta(appIdArg);
} catch (error) {
throw new Error(`Failed to fetch metadata for app '${appId}': ${getErrorMessage(error)}`);
throw new Error(`Failed to fetch metadata for app '${appIdArg}': ${getErrorMessage(error)}`);
}
}
/**
* Fetch full config for an app version
*/
async getAppVersionConfig(appId: string, version: string): Promise<IAppVersionConfig> {
public async getAppVersionConfig(
appIdArg: string,
versionArg?: string,
): Promise<IAppStoreVersionConfig> {
try {
const config = await this.fetchJson(`apps/${appId}/versions/${version}/config.json`) as IAppVersionConfig;
this.validateAppVersionConfig(config, `${appId}@${version}`);
return config;
const version = versionArg || (await this.getAppMeta(appIdArg)).latestVersion;
await this.getAppStore();
return await this.appStoreResolver.getAppVersionConfig(appIdArg, version);
} catch (error) {
throw new Error(`Failed to fetch config for ${appId}@${version}: ${getErrorMessage(error)}`);
throw new Error(`Failed to fetch config for ${appIdArg}@${versionArg || 'latest'}: ${getErrorMessage(error)}`);
}
}
async installApp(optionsArg: IAppInstallOptions): Promise<IService> {
public async installApp(optionsArg: IAppStoreInstallOptions): Promise<IService> {
this.validateInstallOptions(optionsArg);
const appMeta = await this.getAppMeta(optionsArg.appId);
const version = optionsArg.version || appMeta.latestVersion;
const config = await this.getAppVersionConfig(optionsArg.appId, version);
const appStoreVersion = config.appStoreVersion || version;
this.assertRuntimeCompatibility(config);
const servicePort = optionsArg.port || config.port;
this.assertValidPort(servicePort, 'install service port');
const volumes = this.normalizeVolumes(config.volumes);
const publishedPorts = optionsArg.publishedPorts || config.publishedPorts || [];
this.validatePublishedPorts(publishedPorts, `${optionsArg.appId}@${version}`);
this.validateAppVersionConfig(
{ ...config, port: servicePort, publishedPorts },
`${optionsArg.appId}@${version} install`,
);
const envVars = this.getAppStoreEnvVars(config, optionsArg.envVars || {});
if (this.requiresTemplateValue(envVars, 'SERVICE_DOMAIN') && !optionsArg.domain) {
@@ -133,105 +164,95 @@ export class AppStoreManager {
enableRedis: Boolean(config.platformRequirements?.redis),
enableMariaDB: Boolean(config.platformRequirements?.mariadb),
appTemplateId: optionsArg.appId,
appTemplateVersion: version,
appTemplateVersion: appStoreVersion,
imageDigest: config.resolvedImageDigest,
});
}
/**
* Compare deployed services against catalog to find those with available upgrades
*/
async getUpgradeableServices(): Promise<IUpgradeableService[]> {
const catalog = await this.getCatalog();
public async getUpgradeableAppStoreServices(): Promise<IUpgradeableAppStoreService[]> {
const appStore = await this.getAppStore();
const services = this.oneboxRef.database.getAllServices();
const upgradeable: IUpgradeableService[] = [];
const upgradeable: IUpgradeableAppStoreService[] = [];
for (const service of services) {
if (!service.appTemplateId || !service.appTemplateVersion) continue;
const catalogApp = catalog.apps.find(a => a.id === service.appTemplateId);
if (!catalogApp) continue;
const appStoreApp = appStore.apps.find((appArg: IAppStoreApp) => appArg.id === service.appTemplateId);
if (!appStoreApp || appStoreApp.latestVersion === service.appTemplateVersion) continue;
if (catalogApp.latestVersion !== service.appTemplateVersion) {
// Check if a migration script exists
const hasMigration = await this.hasMigrationScript(
upgradeable.push({
serviceName: service.name,
appTemplateId: service.appTemplateId,
currentVersion: service.appTemplateVersion,
latestVersion: appStoreApp.latestVersion,
hasMigration: await this.hasMigrationScript(
service.appTemplateId,
service.appTemplateVersion,
catalogApp.latestVersion,
);
upgradeable.push({
serviceName: service.name,
appTemplateId: service.appTemplateId,
currentVersion: service.appTemplateVersion,
latestVersion: catalogApp.latestVersion,
hasMigration,
});
}
appStoreApp.latestVersion,
),
});
}
return upgradeable;
}
/**
* Check if a migration script exists for a specific version transition
*/
async hasMigrationScript(appId: string, fromVersion: string, toVersion: string): Promise<boolean> {
public async hasMigrationScript(
appIdArg: string,
fromVersionArg: string,
toVersionArg: string,
): Promise<boolean> {
try {
const scriptPath = `apps/${appId}/versions/${toVersion}/migrate-from-${fromVersion}.ts`;
await this.fetchText(scriptPath);
await this.fetchText(`apps/${appIdArg}/versions/${toVersionArg}/migrate-from-${fromVersionArg}.ts`);
return true;
} catch {
return false;
}
}
/**
* Execute a migration in a sandboxed Deno child process
*/
async executeMigration(service: IService, fromVersion: string, toVersion: string): Promise<IMigrationResult> {
const appId = service.appTemplateId;
public async executeMigration(
serviceArg: IService,
fromVersionArg: string,
toVersionArg: string,
): Promise<IMigrationResult> {
const appId = serviceArg.appTemplateId;
if (!appId) {
throw new Error('Service has no appTemplateId');
}
// Fetch the migration script
const scriptPath = `apps/${appId}/versions/${toVersion}/migrate-from-${fromVersion}.ts`;
const scriptPath = `apps/${appId}/versions/${toVersionArg}/migrate-from-${fromVersionArg}.ts`;
let scriptContent: string;
try {
scriptContent = await this.fetchText(scriptPath);
} catch {
// No migration script — do a simple config-based upgrade
logger.info(`No migration script for ${appId} ${fromVersion} -> ${toVersion}, using config-only upgrade`);
const config = await this.getAppVersionConfig(appId, toVersion);
logger.info(`No migration script for ${appId} ${fromVersionArg} -> ${toVersionArg}, using config-only upgrade`);
const config = await this.getAppVersionConfig(appId, toVersionArg);
return {
success: true,
image: config.image,
imageDigest: config.resolvedImageDigest,
port: config.port,
volumes: this.normalizeVolumes(config.volumes),
publishedPorts: config.publishedPorts,
envVars: undefined, // Keep existing env vars
envVars: undefined,
warnings: [],
};
}
// Write to temp file
const tempFile = `/tmp/onebox-migration-${crypto.randomUUID()}.ts`;
await Deno.writeTextFile(tempFile, scriptContent);
try {
// Prepare context
const context: IMigrationContext = {
service: {
name: service.name,
image: service.image,
envVars: service.envVars,
port: service.port,
name: serviceArg.name,
image: serviceArg.image,
envVars: serviceArg.envVars,
port: serviceArg.port,
},
fromVersion,
toVersion,
fromVersion: fromVersionArg,
toVersion: toVersionArg,
};
// Execute in sandboxed Deno child process
const cmd = new Deno.Command('deno', {
args: ['run', '--allow-env', '--allow-net=none', '--allow-read=none', '--allow-write=none', tempFile],
stdin: 'piped',
@@ -240,27 +261,22 @@ export class AppStoreManager {
});
const child = cmd.spawn();
// Write context to stdin
const writer = child.stdin.getWriter();
await writer.write(new TextEncoder().encode(JSON.stringify(context)));
await writer.close();
// Read result
const output = await child.output();
const exitCode = output.code;
const stdout = new TextDecoder().decode(output.stdout);
const stderr = new TextDecoder().decode(output.stderr);
if (exitCode !== 0) {
logger.error(`Migration script failed (exit ${exitCode}): ${stderr.substring(0, 500)}`);
if (output.code !== 0) {
logger.error(`Migration script failed (exit ${output.code}): ${stderr.substring(0, 500)}`);
return {
success: false,
warnings: [`Migration script failed: ${stderr.substring(0, 200)}`],
};
}
// Parse result from stdout
try {
const result = JSON.parse(stdout) as IMigrationResult;
result.success = true;
@@ -273,58 +289,46 @@ export class AppStoreManager {
};
}
} finally {
// Cleanup temp file
try {
await Deno.remove(tempFile);
} catch {
// Ignore cleanup errors
// Ignore cleanup errors.
}
}
}
/**
* Apply an upgrade: update image, env vars, recreate container
*/
async applyUpgrade(
serviceName: string,
migrationResult: IMigrationResult,
newVersion: string,
public async applyUpgrade(
serviceNameArg: string,
migrationResultArg: IMigrationResult,
newVersionArg: string,
optionsArg: IAppStoreUpgradeApplyOptions = {},
): Promise<IService> {
const service = this.oneboxRef.database.getServiceByName(serviceName);
const service = this.oneboxRef.database.getServiceByName(serviceNameArg);
if (!service) {
throw new Error(`Service not found: ${serviceName}`);
throw new Error(`Service not found: ${serviceNameArg}`);
}
// Stop the existing container
if (service.containerID && service.status === 'running') {
await this.oneboxRef.services.stopService(serviceName);
}
// Update service record
const updates: Partial<IService> = {
appTemplateVersion: newVersion,
appTemplateVersion: newVersionArg,
};
if (migrationResult.image) {
updates.image = migrationResult.image;
if (migrationResultArg.image) {
updates.image = migrationResultArg.image;
}
if (migrationResult.port) {
updates.port = migrationResult.port;
if (migrationResultArg.imageDigest !== undefined) {
updates.imageDigest = migrationResultArg.imageDigest;
}
if (migrationResult.volumes) {
updates.volumes = migrationResult.volumes;
if (migrationResultArg.port) {
updates.port = migrationResultArg.port;
}
if (migrationResult.publishedPorts) {
updates.publishedPorts = migrationResult.publishedPorts;
if (migrationResultArg.volumes) {
updates.volumes = migrationResultArg.volumes;
}
if (migrationResult.envVars) {
// Merge: migration result provides base, user overrides preserved
const mergedEnvVars = { ...migrationResult.envVars };
// Keep any user-set env vars that aren't in the migration result
if (migrationResultArg.publishedPorts) {
updates.publishedPorts = migrationResultArg.publishedPorts;
}
if (migrationResultArg.envVars) {
const mergedEnvVars = { ...migrationResultArg.envVars };
for (const [key, value] of Object.entries(service.envVars)) {
if (!(key in mergedEnvVars)) {
mergedEnvVars[key] = value;
@@ -333,100 +337,46 @@ export class AppStoreManager {
updates.envVars = mergedEnvVars;
}
this.oneboxRef.database.updateService(service.id!, updates);
const updatedService = await this.oneboxRef.services.updateService(
serviceNameArg,
updates,
{
onProgress: async (progressArg) => {
await optionsArg.onProgress?.(progressArg);
},
},
);
// Pull new image if changed
const newImage = migrationResult.image || service.image;
if (migrationResult.image && migrationResult.image !== service.image) {
await this.oneboxRef.docker.pullImage(newImage);
}
// Recreate and start container
const updatedService = this.oneboxRef.database.getServiceByName(serviceName)!;
// Remove old container
if (service.containerID) {
try {
await this.oneboxRef.docker.removeContainer(service.containerID, true);
} catch {
// Container might already be gone
}
}
// Create new container
const containerID = await this.oneboxRef.docker.createContainer(updatedService);
this.oneboxRef.database.updateService(service.id!, { containerID, status: 'starting' });
// Start container
await this.oneboxRef.docker.startContainer(containerID);
this.oneboxRef.database.updateService(service.id!, { status: 'running' });
logger.success(`Service '${serviceName}' upgraded to template version ${newVersion}`);
return this.oneboxRef.database.getServiceByName(serviceName)!;
logger.success(`Service '${serviceNameArg}' upgraded to App Store version ${newVersionArg}`);
return updatedService;
}
/**
* Fetch JSON from the remote repo
*/
private async fetchJson(path: string): Promise<unknown> {
const url = `${this.repoBaseUrl}/${path}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${url}`);
}
return response.json();
public normalizeVolumes(volumesArg: IAppStoreVersionConfig['volumes'] = []): IServiceVolume[] {
return this.appStoreResolver.normalizeVolumes(volumesArg) as IServiceVolume[];
}
/**
* Fetch text from the remote repo
*/
private async fetchText(path: string): Promise<string> {
const url = `${this.repoBaseUrl}/${path}`;
const response = await fetch(url);
public validateAppVersionConfig(configArg: IAppStoreVersionConfig, labelArg = 'app config'): void {
this.appStoreResolver.validateAppStoreVersionConfig(configArg, labelArg);
}
private createAppStoreResolver(): plugins.servezoneAppstore.AppStoreResolver {
return new plugins.servezoneAppstore.AppStoreResolver({
baseUrl: this.appStoreBaseUrl,
fetch: this.fetchRef,
resolveDockerDigests: this.resolveDockerDigests,
});
}
private async fetchText(pathArg: string): Promise<string> {
const url = `${this.appStoreBaseUrl}/${pathArg}`;
const response = await this.fetchRef(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${url}`);
}
return response.text();
}
public normalizeVolumes(volumesArg: IAppVersionConfig['volumes'] = []): IServiceVolume[] {
return volumesArg.map((volumeArg, indexArg): IAppCatalogVolume => {
if (typeof volumeArg === 'string') {
return { mountPath: volumeArg };
}
return volumeArg;
}).map((volumeArg, indexArg) => {
this.validateVolume(volumeArg, `volume ${indexArg + 1}`);
return volumeArg;
});
}
public validateAppVersionConfig(configArg: IAppVersionConfig, labelArg = 'app config'): void {
if (!configArg || typeof configArg !== 'object') {
throw new Error(`Invalid ${labelArg}: config must be an object`);
}
if (!configArg.image || typeof configArg.image !== 'string') {
throw new Error(`Invalid ${labelArg}: image is required`);
}
if (configArg.image.endsWith(':latest')) {
logger.warn(`App template ${labelArg} uses a mutable ':latest' image tag`);
}
this.assertValidPort(configArg.port, `${labelArg} port`);
for (const envVar of configArg.envVars || []) {
if (!envVar.key || !/^[A-Z_][A-Z0-9_]*$/.test(envVar.key)) {
throw new Error(`Invalid ${labelArg}: env var key '${envVar.key}' is not valid`);
}
if (envVar.value !== undefined && typeof envVar.value !== 'string') {
throw new Error(`Invalid ${labelArg}: env var '${envVar.key}' value must be a string`);
}
}
this.normalizeVolumes(configArg.volumes);
this.validatePublishedPorts(configArg.publishedPorts || [], labelArg);
}
private validateInstallOptions(optionsArg: IAppInstallOptions): void {
private validateInstallOptions(optionsArg: IAppStoreInstallOptions): void {
if (!optionsArg.appId || !/^[a-z0-9][a-z0-9-]*$/.test(optionsArg.appId)) {
throw new Error(`Invalid app id: ${optionsArg.appId}`);
}
@@ -436,66 +386,6 @@ export class AppStoreManager {
if (optionsArg.port !== undefined) {
this.assertValidPort(optionsArg.port, 'install service port');
}
if (optionsArg.publishedPorts) {
this.validatePublishedPorts(optionsArg.publishedPorts, `install options for ${optionsArg.appId}`);
}
}
private validateVolume(volumeArg: IAppCatalogVolume, labelArg: string): void {
if (!volumeArg.mountPath || !volumeArg.mountPath.startsWith('/')) {
throw new Error(`Invalid ${labelArg}: mountPath must be an absolute path`);
}
if (volumeArg.mountPath.includes(':')) {
throw new Error(`Invalid ${labelArg}: mountPath must not contain ':'`);
}
if ((volumeArg.source || volumeArg.name)?.includes(':')) {
throw new Error(`Invalid ${labelArg}: source/name must not contain ':'`);
}
}
private validatePublishedPorts(
publishedPortsArg: IAppVersionConfig['publishedPorts'] = [],
labelArg: string,
): void {
const seenPublishedPorts = new Set<string>();
for (const portArg of publishedPortsArg) {
const protocol = portArg.protocol || 'tcp';
const targetStart = portArg.targetPort;
const targetEnd = portArg.targetPortEnd || targetStart;
const publishedStart = portArg.publishedPort || targetStart;
const publishedEnd = portArg.publishedPortEnd || (publishedStart + (targetEnd - targetStart));
const hostIp = portArg.hostIp || '0.0.0.0';
if (!['tcp', 'udp'].includes(protocol)) {
throw new Error(`Invalid ${labelArg}: published port protocol '${protocol}' is not supported`);
}
this.assertValidPort(targetStart, `${labelArg} targetPort`);
this.assertValidPort(targetEnd, `${labelArg} targetPortEnd`);
this.assertValidPort(publishedStart, `${labelArg} publishedPort`);
this.assertValidPort(publishedEnd, `${labelArg} publishedPortEnd`);
if (targetEnd < targetStart || publishedEnd < publishedStart) {
throw new Error(`Invalid ${labelArg}: published port ranges must be ascending`);
}
if ((targetEnd - targetStart) !== (publishedEnd - publishedStart)) {
throw new Error(`Invalid ${labelArg}: target and published port ranges must have the same size`);
}
if ((targetEnd - targetStart) > 1000) {
throw new Error(`Invalid ${labelArg}: published port ranges may not exceed 1001 ports`);
}
for (let offset = 0; offset <= targetEnd - targetStart; offset++) {
const publishedPort = publishedStart + offset;
const publishedKey = `${hostIp}/${protocol}/${publishedPort}`;
const wildcardKey = `0.0.0.0/${protocol}/${publishedPort}`;
const conflictsWithWildcard = hostIp === '0.0.0.0'
? Array.from(seenPublishedPorts).some((keyArg) => keyArg.endsWith(`/${protocol}/${publishedPort}`))
: seenPublishedPorts.has(wildcardKey);
if (seenPublishedPorts.has(publishedKey) || conflictsWithWildcard) {
throw new Error(`Invalid ${labelArg}: duplicate published port ${hostIp}:${publishedPort}/${protocol}`);
}
seenPublishedPorts.add(publishedKey);
}
}
}
private assertValidPort(portArg: number, labelArg: string): void {
@@ -505,7 +395,7 @@ export class AppStoreManager {
}
private getAppStoreEnvVars(
configArg: IAppVersionConfig,
configArg: IAppStoreVersionConfig,
overridesArg: Record<string, string>,
): Record<string, string> {
const envVars: Record<string, string> = {};
@@ -519,14 +409,10 @@ export class AppStoreManager {
envVars[envVar.key] = value;
}
for (const [key, value] of Object.entries(overridesArg)) {
envVars[key] = value;
}
Object.assign(envVars, overridesArg);
if (missingRequiredEnvVars.length > 0) {
throw new Error(
`Missing required app env var(s): ${missingRequiredEnvVars.join(', ')}`,
);
throw new Error(`Missing required app env var(s): ${missingRequiredEnvVars.join(', ')}`);
}
return envVars;
@@ -536,7 +422,7 @@ export class AppStoreManager {
return Object.values(envVarsArg).some((value) => value.includes(`\${${templateNameArg}}`));
}
private assertRuntimeCompatibility(configArg: IAppVersionConfig): void {
private assertRuntimeCompatibility(configArg: IAppStoreVersionConfig): void {
if (!configArg.minOneboxVersion) return;
if (this.compareVersions(projectInfo.version, configArg.minOneboxVersion) < 0) {
throw new Error(
+45 -21
View File
@@ -14,6 +14,12 @@ type TExpandedPublishedPort = Required<Pick<
'targetPort' | 'publishedPort' | 'protocol' | 'hostIp'
>>;
export interface IInteractiveContainerExec {
stream: plugins.nodeStream.Duplex;
close: () => Promise<void>;
inspect: () => Promise<{ ExitCode?: number | null; Running?: boolean }>;
}
export class OneboxDockerManager {
private dockerClient: InstanceType<typeof plugins.docker.Docker> | null = null;
private networkName = 'onebox-network';
@@ -1128,32 +1134,37 @@ export class OneboxDockerManager {
/**
* Execute a command in a running container
*/
private async resolveContainer(containerID: string): Promise<any> {
let container: any = null;
try {
container = await this.dockerClient!.getContainerById(containerID);
} catch {
// Not a direct container ID — try Swarm service lookup.
}
if (!container) {
const serviceContainerId = await this.getContainerIdForService(containerID);
if (serviceContainerId) {
try {
container = await this.dockerClient!.getContainerById(serviceContainerId);
} catch {
// Service container also not found.
}
}
}
if (!container) {
throw new Error(`Container not found: ${containerID}`);
}
return container;
}
async execInContainer(
containerID: string,
cmd: string[]
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
try {
let container: any = null;
try {
container = await this.dockerClient!.getContainerById(containerID);
} catch {
// Not a direct container ID — try Swarm service lookup
}
if (!container) {
const serviceContainerId = await this.getContainerIdForService(containerID);
if (serviceContainerId) {
try {
container = await this.dockerClient!.getContainerById(serviceContainerId);
} catch {
// Service container also not found
}
}
}
if (!container) {
throw new Error(`Container not found: ${containerID}`);
}
const container = await this.resolveContainer(containerID);
const { stream, inspect } = await container.exec(cmd, {
attachStdout: true,
@@ -1190,6 +1201,19 @@ export class OneboxDockerManager {
}
}
async startInteractiveExecInContainer(
containerID: string,
cmd: string[],
): Promise<IInteractiveContainerExec> {
const container = await this.resolveContainer(containerID);
return await container.exec(cmd, {
tty: true,
attachStdin: true,
attachStdout: true,
attachStderr: true,
});
}
/**
* Create a platform service container (MongoDB, MinIO, etc.)
* Platform containers are long-running infrastructure services
+102 -17
View File
@@ -1,11 +1,17 @@
import * as plugins from '../plugins.ts';
import { logger } from '../logging.ts';
import { getErrorMessage } from '../utils/error.ts';
import { normalizeHostname } from '../utils/domain.ts';
import { OneboxDatabase } from './database.ts';
import type { IDomain, IService } from '../types.ts';
import type { TDcRouterMode } from './managed-dcrouter.ts';
const adminUiRouteName = 'onebox-admin-ui';
type TWorkHosterType = 'onebox';
type TExternalGatewayRoute = Pick<IService, 'id' | 'name' | 'domain' | 'status'> & {
domain: string;
};
interface IExternalGatewayConfig {
url: string;
@@ -137,15 +143,34 @@ export class ExternalGatewayManager {
}
public async syncServiceRoutes(): Promise<void> {
const adminUiRoute = this.getAdminUiRoute();
const adminUiDomain = adminUiRoute?.domain;
const services = this.database.getAllServices()
.filter((service) => service.domain && service.status === 'running');
.filter((service) =>
service.domain && service.status === 'running' && service.domain !== adminUiDomain
);
const activeHostnames = new Set(services.map((service) => service.domain!));
if (adminUiRoute) {
activeHostnames.add(adminUiRoute.domain);
try {
await this.syncGatewayRoute(adminUiRoute);
} catch (error) {
logger.warn(
`Failed to sync external gateway route for ${adminUiRoute.domain}: ${
getErrorMessage(error)
}`,
);
}
}
for (const service of services) {
try {
await this.syncServiceRoute(service);
} catch (error) {
logger.warn(`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`);
logger.warn(
`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`,
);
}
}
@@ -158,6 +183,7 @@ export class ExternalGatewayManager {
for (const record of records) {
if (!record.hostname || activeHostnamesArg.has(record.hostname)) continue;
if (this.shouldPreserveUnconfiguredAdminUiRecord(record)) continue;
if (!record.routeId && !record.appId && !record.serviceName) continue;
staleRecordsByHostname.set(record.hostname, record);
}
@@ -169,7 +195,11 @@ export class ExternalGatewayManager {
domain: record.hostname,
});
} catch (error) {
logger.warn(`Failed to delete stale external gateway route for ${record.hostname}: ${getErrorMessage(error)}`);
logger.warn(
`Failed to delete stale external gateway route for ${record.hostname}: ${
getErrorMessage(error)
}`,
);
}
}
}
@@ -289,40 +319,72 @@ export class ExternalGatewayManager {
public async syncServiceRoute(service: IService): Promise<void> {
if (!service.domain) return;
await this.syncGatewayRoute({
id: service.id,
name: service.name,
domain: service.domain,
status: service.status,
});
}
public async syncAdminUiRoute(): Promise<void> {
const route = this.getAdminUiRoute();
if (!route) return;
await this.syncGatewayRoute(route);
}
public async deleteAdminUiRoute(domain: string): Promise<void> {
const normalizedDomain = normalizeHostname(domain);
if (!normalizedDomain) return;
await this.deleteServiceRoute({
name: adminUiRouteName,
domain: normalizedDomain,
});
}
private async syncGatewayRoute(route: TExternalGatewayRoute): Promise<void> {
if (!route.domain) return;
const config = await this.getConfig({ requireTarget: true });
if (!config) return;
const result = await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
'syncGatewayClientRoute',
{
ownership: this.buildGatewayClientOwnership(service, service.domain, config),
route: this.buildRoute(service, config),
enabled: service.status === 'running',
ownership: this.buildGatewayClientOwnership(route, route.domain, config),
route: this.buildRoute(route, config),
enabled: route.status === 'running',
},
config,
).catch(async () => {
return await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
'syncWorkAppRoute',
{
ownership: this.buildOwnership(service, service.domain!, config),
route: this.buildRoute(service, config),
enabled: service.status === 'running',
ownership: this.buildOwnership(route, route.domain, config),
route: this.buildRoute(route, config),
enabled: route.status === 'running',
},
config,
);
});
if (!result.success) {
throw new Error(result.message || `dcrouter route sync failed for ${service.domain}`);
throw new Error(result.message || `dcrouter route sync failed for ${route.domain}`);
}
logger.success(`External gateway route ${result.action || 'synced'} for ${service.domain}`);
await this.importCertificateForDomain(service.domain).catch((error) => {
logger.debug(`External gateway certificate import skipped for ${service.domain}: ${getErrorMessage(error)}`);
logger.success(`External gateway route ${result.action || 'synced'} for ${route.domain}`);
await this.importCertificateForDomain(route.domain).catch((error) => {
logger.debug(
`External gateway certificate import skipped for ${route.domain}: ${
getErrorMessage(error)
}`,
);
});
}
public async deleteServiceRoute(service: Pick<IService, 'id' | 'name' | 'domain'>): Promise<void> {
public async deleteServiceRoute(
service: Pick<IService, 'id' | 'name' | 'domain'>,
): Promise<void> {
if (!service.domain) return;
const config = await this.getConfig({ requireTarget: false });
@@ -536,12 +598,35 @@ export class ExternalGatewayManager {
return ownership;
}
private buildRoute(service: IService, config: IExternalGatewayConfig): IDcRouterRouteConfig {
private getAdminUiRoute(): TExternalGatewayRoute | null {
const domain = normalizeHostname(this.database.getSetting('adminUiDomain') || '');
if (!domain) return null;
return {
name: this.routeName(service.domain!),
id: 0,
name: adminUiRouteName,
domain,
status: 'running',
};
}
private isAdminUiRecord(record: IGatewayDnsRecord): boolean {
const ownerName = record.serviceName || record.appId;
return ownerName === adminUiRouteName || ownerName === 'onebox';
}
private shouldPreserveUnconfiguredAdminUiRecord(record: IGatewayDnsRecord): boolean {
return this.database.getSetting('adminUiDomain') === null && this.isAdminUiRecord(record);
}
private buildRoute(
route: TExternalGatewayRoute,
config: IExternalGatewayConfig,
): IDcRouterRouteConfig {
return {
name: this.routeName(route.domain),
match: {
ports: [443],
domains: [service.domain!],
domains: [route.domain],
},
action: {
type: 'forward',
+9
View File
@@ -5,6 +5,7 @@
*/
import { logger } from '../logging.ts';
import { projectInfo } from '../info.ts';
import { getErrorMessage } from '../utils/error.ts';
import { hashPassword } from '../utils/auth.ts';
import { OneboxDatabase } from './database.ts';
@@ -26,6 +27,7 @@ import { BackupManager } from './backup-manager.ts';
import { BackupScheduler } from './backup-scheduler.ts';
import { ExternalGatewayManager } from './external-gateway.ts';
import { ManagedDcRouterManager } from './managed-dcrouter.ts';
import { OneboxUpdateManager } from './update-manager.ts';
import { OpsServer } from '../opsserver/index.ts';
export class Onebox {
@@ -48,6 +50,7 @@ export class Onebox {
public backupScheduler: BackupScheduler;
public managedDcRouter: ManagedDcRouterManager;
public externalGateway: ExternalGatewayManager;
public updateManager: OneboxUpdateManager;
public opsServer: OpsServer;
private initialized = false;
@@ -93,6 +96,7 @@ export class Onebox {
// Initialize optional dcrouter gateway integration
this.managedDcRouter = new ManagedDcRouterManager(this);
this.externalGateway = new ExternalGatewayManager(this);
this.updateManager = new OneboxUpdateManager();
// Initialize OpsServer (TypedRequest-based server)
this.opsServer = new OpsServer(this);
@@ -305,6 +309,7 @@ export class Onebox {
const proxyStatus = this.reverseProxy.getStatus();
const dnsConfigured = this.dns.isConfigured();
const sslConfigured = this.ssl.isConfigured();
const oneboxUpdate = await this.updateManager.getUpdateStatus();
const services = this.services.listServices();
const runningServices = services.filter((s) => s.status === 'running').length;
@@ -407,6 +412,10 @@ export class Onebox {
}
return {
onebox: {
version: projectInfo.version,
update: oneboxUpdate,
},
docker: {
running: dockerRunning,
version: dockerRunning ? await this.docker.getDockerVersion() : null,
+43 -1
View File
@@ -10,15 +10,20 @@
import { logger } from '../logging.ts';
import { getErrorMessage } from '../utils/error.ts';
import { normalizeHostname } from '../utils/domain.ts';
import { OneboxDatabase } from './database.ts';
import { SmartProxyManager } from './smartproxy.ts';
const adminUiRouteName = 'onebox-admin-ui';
const adminUiPort = 3000;
interface IProxyRoute {
domain: string;
targetHost: string;
targetPort: number;
serviceId: number;
serviceId?: number;
serviceName?: string;
routeType: 'service' | 'admin-ui';
}
export class OneboxReverseProxy {
@@ -112,6 +117,7 @@ export class OneboxReverseProxy {
targetPort,
serviceId,
serviceName,
routeType: 'service',
};
this.routes.set(domain, route);
@@ -127,6 +133,25 @@ export class OneboxReverseProxy {
}
}
async addAdminUiRoute(domain: string): Promise<void> {
const normalizedDomain = normalizeHostname(domain);
if (!normalizedDomain) return;
const targetHost = this.getAdminUiTargetHost();
const route: IProxyRoute = {
domain: normalizedDomain,
targetHost,
targetPort: adminUiPort,
serviceName: adminUiRouteName,
routeType: 'admin-ui',
};
this.routes.set(normalizedDomain, route);
const upstream = `${targetHost}:${adminUiPort}`;
await this.smartProxy.addRoute(normalizedDomain, upstream);
logger.success(`Added Admin UI proxy route: ${normalizedDomain} -> ${upstream}`);
}
/**
* Remove a route
*/
@@ -166,6 +191,11 @@ export class OneboxReverseProxy {
}
}
const adminUiDomain = this.getAdminUiDomain();
if (adminUiDomain) {
await this.addAdminUiRoute(adminUiDomain);
}
logger.success(`Loaded ${this.routes.size} proxy routes`);
} catch (error) {
logger.error(`Failed to reload routes: ${getErrorMessage(error)}`);
@@ -173,6 +203,18 @@ export class OneboxReverseProxy {
}
}
private getAdminUiDomain(): string {
return normalizeHostname(this.database.getSetting('adminUiDomain') || '');
}
private getAdminUiTargetHost(): string {
const serverIP = this.database.getSetting('serverIP');
if (!serverIP) {
logger.warn('serverIP is not configured; Admin UI proxy route will use host.docker.internal');
}
return serverIP || 'host.docker.internal';
}
/**
* Add TLS certificate for a domain
* Sends PEM content to SmartProxy via Admin API
+49 -1
View File
@@ -11,6 +11,26 @@ import { OneboxDatabase } from './database.ts';
import { OneboxDockerManager } from './docker.ts';
import type { PlatformServicesManager } from './platform-services/index.ts';
export type TServiceUpdateProgressStep =
| 'stopping'
| 'pulling-image'
| 'updating-record'
| 'removing-container'
| 'creating-container'
| 'starting'
| 'restoring-route'
| 'syncing-gateway'
| 'complete';
export interface IServiceUpdateProgress {
step: TServiceUpdateProgressStep;
message: string;
}
export interface IServiceUpdateOptions {
onProgress?: (progressArg: IServiceUpdateProgress) => void | Promise<void>;
}
export class OneboxServicesManager {
private oneboxRef: any; // Will be Onebox instance
private database: OneboxDatabase;
@@ -107,6 +127,7 @@ export class OneboxServicesManager {
registryRepository: options.useOneboxRegistry ? options.name : undefined,
registryImageTag: options.registryImageTag || 'latest',
autoUpdateOnPush: options.autoUpdateOnPush,
imageDigest: options.imageDigest,
// Platform requirements
platformRequirements,
// App Store template tracking
@@ -582,9 +603,15 @@ export class OneboxServicesManager {
envVars?: Record<string, string>;
volumes?: IService['volumes'];
publishedPorts?: IService['publishedPorts'];
}
imageDigest?: string;
appTemplateVersion?: string;
},
optionsArg: IServiceUpdateOptions = {},
): Promise<IService> {
try {
const emitProgress = async (step: TServiceUpdateProgressStep, message: string) => {
await optionsArg.onProgress?.({ step, message });
};
const service = this.database.getServiceByName(name);
if (!service) {
throw new Error(`Service not found: ${name}`);
@@ -598,6 +625,7 @@ export class OneboxServicesManager {
// Stop the container if running
if (wasRunning && oldContainerID) {
logger.info(`Stopping service ${name} for updates...`);
await emitProgress('stopping', `Stopping ${name} before updating its container`);
try {
await this.docker.stopContainer(oldContainerID);
} catch (error) {
@@ -608,10 +636,12 @@ export class OneboxServicesManager {
// Pull new image if changed
if (updates.image && updates.image !== service.image) {
logger.info(`Pulling new image: ${updates.image}`);
await emitProgress('pulling-image', `Pulling image ${updates.image}`);
await this.docker.pullImage(updates.image, updates.registry || service.registry);
}
// Update service in database
await emitProgress('updating-record', `Updating service record for ${name}`);
const updateData: any = {
updatedAt: Date.now(),
};
@@ -622,6 +652,8 @@ export class OneboxServicesManager {
if (updates.envVars !== undefined) updateData.envVars = updates.envVars;
if (updates.volumes !== undefined) updateData.volumes = updates.volumes;
if (updates.publishedPorts !== undefined) updateData.publishedPorts = updates.publishedPorts;
if (updates.imageDigest !== undefined) updateData.imageDigest = updates.imageDigest;
if (updates.appTemplateVersion !== undefined) updateData.appTemplateVersion = updates.appTemplateVersion;
this.database.updateService(service.id!, updateData);
@@ -630,6 +662,7 @@ export class OneboxServicesManager {
// Remove old container
if (oldContainerID) {
await emitProgress('removing-container', `Removing old container for ${name}`);
try {
await this.docker.removeContainer(oldContainerID, true);
logger.info(`Removed old container for ${name}`);
@@ -640,6 +673,7 @@ export class OneboxServicesManager {
// Create new container with updated config
logger.info(`Creating new container for ${name}...`);
await emitProgress('creating-container', `Creating replacement container for ${name}`);
const containerID = await this.docker.createContainer(updatedService);
this.database.updateService(service.id!, { containerID });
@@ -673,6 +707,7 @@ export class OneboxServicesManager {
// Restart the container if it was running
if (wasRunning) {
logger.info(`Starting updated service ${name}...`);
await emitProgress('starting', `Starting updated service ${name}`);
this.database.updateService(service.id!, { status: 'starting' });
await this.docker.startContainer(containerID);
this.database.updateService(service.id!, { status: 'running' });
@@ -684,8 +719,21 @@ export class OneboxServicesManager {
const refreshedService = this.database.getServiceByName(name)!;
if (refreshedService.domain && refreshedService.status === 'running') {
await emitProgress('restoring-route', `Restoring route ${refreshedService.domain} -> ${refreshedService.port}`);
try {
await this.oneboxRef.reverseProxy.addRoute(
refreshedService.id!,
refreshedService.domain,
refreshedService.port,
);
} catch (error) {
logger.warn(`Failed to restore reverse proxy route for ${refreshedService.domain}: ${getErrorMessage(error)}`);
throw error;
}
await emitProgress('syncing-gateway', `Syncing external gateway route for ${refreshedService.domain}`);
await this.syncExternalGatewayRoute(refreshedService);
}
await emitProgress('complete', `Service ${name} update completed`);
await this.broadcastServiceUpdate(name, 'updated');
return refreshedService;
} catch (error) {
+6 -4
View File
@@ -10,7 +10,7 @@ import { logger } from '../logging.ts';
import { getErrorMessage } from '../utils/error.ts';
const SMARTPROXY_SERVICE_NAME = 'onebox-smartproxy';
const LEGACY_CADDY_SERVICE_NAME = 'onebox-caddy';
const LEGACY_REVERSE_PROXY_SERVICE_NAME = 'onebox-caddy';
const SMARTPROXY_IMAGE = 'code.foss.global/host.today/ht-docker-smartproxy:latest';
const SMARTPROXY_ADMIN_CONTAINER_PORT = 3000;
const SMARTPROXY_HTTP_CONTAINER_PORT = 80;
@@ -102,10 +102,12 @@ export class SmartProxyManager {
logger.info('Starting SmartProxy Docker service...');
const legacyService = await this.getExistingService(LEGACY_CADDY_SERVICE_NAME);
const legacyService = await this.getExistingService(LEGACY_REVERSE_PROXY_SERVICE_NAME);
if (legacyService) {
logger.info('Legacy Caddy service exists, removing it before SmartProxy startup...');
await this.removeService(LEGACY_CADDY_SERVICE_NAME);
logger.info(
`Legacy reverse proxy service ${LEGACY_REVERSE_PROXY_SERVICE_NAME} exists, removing it before SmartProxy startup...`,
);
await this.removeService(LEGACY_REVERSE_PROXY_SERVICE_NAME);
await new Promise((resolve) => setTimeout(resolve, 2000));
}
+234
View File
@@ -0,0 +1,234 @@
import { logger } from '../logging.ts';
import { projectInfo } from '../info.ts';
import { getErrorMessage } from '../utils/error.ts';
import * as interfaces from '../../ts_interfaces/index.ts';
const ONEBOX_REPOSITORY_URL = 'https://code.foss.global/serve.zone/onebox';
const ONEBOX_LATEST_RELEASE_API_URL =
'https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/latest';
const ONEBOX_INSTALL_SCRIPT_URL = `${ONEBOX_REPOSITORY_URL}/raw/branch/main/install.sh`;
const ONEBOX_CHANGELOG_URL = `${ONEBOX_REPOSITORY_URL}/src/branch/main/changelog.md`;
const UPGRADE_LOG_PATH = '/var/log/onebox-upgrade.log';
interface IGiteaReleaseResponse {
tag_name?: unknown;
html_url?: unknown;
}
interface IParsedRelease {
tagName: string;
releaseUrl: string;
}
export class OneboxUpdateManager {
private cachedStatus: interfaces.data.IOneboxUpdateStatus | null = null;
private cachedStatusExpiresAt = 0;
private upgradeStartedAt = 0;
private readonly statusCacheTtlMs = 5 * 60 * 1000;
public async getUpdateStatus(
optionsArg: { force?: boolean } = {},
): Promise<interfaces.data.IOneboxUpdateStatus> {
const now = Date.now();
if (!optionsArg.force && this.cachedStatus && this.cachedStatusExpiresAt > now) {
return this.cachedStatus;
}
const status = await this.fetchUpdateStatus();
this.cachedStatus = status;
this.cachedStatusExpiresAt = now + this.statusCacheTtlMs;
return status;
}
public async startDetachedUpgrade(): Promise<interfaces.data.IOneboxUpgradeStartResult> {
this.assertRoot();
const status = await this.getUpdateStatus({ force: true });
this.assertUpdateCheckSucceeded(status);
const targetVersion = status.latestVersion || status.currentVersion;
if (!status.updateAvailable) {
return {
accepted: false,
currentVersion: status.currentVersion,
targetVersion,
message: 'Onebox is already up to date.',
};
}
if (this.upgradeStartedAt && Date.now() - this.upgradeStartedAt < 10 * 60 * 1000) {
return {
accepted: false,
currentVersion: status.currentVersion,
targetVersion,
message: 'A Onebox upgrade has already been started.',
logPath: UPGRADE_LOG_PATH,
};
}
const unitName = `onebox-upgrade-${Date.now()}`;
const command = new Deno.Command('systemd-run', {
args: [
'--unit',
unitName,
'--description',
`Onebox upgrade to ${targetVersion}`,
'--collect',
'--property=Type=oneshot',
'--setenv=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'bash',
'-lc',
this.createDetachedUpgradeScript(),
],
stdin: 'null',
stdout: 'piped',
stderr: 'piped',
});
const result = await command.output();
if (!result.success) {
const stderr = new TextDecoder().decode(result.stderr).trim();
const stdout = new TextDecoder().decode(result.stdout).trim();
throw new Error(
`Failed to start Onebox upgrade systemd unit: ${
stderr || stdout || `exit code ${result.code}`
}`,
);
}
this.upgradeStartedAt = Date.now();
logger.info(`Started Onebox upgrade systemd unit ${unitName}`);
return {
accepted: true,
currentVersion: status.currentVersion,
targetVersion,
message: 'Onebox upgrade started. The service will restart automatically.',
unitName,
logPath: UPGRADE_LOG_PATH,
};
}
public async runUpgradeForeground(
statusArg?: interfaces.data.IOneboxUpdateStatus,
): Promise<interfaces.data.IOneboxUpgradeStartResult> {
this.assertRoot();
const status = statusArg || (await this.getUpdateStatus({ force: true }));
this.assertUpdateCheckSucceeded(status);
const targetVersion = status.latestVersion || status.currentVersion;
if (!status.updateAvailable) {
return {
accepted: false,
currentVersion: status.currentVersion,
targetVersion,
message: 'Onebox is already up to date.',
};
}
const installCommand = new Deno.Command('bash', {
args: ['-c', `set -o pipefail; curl -fsSL ${ONEBOX_INSTALL_SCRIPT_URL} | bash`],
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
const installResult = await installCommand.output();
if (!installResult.success) {
throw new Error('Upgrade failed');
}
return {
accepted: true,
currentVersion: status.currentVersion,
targetVersion,
message: `Upgraded to ${targetVersion}`,
};
}
private async fetchUpdateStatus(): Promise<interfaces.data.IOneboxUpdateStatus> {
const currentVersion = this.normalizeVersion(projectInfo.version);
const checkedAt = Date.now();
try {
const release = await this.fetchLatestRelease();
const latestVersion = this.normalizeVersion(release.tagName);
return {
currentVersion,
latestVersion,
updateAvailable: currentVersion !== latestVersion,
checkedAt,
releaseUrl: release.releaseUrl,
changelogUrl: ONEBOX_CHANGELOG_URL,
};
} catch (error) {
return {
currentVersion,
latestVersion: null,
updateAvailable: false,
checkedAt,
releaseUrl: `${ONEBOX_REPOSITORY_URL}/releases`,
changelogUrl: ONEBOX_CHANGELOG_URL,
error: getErrorMessage(error),
};
}
}
private async fetchLatestRelease(): Promise<IParsedRelease> {
const abortController = new AbortController();
const timeoutId = setTimeout(() => abortController.abort(), 5000);
try {
const response = await fetch(ONEBOX_LATEST_RELEASE_API_URL, {
headers: { accept: 'application/json' },
signal: abortController.signal,
});
if (!response.ok) {
throw new Error(`Failed to fetch latest release: HTTP ${response.status}`);
}
const release = await response.json() as IGiteaReleaseResponse;
if (typeof release.tag_name !== 'string' || !release.tag_name) {
throw new Error('Latest release response does not include a tag name');
}
const tagName = release.tag_name;
const releaseUrl = typeof release.html_url === 'string' && release.html_url
? release.html_url
: `${ONEBOX_REPOSITORY_URL}/releases/tag/${this.normalizeVersion(tagName)}`;
return { tagName, releaseUrl };
} finally {
clearTimeout(timeoutId);
}
}
private assertRoot(): void {
if (Deno.uid() !== 0) {
throw new Error('Onebox upgrades must be started as root. Try: sudo onebox upgrade');
}
}
private assertUpdateCheckSucceeded(statusArg: interfaces.data.IOneboxUpdateStatus): void {
if (statusArg.error) {
throw new Error(`Cannot determine latest Onebox release: ${statusArg.error}`);
}
}
private normalizeVersion(versionArg: string): string {
const trimmedVersion = versionArg.trim();
return trimmedVersion.startsWith('v') ? trimmedVersion : `v${trimmedVersion}`;
}
private createDetachedUpgradeScript(): string {
return `
set -e
set -o pipefail
mkdir -p /var/log
{
echo "==== Onebox upgrade started $(date -Is) ===="
sleep 2
curl -fsSL ${ONEBOX_INSTALL_SCRIPT_URL} | bash
echo "==== Onebox upgrade finished $(date -Is) ===="
} >> ${UPGRADE_LOG_PATH} 2>&1
`;
}
}
+16 -44
View File
@@ -8,7 +8,10 @@ import { getErrorMessage } from './utils/error.ts';
import { Onebox } from './classes/onebox.ts';
import { OneboxDaemon } from './classes/daemon.ts';
import { OneboxSystemd } from './classes/systemd.ts';
import type { IAppVersionConfig } from './classes/appstore-types.ts';
import { OneboxUpdateManager } from './classes/update-manager.ts';
import type * as servezoneInterfaces from '@serve.zone/interfaces';
type IAppStoreVersionConfig = servezoneInterfaces.appstore.IAppStoreVersionConfig;
export async function runCli(): Promise<void> {
const args = Deno.args;
@@ -500,60 +503,29 @@ async function handleUpgradeCommand(): Promise<void> {
logger.info('Checking for updates...');
try {
// Get current version
const currentVersion = projectInfo.version;
const updateManager = new OneboxUpdateManager();
const status = await updateManager.getUpdateStatus({ force: true });
if (status.error) {
throw new Error(status.error);
}
// Fetch latest version from Gitea API
const apiUrl = 'https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/latest';
const curlCmd = new Deno.Command('curl', {
args: ['-sSL', apiUrl],
stdout: 'piped',
stderr: 'piped',
});
const curlResult = await curlCmd.output();
const response = new TextDecoder().decode(curlResult.stdout);
const release = JSON.parse(response);
const latestVersion = release.tag_name as string; // e.g., "v1.11.0"
// Normalize versions for comparison (ensure both have "v" prefix)
const normalizedCurrent = currentVersion.startsWith('v')
? currentVersion
: `v${currentVersion}`;
const normalizedLatest = latestVersion.startsWith('v')
? latestVersion
: `v${latestVersion}`;
console.log(` Current version: ${normalizedCurrent}`);
console.log(` Latest version: ${normalizedLatest}`);
console.log(` Current version: ${status.currentVersion}`);
console.log(` Latest version: ${status.latestVersion}`);
console.log('');
// Compare normalized versions
if (normalizedCurrent === normalizedLatest) {
if (!status.updateAvailable) {
logger.success('Already up to date!');
return;
}
logger.info(`New version available: ${latestVersion}`);
logger.info(`New version available: ${status.latestVersion}`);
logger.info('Downloading and installing...');
console.log('');
// Download and run the install script
const installUrl = 'https://code.foss.global/serve.zone/onebox/raw/branch/main/install.sh';
const installCmd = new Deno.Command('bash', {
args: ['-c', `curl -sSL ${installUrl} | bash`],
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
const installResult = await installCmd.output();
if (!installResult.success) {
logger.error('Upgrade failed');
Deno.exit(1);
}
const upgrade = await updateManager.runUpgradeForeground(status);
console.log('');
logger.success(`Upgraded to ${latestVersion}`);
logger.success(upgrade.message);
} catch (error) {
logger.error(`Upgrade failed: ${getErrorMessage(error)}`);
Deno.exit(1);
@@ -621,7 +593,7 @@ function parseEnvArgs(args: string[]): Record<string, string> {
}
function getAppStoreEnvVars(
configArg: IAppVersionConfig,
configArg: IAppStoreVersionConfig,
overridesArg: Record<string, string>,
): Record<string, string> {
const envVars: Record<string, string> = {};
@@ -3,7 +3,7 @@ import type { TQueryFunction } from '../types.ts';
export class Migration015SmartProxyPlatformService extends BaseMigration {
readonly version = 15;
readonly description = 'Rename Caddy platform service to SmartProxy';
readonly description = 'Rename legacy reverse proxy platform service to SmartProxy';
up(query: TQueryFunction): void {
query(
+227 -49
View File
@@ -3,20 +3,209 @@ import { logger } from '../../logging.ts';
import type { OpsServer } from '../classes.opsserver.ts';
import * as interfaces from '../../../ts_interfaces/index.ts';
import { requireAdminIdentity } from '../helpers/guards.ts';
import { getErrorMessage } from '../../utils/error.ts';
type IAppStoreUpgradeOperation = interfaces.requests.IAppStoreUpgradeOperation;
type TAppStoreUpgradeStep = interfaces.requests.TAppStoreUpgradeStep;
export class AppStoreHandler {
public typedrouter = new plugins.typedrequest.TypedRouter();
private upgradeOperations = new Map<string, IAppStoreUpgradeOperation>();
constructor(private opsServerRef: OpsServer) {
this.opsServerRef.typedrouter.addTypedRouter(this.typedrouter);
this.registerHandlers();
}
private getUpgradeOperations(): IAppStoreUpgradeOperation[] {
return Array.from(this.upgradeOperations.values())
.sort((a, b) => b.startedAt - a.startedAt)
.slice(0, 25);
}
private getRunningUpgrade(serviceNameArg: string): IAppStoreUpgradeOperation | null {
for (const operation of this.upgradeOperations.values()) {
if (operation.serviceName === serviceNameArg && operation.status === 'running') {
return operation;
}
}
return null;
}
private async createUpgradeOperation(
serviceNameArg: string,
targetVersionArg: string,
): Promise<IAppStoreUpgradeOperation> {
const existingRunning = this.getRunningUpgrade(serviceNameArg);
if (existingRunning) {
throw new plugins.typedrequest.TypedResponseError(
`An upgrade is already running for ${serviceNameArg}`,
);
}
const existingService = this.opsServerRef.oneboxRef.database.getServiceByName(serviceNameArg);
if (!existingService) {
throw new plugins.typedrequest.TypedResponseError(`Service not found: ${serviceNameArg}`);
}
if (!existingService.appTemplateId) {
throw new plugins.typedrequest.TypedResponseError('Service was not deployed from an app template');
}
if (!existingService.appTemplateVersion) {
throw new plugins.typedrequest.TypedResponseError('Service has no tracked template version');
}
const now = Date.now();
const operation: IAppStoreUpgradeOperation = {
id: crypto.randomUUID(),
serviceName: existingService.name,
appTemplateId: existingService.appTemplateId,
fromVersion: existingService.appTemplateVersion,
targetVersion: targetVersionArg,
status: 'running',
step: 'queued',
progressLines: [`Queued upgrade ${existingService.appTemplateVersion} -> ${targetVersionArg}`],
warnings: [],
startedAt: now,
updatedAt: now,
};
this.upgradeOperations.set(operation.id, operation);
await this.pushUpgradeProgress(operation);
return operation;
}
private async updateUpgradeOperation(
operationIdArg: string,
stepArg: TAppStoreUpgradeStep,
messageArg: string,
updatesArg: Partial<IAppStoreUpgradeOperation> = {},
): Promise<IAppStoreUpgradeOperation> {
const existing = this.upgradeOperations.get(operationIdArg);
if (!existing) {
throw new Error(`Upgrade operation not found: ${operationIdArg}`);
}
const nextOperation: IAppStoreUpgradeOperation = {
...existing,
...updatesArg,
step: stepArg,
updatedAt: Date.now(),
progressLines: [...existing.progressLines, messageArg].slice(-200),
};
this.upgradeOperations.set(operationIdArg, nextOperation);
await this.pushUpgradeProgress(nextOperation);
return nextOperation;
}
private async pushUpgradeProgress(operationArg: IAppStoreUpgradeOperation): Promise<void> {
await this.opsServerRef.pushDashboardEvent('pushAppStoreUpgradeProgress', {
operation: operationArg,
});
}
private async performUpgrade(operationIdArg: string): Promise<interfaces.data.IService> {
let operation = this.upgradeOperations.get(operationIdArg);
if (!operation) {
throw new Error(`Upgrade operation not found: ${operationIdArg}`);
}
try {
operation = await this.updateUpgradeOperation(
operation.id,
'validating',
`Validating ${operation.serviceName} for App Store upgrade`,
);
const existingService = this.opsServerRef.oneboxRef.database.getServiceByName(operation.serviceName);
if (!existingService) {
throw new Error(`Service not found: ${operation.serviceName}`);
}
if (!existingService.appTemplateId || !existingService.appTemplateVersion) {
throw new Error('Service is missing App Store template metadata');
}
logger.info(
`Upgrading service '${operation.serviceName}' from v${operation.fromVersion} to v${operation.targetVersion}`,
);
await this.updateUpgradeOperation(
operation.id,
'migration',
`Resolving migration for ${operation.appTemplateId} ${operation.fromVersion} -> ${operation.targetVersion}`,
);
const migrationResult = await this.opsServerRef.oneboxRef.appStore.executeMigration(
existingService,
operation.fromVersion,
operation.targetVersion,
);
if (!migrationResult.success) {
throw new Error(`Migration failed: ${migrationResult.warnings.join('; ')}`);
}
if (migrationResult.warnings.length > 0) {
operation = await this.updateUpgradeOperation(
operation.id,
'migration',
`Migration completed with ${migrationResult.warnings.length} warning(s)`,
{ warnings: migrationResult.warnings },
);
}
await this.updateUpgradeOperation(
operation.id,
'applying',
`Applying upgrade to ${operation.serviceName}`,
);
const updatedService = await this.opsServerRef.oneboxRef.appStore.applyUpgrade(
operation.serviceName,
migrationResult,
operation.targetVersion,
{
onProgress: async (progressArg) => {
await this.updateUpgradeOperation(
operation!.id,
progressArg.step as TAppStoreUpgradeStep,
progressArg.message,
);
},
},
);
await this.updateUpgradeOperation(
operation.id,
'complete',
`Upgrade completed for ${operation.serviceName}`,
{
status: 'success',
completedAt: Date.now(),
service: updatedService,
warnings: migrationResult.warnings,
},
);
return updatedService;
} catch (error) {
await this.updateUpgradeOperation(
operation.id,
'failed',
`Upgrade failed: ${getErrorMessage(error)}`,
{
status: 'failed',
completedAt: Date.now(),
error: getErrorMessage(error),
},
);
throw error;
}
}
private registerHandlers(): void {
// Get app templates (catalog)
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetAppTemplates>(
'getAppTemplates',
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetAppStoreTemplates>(
'getAppStoreTemplates',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const apps = await this.opsServerRef.oneboxRef.appStore.getApps();
@@ -25,10 +214,9 @@ export class AppStoreHandler {
),
);
// Get app config for a specific version
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetAppConfig>(
'getAppConfig',
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetAppStoreConfig>(
'getAppStoreConfig',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const config = await this.opsServerRef.oneboxRef.appStore.getAppVersionConfig(
@@ -42,8 +230,8 @@ export class AppStoreHandler {
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_InstallAppTemplate>(
'installAppTemplate',
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_InstallAppStoreApp>(
'installAppStoreApp',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const service = await this.opsServerRef.oneboxRef.appStore.installApp(dataArg.install);
@@ -52,64 +240,54 @@ export class AppStoreHandler {
),
);
// Get services with available upgrades
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetUpgradeableServices>(
'getUpgradeableServices',
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetUpgradeableAppStoreServices>(
'getUpgradeableAppStoreServices',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const services = await this.opsServerRef.oneboxRef.appStore.getUpgradeableServices();
const services = await this.opsServerRef.oneboxRef.appStore.getUpgradeableAppStoreServices();
return { services };
},
),
);
// Upgrade a service to a new template version
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_UpgradeService>(
'upgradeService',
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_UpgradeAppStoreService>(
'upgradeAppStoreService',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const existingService = this.opsServerRef.oneboxRef.database.getServiceByName(dataArg.serviceName);
if (!existingService) {
throw new plugins.typedrequest.TypedResponseError(`Service not found: ${dataArg.serviceName}`);
}
if (!existingService.appTemplateId) {
throw new plugins.typedrequest.TypedResponseError('Service was not deployed from an app template');
}
if (!existingService.appTemplateVersion) {
throw new plugins.typedrequest.TypedResponseError('Service has no tracked template version');
}
logger.info(`Upgrading service '${dataArg.serviceName}' from v${existingService.appTemplateVersion} to v${dataArg.targetVersion}`);
// Execute migration
const migrationResult = await this.opsServerRef.oneboxRef.appStore.executeMigration(
existingService,
existingService.appTemplateVersion,
dataArg.targetVersion,
);
if (!migrationResult.success) {
throw new plugins.typedrequest.TypedResponseError(
`Migration failed: ${migrationResult.warnings.join('; ')}`,
);
}
// Apply the upgrade
const updatedService = await this.opsServerRef.oneboxRef.appStore.applyUpgrade(
dataArg.serviceName,
migrationResult,
dataArg.targetVersion,
);
const operation = await this.createUpgradeOperation(dataArg.serviceName, dataArg.targetVersion);
const updatedService = await this.performUpgrade(operation.id);
const completedOperation = this.upgradeOperations.get(operation.id)!;
return {
service: updatedService,
warnings: migrationResult.warnings,
warnings: completedOperation.warnings,
};
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_StartAppStoreServiceUpgrade>(
'startAppStoreServiceUpgrade',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const operation = await this.createUpgradeOperation(dataArg.serviceName, dataArg.targetVersion);
void this.performUpgrade(operation.id).catch(() => {});
return { operation };
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetAppStoreUpgradeOperations>(
'getAppStoreUpgradeOperations',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
return { operations: this.getUpgradeOperations() };
},
),
);
}
}
+43 -18
View File
@@ -4,6 +4,7 @@ import * as interfaces from '../../../ts_interfaces/index.ts';
import { requireAdminIdentity } from '../helpers/guards.ts';
import { logger } from '../../logging.ts';
import { getErrorMessage } from '../../utils/error.ts';
import { isValidHostname, normalizeHostname } from '../../utils/domain.ts';
export class SettingsHandler {
public typedrouter = new plugins.typedrequest.TypedRouter();
@@ -23,6 +24,7 @@ export class SettingsHandler {
return {
cloudflareToken: cloudflareToken || '',
cloudflareZoneId: settingsMap['cloudflareZoneId'] || '',
adminUiDomain: settingsMap['adminUiDomain'] || '',
dcrouterMode: managedDcRouter.getMode(),
dcrouterManagedImage: managedDcRouter.getImage(),
dcrouterManagedOpsPort: managedDcRouter.getOpsPort(),
@@ -64,8 +66,10 @@ export class SettingsHandler {
const db = this.opsServerRef.oneboxRef.database;
const updates = dataArg.settings;
const normalizedUpdates = this.normalizeUpdates(updates);
// Store each setting as key-value pair
for (const [key, value] of Object.entries(updates)) {
for (const [key, value] of Object.entries(normalizedUpdates)) {
if (value !== undefined) {
if (db.isSecretSettingKey(key)) {
await db.setSecretSetting(key, String(value));
@@ -75,8 +79,8 @@ export class SettingsHandler {
}
}
if (this.hasExternalGatewaySetting(updates)) {
this.refreshDcRouterGateway().catch((error) => {
if (this.hasRouteSyncSetting(normalizedUpdates)) {
this.refreshGatewayRoutes(normalizedUpdates).catch((error) => {
logger.warn(`dcrouter gateway settings refresh failed: ${getErrorMessage(error)}`);
});
}
@@ -110,8 +114,23 @@ export class SettingsHandler {
);
}
private hasExternalGatewaySetting(settings: Partial<interfaces.data.ISettings>): boolean {
private normalizeUpdates(
settings: Partial<interfaces.data.ISettings>,
): Partial<interfaces.data.ISettings> {
const normalizedUpdates = { ...settings };
if (Object.prototype.hasOwnProperty.call(normalizedUpdates, 'adminUiDomain')) {
const normalizedDomain = normalizeHostname(String(normalizedUpdates.adminUiDomain || ''));
if (!isValidHostname(normalizedDomain)) {
throw new plugins.typedrequest.TypedResponseError('Invalid Admin UI domain');
}
normalizedUpdates.adminUiDomain = normalizedDomain;
}
return normalizedUpdates;
}
private hasRouteSyncSetting(settings: Partial<interfaces.data.ISettings>): boolean {
return [
'adminUiDomain',
'dcrouterMode',
'dcrouterManagedImage',
'dcrouterManagedOpsPort',
@@ -127,23 +146,29 @@ export class SettingsHandler {
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
}
private async refreshDcRouterGateway(): Promise<void> {
private hasManagedDcRouterRuntimeSetting(settings: Partial<interfaces.data.ISettings>): boolean {
return [
'dcrouterMode',
'dcrouterManagedImage',
'dcrouterManagedOpsPort',
'dcrouterManagedHttpPort',
'dcrouterManagedHttpsPort',
'dcrouterManagedDataDir',
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
}
private async refreshGatewayRoutes(settings: Partial<interfaces.data.ISettings>): Promise<void> {
const onebox = this.opsServerRef.oneboxRef;
if (onebox.managedDcRouter.getMode() === 'managed') {
await onebox.managedDcRouter.restart();
} else {
await onebox.managedDcRouter.stop();
if (this.hasManagedDcRouterRuntimeSetting(settings)) {
if (onebox.managedDcRouter.getMode() === 'managed') {
await onebox.managedDcRouter.restart();
} else {
await onebox.managedDcRouter.stop();
}
}
await onebox.reverseProxy.reloadRoutes();
await onebox.externalGateway.syncDomains();
const services = onebox.database.getAllServices().filter((service) => service.domain);
await Promise.all(services.map(async (service) => {
try {
await onebox.externalGateway.syncServiceRoute(service);
} catch (error) {
logger.warn(`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`);
}
}));
await onebox.externalGateway.syncServiceRoutes();
}
}
+16
View File
@@ -2,6 +2,7 @@ import * as plugins from '../../plugins.ts';
import type { OpsServer } from '../classes.opsserver.ts';
import * as interfaces from '../../../ts_interfaces/index.ts';
import { requireAdminIdentity } from '../helpers/guards.ts';
import { getErrorMessage } from '../../utils/error.ts';
export class StatusHandler {
public typedrouter = new plugins.typedrequest.TypedRouter();
@@ -22,5 +23,20 @@ export class StatusHandler {
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_StartOneboxUpgrade>(
'startOneboxUpgrade',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
try {
const upgrade = await this.opsServerRef.oneboxRef.updateManager.startDetachedUpgrade();
return { upgrade };
} catch (error) {
throw new plugins.typedrequest.TypedResponseError(getErrorMessage(error));
}
},
),
);
}
}
+220
View File
@@ -5,8 +5,21 @@ import * as interfaces from '../../../ts_interfaces/index.ts';
import { requireAdminIdentity } from '../helpers/guards.ts';
import { getErrorMessage } from '../../utils/error.ts';
interface IWorkspaceProcessSession {
processId: string;
serviceName: string;
userId: string;
stream: plugins.nodeStream.Duplex;
close: () => Promise<void>;
inspect: () => Promise<{ ExitCode?: number | null; Running?: boolean }>;
finalized: boolean;
}
const getWorkspaceProcessTag = (processIdArg: string) => `workspaceProcess:${processIdArg}`;
export class WorkspaceHandler {
public typedrouter = new plugins.typedrequest.TypedRouter();
private workspaceProcesses = new Map<string, IWorkspaceProcessSession>();
constructor(private opsServerRef: OpsServer) {
this.opsServerRef.typedrouter.addTypedRouter(this.typedrouter);
@@ -24,6 +37,111 @@ export class WorkspaceHandler {
return service.containerID;
}
private validateProcessId(processIdArg: string): void {
if (!/^[a-zA-Z0-9_-]{8,80}$/.test(processIdArg)) {
throw new plugins.typedrequest.TypedResponseError('Invalid workspace process id');
}
}
private async getShellCommandForContainer(
containerIdArg: string,
): Promise<interfaces.requests.IWorkspaceShellCommand> {
const candidates: interfaces.requests.IWorkspaceShellCommand[] = [
{ command: '/bin/bash', args: ['-il'], label: 'bash', prompt: '# ' },
{ command: 'bash', args: ['-il'], label: 'bash', prompt: '# ' },
{ command: '/bin/sh', args: ['-i'], label: 'sh', prompt: '# ' },
{ command: 'sh', args: ['-i'], label: 'sh', prompt: '# ' },
{ command: '/bin/ash', args: ['-i'], label: 'ash', prompt: '# ' },
{ command: 'ash', args: ['-i'], label: 'ash', prompt: '# ' },
{ command: '/usr/bin/zsh', args: ['-il'], label: 'zsh', prompt: '# ' },
{ command: 'zsh', args: ['-il'], label: 'zsh', prompt: '# ' },
];
for (const candidate of candidates) {
const result = await this.opsServerRef.oneboxRef.docker.execInContainer(
containerIdArg,
[candidate.command, '-c', 'printf onebox-shell'],
);
if (result.exitCode === 0 && result.stdout.includes('onebox-shell')) {
return candidate;
}
}
throw new plugins.typedrequest.TypedResponseError(
'No supported interactive shell found in the target container',
);
}
private async getProcessSession(
dataArg: { identity: interfaces.data.IIdentity; processId: string },
): Promise<IWorkspaceProcessSession> {
const identity = await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
this.validateProcessId(dataArg.processId);
const session = this.workspaceProcesses.get(dataArg.processId);
if (!session) {
throw new plugins.typedrequest.TypedResponseError(`Workspace process not found: ${dataArg.processId}`);
}
if (session.userId !== identity.userId) {
throw new plugins.typedrequest.TypedResponseError('Workspace process belongs to another session');
}
return session;
}
private async pushWorkspaceProcessOutput(processIdArg: string, outputArg: string): Promise<void> {
const typedsocket = (this.opsServerRef.server as any)?.typedserver?.typedsocket;
if (!typedsocket) return;
const connections = await typedsocket.findAllTargetConnectionsByTag(getWorkspaceProcessTag(processIdArg));
await Promise.allSettled(
connections.map((connection: any) => typedsocket
.createTypedRequest(
'pushWorkspaceProcessOutput',
connection,
)
.fire({ processId: processIdArg, output: outputArg })),
);
}
private async pushWorkspaceProcessExit(processIdArg: string, exitCodeArg: number): Promise<void> {
const typedsocket = (this.opsServerRef.server as any)?.typedserver?.typedsocket;
if (!typedsocket) return;
const connections = await typedsocket.findAllTargetConnectionsByTag(getWorkspaceProcessTag(processIdArg));
await Promise.allSettled(
connections.map((connection: any) => typedsocket
.createTypedRequest(
'pushWorkspaceProcessExit',
connection,
)
.fire({ processId: processIdArg, exitCode: exitCodeArg })),
);
}
private async finalizeWorkspaceProcess(processIdArg: string, fallbackExitCodeArg = -1): Promise<void> {
const session = this.workspaceProcesses.get(processIdArg);
if (!session || session.finalized) return;
session.finalized = true;
let exitCode = fallbackExitCodeArg;
try {
await new Promise((resolve) => setTimeout(resolve, 50));
const inspectResult = await session.inspect();
if (typeof inspectResult.ExitCode === 'number') {
exitCode = inspectResult.ExitCode;
}
} catch (error) {
logger.debug(`Failed to inspect workspace process ${processIdArg}: ${getErrorMessage(error)}`);
}
this.workspaceProcesses.delete(processIdArg);
await this.pushWorkspaceProcessExit(processIdArg, exitCode);
try {
await session.close();
} catch {
// The hijacked connection may already be closed by Docker.
}
}
private registerHandlers(): void {
// Read file from container
this.typedrouter.addTypedHandler(
@@ -176,6 +294,108 @@ export class WorkspaceHandler {
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_WorkspaceGetShellCommand>(
'workspaceGetShellCommand',
async (dataArg) => {
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
const containerId = await this.resolveContainerId(dataArg.serviceName);
const shellCommand = await this.getShellCommandForContainer(containerId);
return { shellCommand };
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_WorkspaceStartProcess>(
'workspaceStartProcess',
async (dataArg) => {
const identity = await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
this.validateProcessId(dataArg.processId);
if (this.workspaceProcesses.has(dataArg.processId)) {
throw new plugins.typedrequest.TypedResponseError(`Workspace process already exists: ${dataArg.processId}`);
}
const containerId = await this.resolveContainerId(dataArg.serviceName);
const command = dataArg.args ? [dataArg.command, ...dataArg.args] : [dataArg.command];
const interactiveExec = await this.opsServerRef.oneboxRef.docker.startInteractiveExecInContainer(
containerId,
command,
);
const session: IWorkspaceProcessSession = {
processId: dataArg.processId,
serviceName: dataArg.serviceName,
userId: identity.userId,
stream: interactiveExec.stream,
close: interactiveExec.close,
inspect: interactiveExec.inspect,
finalized: false,
};
this.workspaceProcesses.set(dataArg.processId, session);
interactiveExec.stream.on('data', (chunk: Uint8Array | string) => {
const output = typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
void this.pushWorkspaceProcessOutput(dataArg.processId, output);
});
interactiveExec.stream.on('error', (error: Error) => {
void this.pushWorkspaceProcessOutput(
dataArg.processId,
`\r\n[workspace process error: ${getErrorMessage(error)}]\r\n`,
);
void this.finalizeWorkspaceProcess(dataArg.processId, -1);
});
interactiveExec.stream.on('end', () => {
void this.finalizeWorkspaceProcess(dataArg.processId, -1);
});
interactiveExec.stream.on('close', () => {
void this.finalizeWorkspaceProcess(dataArg.processId, -1);
});
return { processId: dataArg.processId };
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_WorkspaceProcessInput>(
'workspaceProcessInput',
async (dataArg) => {
const session = await this.getProcessSession(dataArg);
if (session.finalized || session.stream.writableEnded) {
return {};
}
await new Promise<void>((resolve, reject) => {
session.stream.write(dataArg.input, (error?: Error | null) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
return {};
},
),
);
this.typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_WorkspaceKillProcess>(
'workspaceKillProcess',
async (dataArg) => {
const session = await this.getProcessSession(dataArg);
session.stream.destroy();
try {
await session.close();
} catch {
// The stream may already be closed.
}
await this.finalizeWorkspaceProcess(dataArg.processId, -1);
return {};
},
),
);
logger.info('Workspace handler registered');
}
}
+5
View File
@@ -82,6 +82,11 @@ export { smartguard, smartjwt };
import { ContainerArchive } from '@serve.zone/containerarchive';
export { ContainerArchive };
// serve.zone App Store contracts and resolver
import * as servezoneInterfaces from '@serve.zone/interfaces';
import * as servezoneAppstore from '@serve.zone/appstore';
export { servezoneInterfaces, servezoneAppstore };
// Node.js compat for streaming
import * as nodeFs from 'node:fs';
import * as nodeStream from 'node:stream';
+2
View File
@@ -280,6 +280,7 @@ export interface ISetting {
// Application settings
export interface IAppSettings {
serverIP?: string;
adminUiDomain?: string;
cloudflareToken?: string;
cloudflareZoneId?: string;
dcrouterMode?: 'managed' | 'external' | 'disabled';
@@ -332,6 +333,7 @@ export interface IServiceDeployOptions {
useOneboxRegistry?: boolean;
registryImageTag?: string;
autoUpdateOnPush?: boolean;
imageDigest?: string;
// Platform service requirements
enableMongoDB?: boolean;
enableS3?: boolean;
+17
View File
@@ -0,0 +1,17 @@
export function normalizeHostname(valueArg: string): string {
const trimmedValue = valueArg.trim().toLowerCase();
if (!trimmedValue) return '';
const withoutProtocol = trimmedValue.replace(/^[a-z][a-z0-9+.-]*:\/\//, '');
const withoutPath = withoutProtocol.split('/')[0].split('?')[0].split('#')[0];
return withoutPath.replace(/:\d+$/, '').replace(/\.$/, '');
}
export function isValidHostname(hostnameArg: string): boolean {
if (!hostnameArg) return true;
if (hostnameArg.length > 253) return false;
return hostnameArg.split('.').every((label) => {
if (!label || label.length > 63) return false;
return /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label);
});
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -21,6 +21,7 @@ export interface IManagedDcRouterStatus {
export interface ISettings {
cloudflareToken: string;
cloudflareZoneId: string;
adminUiDomain: string;
dcrouterMode: TDcRouterMode;
dcrouterManagedImage: string;
dcrouterManagedOpsPort: number;
+25 -1
View File
@@ -2,9 +2,33 @@
* System status data shapes for Onebox
*/
import type { TPlatformServiceType, TPlatformServiceStatus } from './platform.ts';
import type { TPlatformServiceStatus, TPlatformServiceType } from './platform.ts';
export interface IOneboxUpdateStatus {
currentVersion: string;
latestVersion: string | null;
updateAvailable: boolean;
checkedAt: number;
releaseUrl: string;
changelogUrl: string;
error?: string;
}
export interface IOneboxUpgradeStartResult {
accepted: boolean;
currentVersion: string;
targetVersion: string;
message: string;
pid?: number;
unitName?: string;
logPath?: string;
}
export interface ISystemStatus {
onebox: {
version: string;
update: IOneboxUpdateStatus;
};
docker: {
running: boolean;
version: unknown;
+95 -69
View File
@@ -1,125 +1,112 @@
import type * as servezoneInterfaces from '@serve.zone/interfaces';
import * as plugins from '../plugins.ts';
import * as data from '../data/index.ts';
export interface ICatalogApp {
id: string;
name: string;
description: string;
category: string;
iconName?: string;
iconUrl?: string;
latestVersion: string;
tags?: string[];
}
export type IAppStoreApp = servezoneInterfaces.appstore.IAppStoreApp;
export type IAppStoreVersionConfig = servezoneInterfaces.appstore.IAppStoreVersionConfig;
export type IAppStoreAppMeta = servezoneInterfaces.appstore.IAppStoreAppMeta;
export type IUpgradeableAppStoreService = servezoneInterfaces.appstore.IUpgradeableAppStoreService;
export interface IAppVersionConfig {
image: string;
port: number;
envVars?: Array<{ key: string; value: string; description: string; required?: boolean }>;
volumes?: Array<string | data.IServiceVolume>;
publishedPorts?: data.IServicePublishedPort[];
platformRequirements?: {
mongodb?: boolean;
s3?: boolean;
clickhouse?: boolean;
redis?: boolean;
mariadb?: boolean;
};
minOneboxVersion?: string;
}
export interface IAppInstallOptions {
appId: string;
version?: string;
serviceName: string;
domain?: string;
port?: number;
publishedPorts?: data.IServicePublishedPort[];
envVars?: Record<string, string>;
export interface IAppStoreInstallOptions extends servezoneInterfaces.appstore.IAppStoreInstallRequest {
autoDNS?: boolean;
}
export interface IAppMeta {
id: string;
name: string;
description: string;
category: string;
iconName?: string;
latestVersion: string;
versions: string[];
maintainer?: string;
links?: Record<string, string>;
}
export type TAppStoreUpgradeStatus = 'running' | 'success' | 'failed';
export interface IUpgradeableService {
export type TAppStoreUpgradeStep =
| 'queued'
| 'validating'
| 'migration'
| 'applying'
| 'stopping'
| 'pulling-image'
| 'updating-record'
| 'removing-container'
| 'creating-container'
| 'starting'
| 'restoring-route'
| 'syncing-gateway'
| 'complete'
| 'failed';
export interface IAppStoreUpgradeOperation {
id: string;
serviceName: string;
appTemplateId: string;
currentVersion: string;
latestVersion: string;
hasMigration: boolean;
fromVersion: string;
targetVersion: string;
status: TAppStoreUpgradeStatus;
step: TAppStoreUpgradeStep;
progressLines: string[];
warnings: string[];
error?: string;
startedAt: number;
updatedAt: number;
completedAt?: number;
service?: data.IService;
}
export interface IReq_GetAppTemplates extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_GetAppStoreTemplates extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetAppTemplates
IReq_GetAppStoreTemplates
> {
method: 'getAppTemplates';
method: 'getAppStoreTemplates';
request: {
identity: data.IIdentity;
};
response: {
apps: ICatalogApp[];
apps: IAppStoreApp[];
};
}
export interface IReq_GetAppConfig extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_GetAppStoreConfig extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetAppConfig
IReq_GetAppStoreConfig
> {
method: 'getAppConfig';
method: 'getAppStoreConfig';
request: {
identity: data.IIdentity;
appId: string;
version: string;
};
response: {
config: IAppVersionConfig;
appMeta: IAppMeta;
config: IAppStoreVersionConfig;
appMeta: IAppStoreAppMeta;
};
}
export interface IReq_InstallAppTemplate extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_InstallAppStoreApp extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_InstallAppTemplate
IReq_InstallAppStoreApp
> {
method: 'installAppTemplate';
method: 'installAppStoreApp';
request: {
identity: data.IIdentity;
install: IAppInstallOptions;
install: IAppStoreInstallOptions;
};
response: {
service: data.IService;
};
}
export interface IReq_GetUpgradeableServices extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_GetUpgradeableAppStoreServices extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetUpgradeableServices
IReq_GetUpgradeableAppStoreServices
> {
method: 'getUpgradeableServices';
method: 'getUpgradeableAppStoreServices';
request: {
identity: data.IIdentity;
};
response: {
services: IUpgradeableService[];
services: IUpgradeableAppStoreService[];
};
}
export interface IReq_UpgradeService extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_UpgradeAppStoreService extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_UpgradeService
IReq_UpgradeAppStoreService
> {
method: 'upgradeService';
method: 'upgradeAppStoreService';
request: {
identity: data.IIdentity;
serviceName: string;
@@ -130,3 +117,42 @@ export interface IReq_UpgradeService extends plugins.typedrequestInterfaces.impl
warnings: string[];
};
}
export interface IReq_StartAppStoreServiceUpgrade extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_StartAppStoreServiceUpgrade
> {
method: 'startAppStoreServiceUpgrade';
request: {
identity: data.IIdentity;
serviceName: string;
targetVersion: string;
};
response: {
operation: IAppStoreUpgradeOperation;
};
}
export interface IReq_GetAppStoreUpgradeOperations extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetAppStoreUpgradeOperations
> {
method: 'getAppStoreUpgradeOperations';
request: {
identity: data.IIdentity;
};
response: {
operations: IAppStoreUpgradeOperation[];
};
}
export interface IReq_PushAppStoreUpgradeProgress extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_PushAppStoreUpgradeProgress
> {
method: 'pushAppStoreUpgradeProgress';
request: {
operation: IAppStoreUpgradeOperation;
};
response: {};
}
+13
View File
@@ -13,3 +13,16 @@ export interface IReq_GetSystemStatus extends plugins.typedrequestInterfaces.imp
status: data.ISystemStatus;
};
}
export interface IReq_StartOneboxUpgrade extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_StartOneboxUpgrade
> {
method: 'startOneboxUpgrade';
request: {
identity: data.IIdentity;
};
response: {
upgrade: data.IOneboxUpgradeStartResult;
};
}
+87
View File
@@ -1,6 +1,13 @@
import * as plugins from '../plugins.ts';
import * as data from '../data/index.ts';
export interface IWorkspaceShellCommand {
command: string;
args?: string[];
label?: string;
prompt?: string;
}
export interface IReq_WorkspaceReadFile extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_WorkspaceReadFile
@@ -104,3 +111,83 @@ export interface IReq_WorkspaceExec extends plugins.typedrequestInterfaces.imple
exitCode: number;
};
}
export interface IReq_WorkspaceGetShellCommand extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_WorkspaceGetShellCommand
> {
method: 'workspaceGetShellCommand';
request: {
identity: data.IIdentity;
serviceName: string;
};
response: {
shellCommand: IWorkspaceShellCommand;
};
}
export interface IReq_WorkspaceStartProcess extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_WorkspaceStartProcess
> {
method: 'workspaceStartProcess';
request: {
identity: data.IIdentity;
serviceName: string;
processId: string;
command: string;
args?: string[];
};
response: {
processId: string;
};
}
export interface IReq_WorkspaceProcessInput extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_WorkspaceProcessInput
> {
method: 'workspaceProcessInput';
request: {
identity: data.IIdentity;
processId: string;
input: string;
};
response: {};
}
export interface IReq_WorkspaceKillProcess extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_WorkspaceKillProcess
> {
method: 'workspaceKillProcess';
request: {
identity: data.IIdentity;
processId: string;
};
response: {};
}
export interface IReq_PushWorkspaceProcessOutput extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_PushWorkspaceProcessOutput
> {
method: 'pushWorkspaceProcessOutput';
request: {
processId: string;
output: string;
};
response: {};
}
export interface IReq_PushWorkspaceProcessExit extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_PushWorkspaceProcessExit
> {
method: 'pushWorkspaceProcessExit';
request: {
processId: string;
exitCode: number;
};
response: {};
}
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/onebox',
version: '1.28.0',
version: '2.1.2',
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
}
+75 -18
View File
@@ -58,8 +58,9 @@ export interface ISettingsState {
}
export interface IAppStoreState {
apps: interfaces.requests.ICatalogApp[];
upgradeableServices: interfaces.requests.IUpgradeableService[];
apps: interfaces.requests.IAppStoreApp[];
upgradeableServices: interfaces.requests.IUpgradeableAppStoreService[];
upgradeOperations: interfaces.requests.IAppStoreUpgradeOperation[];
}
export interface IUiState {
@@ -154,6 +155,7 @@ export const appStoreStatePart = await appState.getStatePart<IAppStoreState>(
{
apps: [],
upgradeableServices: [],
upgradeOperations: [],
},
'soft',
);
@@ -1101,6 +1103,19 @@ const upsertService = (
return updatedServices;
};
const upsertUpgradeOperation = (
operations: interfaces.requests.IAppStoreUpgradeOperation[],
operation: interfaces.requests.IAppStoreUpgradeOperation,
): interfaces.requests.IAppStoreUpgradeOperation[] => {
const existingIndex = operations.findIndex((item) => item.id === operation.id);
const updatedOperations = existingIndex === -1
? [operation, ...operations]
: operations.map((item) => item.id === operation.id ? operation : item);
return updatedOperations
.sort((a, b) => b.startedAt - a.startedAt)
.slice(0, 25);
};
socketRouter.addTypedHandler(
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushServiceUpdate>(
'pushServiceUpdate',
@@ -1137,6 +1152,33 @@ socketRouter.addTypedHandler(
),
);
socketRouter.addTypedHandler(
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushAppStoreUpgradeProgress>(
'pushAppStoreUpgradeProgress',
async (dataArg) => {
const state = appStoreStatePart.getState();
appStoreStatePart.setState({
...state,
upgradeOperations: upsertUpgradeOperation(state.upgradeOperations, dataArg.operation),
upgradeableServices: dataArg.operation.status === 'success'
? state.upgradeableServices.filter((service) => service.serviceName !== dataArg.operation.serviceName)
: state.upgradeableServices,
});
if (dataArg.operation.service) {
const servicesState = servicesStatePart.getState();
servicesStatePart.setState({
...servicesState,
services: upsertService(servicesState.services, dataArg.operation.service),
currentService: servicesState.currentService?.name === dataArg.operation.service.name
? dataArg.operation.service
: servicesState.currentService,
});
}
return {};
},
),
);
// Handle server-pushed platform service log entries
socketRouter.addTypedHandler(
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushPlatformServiceLog>(
@@ -1226,13 +1268,13 @@ async function disconnectSocket() {
// App Store Actions
// ============================================================================
export const fetchAppTemplatesAction = appStoreStatePart.createAction(
export const fetchAppStoreTemplatesAction = appStoreStatePart.createAction(
async (statePartArg) => {
const context = getActionContext();
try {
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetAppTemplates
>('/typedrequest', 'getAppTemplates');
interfaces.requests.IReq_GetAppStoreTemplates
>('/typedrequest', 'getAppStoreTemplates');
const response = await typedRequest.fire({ identity: context.identity! });
return { ...statePartArg.getState(), apps: response.apps };
} catch (err) {
@@ -1242,13 +1284,13 @@ export const fetchAppTemplatesAction = appStoreStatePart.createAction(
},
);
export const fetchUpgradeableServicesAction = appStoreStatePart.createAction(
export const fetchUpgradeableAppStoreServicesAction = appStoreStatePart.createAction(
async (statePartArg) => {
const context = getActionContext();
try {
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetUpgradeableServices
>('/typedrequest', 'getUpgradeableServices');
interfaces.requests.IReq_GetUpgradeableAppStoreServices
>('/typedrequest', 'getUpgradeableAppStoreServices');
const response = await typedRequest.fire({ identity: context.identity! });
return { ...statePartArg.getState(), upgradeableServices: response.services };
} catch (err) {
@@ -1258,26 +1300,41 @@ export const fetchUpgradeableServicesAction = appStoreStatePart.createAction(
},
);
export const upgradeServiceAction = appStoreStatePart.createAction<{
export const fetchAppStoreUpgradeOperationsAction = appStoreStatePart.createAction(
async (statePartArg) => {
const context = getActionContext();
try {
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetAppStoreUpgradeOperations
>('/typedrequest', 'getAppStoreUpgradeOperations');
const response = await typedRequest.fire({ identity: context.identity! });
return { ...statePartArg.getState(), upgradeOperations: response.operations };
} catch (err) {
console.error('Failed to fetch upgrade operations:', err);
return statePartArg.getState();
}
},
);
export const upgradeAppStoreServiceAction = appStoreStatePart.createAction<{
serviceName: string;
targetVersion: string;
}>(async (statePartArg, dataArg) => {
const context = getActionContext();
try {
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_UpgradeService
>('/typedrequest', 'upgradeService');
await typedRequest.fire({
interfaces.requests.IReq_StartAppStoreServiceUpgrade
>('/typedrequest', 'startAppStoreServiceUpgrade');
const response = await typedRequest.fire({
identity: context.identity!,
serviceName: dataArg.serviceName,
targetVersion: dataArg.targetVersion,
});
// Re-fetch upgradeable services and services list
const upgradeReq = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetUpgradeableServices
>('/typedrequest', 'getUpgradeableServices');
const upgradeResp = await upgradeReq.fire({ identity: context.identity! });
return { ...statePartArg.getState(), upgradeableServices: upgradeResp.services };
const state = statePartArg.getState();
return {
...state,
upgradeOperations: upsertUpgradeOperation(state.upgradeOperations, response.operation),
};
} catch (err) {
console.error('Failed to upgrade service:', err);
return statePartArg.getState();
+191
View File
@@ -41,6 +41,14 @@ export class ObAppShell extends DeesElement {
refreshInterval: 30000,
};
@state()
accessor systemState: appstate.ISystemState = {
status: null,
};
@state()
accessor globalMessages: plugins.deesCatalog.IGlobalMessage[] = [];
@state()
accessor loginLoading: boolean = false;
@@ -126,6 +134,8 @@ export class ObAppShell extends DeesElement {
];
private resolvedViewTabs: IResolvedView[] = [];
private suppressedUpdateVersion = '';
private upgradeFlowRunning = false;
constructor() {
super();
@@ -135,12 +145,21 @@ export class ObAppShell extends DeesElement {
.select((stateArg: appstate.ILoginState) => stateArg)
.subscribe((loginState: appstate.ILoginState) => {
this.loginState = loginState;
this.updateGlobalMessages();
if (loginState.isLoggedIn) {
appstate.systemStatePart.dispatchAction(appstate.fetchSystemStatusAction, null);
}
});
this.rxSubscriptions.push(loginSubscription);
const systemSubscription = appstate.systemStatePart
.select((stateArg: appstate.ISystemState) => stateArg)
.subscribe((systemState: appstate.ISystemState) => {
this.systemState = systemState;
this.updateGlobalMessages();
});
this.rxSubscriptions.push(systemSubscription);
const uiSubscription = appstate.uiStatePart
.select((stateArg: appstate.IUiState) => stateArg)
.subscribe((uiState: appstate.IUiState) => {
@@ -214,6 +233,7 @@ export class ObAppShell extends DeesElement {
name="Onebox"
.viewTabs=${this.resolvedViewTabs}
.selectedView=${this.currentViewTab}
.globalMessages=${this.globalMessages}
>
</dees-simple-appdash>
</dees-simple-login>
@@ -324,6 +344,177 @@ export class ObAppShell extends DeesElement {
}
}
private updateGlobalMessages(): void {
const updateStatus = this.systemState.status?.onebox.update;
if (
!this.loginState.isLoggedIn ||
!updateStatus?.updateAvailable ||
!updateStatus.latestVersion ||
updateStatus.latestVersion === this.suppressedUpdateVersion
) {
this.globalMessages = [];
return;
}
this.globalMessages = [
{
id: `onebox-update-${updateStatus.latestVersion}`,
type: 'info',
icon: 'lucide:download',
message: `Onebox ${updateStatus.latestVersion} is available. Current version: ${updateStatus.currentVersion}.`,
dismissible: false,
actions: [
{
name: 'Update Now',
iconName: 'lucide:download',
action: () => this.startOneboxUpgradeFlow(),
},
{
name: 'Release Notes',
iconName: 'lucide:fileText',
action: () => this.openUpdateUrl(updateStatus.changelogUrl || updateStatus.releaseUrl),
},
{
name: 'Later',
iconName: 'lucide:clock',
action: () => {
this.suppressedUpdateVersion = updateStatus.latestVersion || '';
this.updateGlobalMessages();
},
},
],
},
];
}
private async startOneboxUpgradeFlow(): Promise<void> {
if (this.upgradeFlowRunning) {
return;
}
const identity = appstate.loginStatePart.getState().identity;
const updateStatus = this.systemState.status?.onebox.update;
if (!identity || !updateStatus?.latestVersion) {
return;
}
this.upgradeFlowRunning = true;
const updater = await plugins.deesCatalog.DeesUpdater.createAndShow({
currentVersion: updateStatus.currentVersion,
updatedVersion: updateStatus.latestVersion,
moreInfoUrl: updateStatus.releaseUrl,
changelogUrl: updateStatus.changelogUrl,
successAction: 'reload',
successDelayMs: 30000,
successActionLabel: 'Reloading Onebox UI',
});
try {
updater.updateProgress({
percentage: 10,
indeterminate: true,
statusText: 'Requesting upgrade...',
terminalLines: ['Requesting Onebox upgrade'],
});
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_StartOneboxUpgrade
>('/typedrequest', 'startOneboxUpgrade');
const response = await typedRequest.fire({ identity });
if (!response.upgrade.accepted) {
updater.markUpdateError(response.upgrade.message);
await this.delay(5000);
await updater.destroy();
return;
}
updater.appendProgressLine(response.upgrade.message);
if (response.upgrade.pid) {
updater.appendProgressLine(`Upgrade process PID: ${response.upgrade.pid}`);
}
if (response.upgrade.logPath) {
updater.appendProgressLine(`Upgrade log: ${response.upgrade.logPath}`);
}
updater.updateProgress({
percentage: 45,
indeterminate: true,
statusText: 'Installer started...',
});
await this.waitForOneboxUpgrade(updater, response.upgrade.targetVersion, identity);
await updater.markUpdateReady();
} catch (error) {
updater.markUpdateError(this.getErrorMessage(error));
await this.delay(5000);
await updater.destroy();
} finally {
this.upgradeFlowRunning = false;
}
}
private async waitForOneboxUpgrade(
updaterArg: plugins.deesCatalog.DeesUpdater,
targetVersionArg: string,
identityArg: interfaces.data.IIdentity,
): Promise<void> {
const normalizedTargetVersion = this.normalizeVersion(targetVersionArg);
const timeoutAt = Date.now() + 90000;
let attempt = 0;
updaterArg.appendProgressLine('Waiting for Onebox to restart with the new version');
while (Date.now() < timeoutAt) {
await this.delay(5000);
attempt++;
try {
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetSystemStatus
>('/typedrequest', 'getSystemStatus');
const response = await typedRequest.fire({ identity: identityArg });
const onlineVersion = this.normalizeVersion(response.status.onebox.version);
updaterArg.appendProgressLine(`Onebox API answered with ${onlineVersion}`);
if (onlineVersion === normalizedTargetVersion) {
updaterArg.updateProgress({
percentage: 100,
indeterminate: false,
statusText: `Onebox ${normalizedTargetVersion} is online.`,
});
return;
}
} catch {
updaterArg.appendProgressLine('Onebox API is restarting...');
}
updaterArg.updateProgress({
percentage: Math.min(95, 45 + attempt * 5),
indeterminate: true,
statusText: `Waiting for Onebox ${normalizedTargetVersion}...`,
});
}
updaterArg.appendProgressLine('Timed out waiting for the version check; reloading the UI anyway');
}
private openUpdateUrl(urlArg: string): void {
window.open(urlArg, '_blank', 'noopener,noreferrer');
}
private async delay(millisecondsArg: number): Promise<void> {
const domtools = await this.domtoolsPromise;
await domtools.convenience.smartdelay.delayFor(millisecondsArg);
}
private getErrorMessage(errorArg: unknown): string {
return errorArg instanceof Error ? errorArg.message : String(errorArg);
}
private normalizeVersion(versionArg: string): string {
const trimmedVersion = versionArg.trim();
return trimmedVersion.startsWith('v') ? trimmedVersion : `v${trimmedVersion}`;
}
private syncAppdashView(viewName: string, subviewName: string | null): void {
const appDash = this.shadowRoot?.querySelector('dees-simple-appdash') as any;
if (!appDash || this.resolvedViewTabs.length === 0) return;
+37 -11
View File
@@ -19,19 +19,20 @@ export class ObViewAppStore extends DeesElement {
accessor appStoreState: appstate.IAppStoreState = {
apps: [],
upgradeableServices: [],
upgradeOperations: [],
};
@state()
accessor currentView: 'grid' | 'detail' = 'grid';
@state()
accessor selectedApp: interfaces.requests.ICatalogApp | null = null;
accessor selectedApp: interfaces.requests.IAppStoreApp | null = null;
@state()
accessor selectedAppMeta: interfaces.requests.IAppMeta | null = null;
accessor selectedAppMeta: interfaces.requests.IAppStoreAppMeta | null = null;
@state()
accessor selectedAppConfig: interfaces.requests.IAppVersionConfig | null = null;
accessor selectedAppConfig: interfaces.requests.IAppStoreVersionConfig | null = null;
@state()
accessor selectedVersion: string = '';
@@ -331,7 +332,10 @@ export class ObViewAppStore extends DeesElement {
async connectedCallback() {
super.connectedCallback();
await appstate.appStoreStatePart.dispatchAction(appstate.fetchAppTemplatesAction, null);
await Promise.all([
appstate.appStoreStatePart.dispatchAction(appstate.fetchAppStoreTemplatesAction, null),
appstate.appStoreStatePart.dispatchAction(appstate.fetchAppStoreUpgradeOperationsAction, null),
]);
}
public render(): TemplateResult {
@@ -357,6 +361,7 @@ export class ObViewAppStore extends DeesElement {
return html`
<ob-sectionheading>App Store</ob-sectionheading>
${this.renderUpgradeOperations()}
${appTemplates.length === 0
? html`<div class="loading-spinner">Loading app templates...</div>`
: html`
@@ -369,6 +374,27 @@ export class ObViewAppStore extends DeesElement {
`;
}
private renderUpgradeOperations(): TemplateResult | '' {
const visibleOperations = this.appStoreState.upgradeOperations
.filter((operation) => operation.status === 'running' || operation.status === 'failed')
.slice(0, 3);
if (visibleOperations.length === 0) return '';
return html`
<div class="detail-card">
<div class="section-label">Recent Upgrade Operations</div>
<div class="footprint-list">
${visibleOperations.map((operation) => html`
<div class="footprint-item">
<span>${operation.serviceName}: ${operation.fromVersion} &rarr; ${operation.targetVersion}</span>
<span class="footprint-meta">${operation.status} / ${operation.step}</span>
</div>
`)}
</div>
</div>
`;
}
private renderDetailView(): TemplateResult {
if (this.loading) {
return html`
@@ -541,7 +567,7 @@ export class ObViewAppStore extends DeesElement {
`;
}
private renderDeploymentFootprint(config: interfaces.requests.IAppVersionConfig): TemplateResult | '' {
private renderDeploymentFootprint(config: interfaces.requests.IAppStoreVersionConfig): TemplateResult | '' {
const volumes = this.getConfigVolumes(config);
const publishedPorts = config.publishedPorts || [];
@@ -577,7 +603,7 @@ export class ObViewAppStore extends DeesElement {
`;
}
private renderDeployConfirmation(config: interfaces.requests.IAppVersionConfig): TemplateResult | '' {
private renderDeployConfirmation(config: interfaces.requests.IAppStoreVersionConfig): TemplateResult | '' {
const volumes = this.getConfigVolumes(config);
const publishedPorts = config.publishedPorts || [];
if (volumes.length === 0 && publishedPorts.length === 0) return '';
@@ -590,7 +616,7 @@ export class ObViewAppStore extends DeesElement {
`;
}
private getConfigVolumes(config: interfaces.requests.IAppVersionConfig): interfaces.data.IServiceVolume[] {
private getConfigVolumes(config: interfaces.requests.IAppStoreVersionConfig): interfaces.data.IServiceVolume[] {
return (config.volumes || []).map((volume) => {
if (typeof volume === 'string') {
return { mountPath: volume };
@@ -658,8 +684,8 @@ export class ObViewAppStore extends DeesElement {
if (!identity) return;
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetAppConfig
>('/typedrequest', 'getAppConfig');
interfaces.requests.IReq_GetAppStoreConfig
>('/typedrequest', 'getAppStoreConfig');
const response = await typedRequest.fire({ identity, appId, version });
@@ -728,8 +754,8 @@ export class ObViewAppStore extends DeesElement {
const identity = appstate.loginStatePart.getState().identity;
if (!identity) return;
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_InstallAppTemplate
>('/typedrequest', 'installAppTemplate');
interfaces.requests.IReq_InstallAppStoreApp
>('/typedrequest', 'installAppStoreApp');
await typedRequest.fire({
identity,
install: {
+65 -8
View File
@@ -146,6 +146,7 @@ export class ObViewServices extends DeesElement {
accessor appStoreState: appstate.IAppStoreState = {
apps: [],
upgradeableServices: [],
upgradeOperations: [],
};
constructor() {
@@ -226,7 +227,8 @@ export class ObViewServices extends DeesElement {
await Promise.all([
appstate.servicesStatePart.dispatchAction(appstate.fetchServicesAction, null),
appstate.servicesStatePart.dispatchAction(appstate.fetchPlatformServicesAction, null),
appstate.appStoreStatePart.dispatchAction(appstate.fetchUpgradeableServicesAction, null),
appstate.appStoreStatePart.dispatchAction(appstate.fetchUpgradeableAppStoreServicesAction, null),
appstate.appStoreStatePart.dispatchAction(appstate.fetchAppStoreUpgradeOperationsAction, null),
]);
// If a platform service was selected from the dashboard, navigate to its detail
@@ -471,9 +473,21 @@ export class ObViewServices extends DeesElement {
const upgradeInfo = service
? this.appStoreState.upgradeableServices.find((u) => u.serviceName === service.name)
: null;
const upgradeOperation = service
? this.appStoreState.upgradeOperations.find((operation) => {
return operation.serviceName === service.name && operation.status === 'running';
})
: null;
const latestUpgradeOperation = service
? this.appStoreState.upgradeOperations.find((operation) => operation.serviceName === service.name)
: null;
return html`
<ob-sectionheading>Service Details</ob-sectionheading>
${upgradeOperation ? this.renderUpgradeOperation(upgradeOperation) : ''}
${!upgradeOperation && latestUpgradeOperation?.status === 'failed'
? this.renderUpgradeOperation(latestUpgradeOperation)
: ''}
${upgradeInfo ? html`
<div style="
background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
@@ -496,18 +510,14 @@ export class ObViewServices extends DeesElement {
<button
class="deploy-button"
style="padding: 8px 16px; font-size: 13px;"
?disabled=${Boolean(upgradeOperation)}
@click=${async () => {
await appstate.appStoreStatePart.dispatchAction(appstate.upgradeServiceAction, {
await appstate.appStoreStatePart.dispatchAction(appstate.upgradeAppStoreServiceAction, {
serviceName: upgradeInfo.serviceName,
targetVersion: upgradeInfo.latestVersion,
});
// Refresh service data
appstate.servicesStatePart.dispatchAction(appstate.fetchServiceAction, {
name: upgradeInfo.serviceName,
});
appstate.servicesStatePart.dispatchAction(appstate.fetchServicesAction, null);
}}
>Upgrade</button>
>${upgradeOperation ? 'Upgrading...' : 'Upgrade'}</button>
</div>
` : ''}
<sz-service-detail-view
@@ -544,6 +554,53 @@ export class ObViewServices extends DeesElement {
`;
}
private renderUpgradeOperation(
operationArg: interfaces.requests.IAppStoreUpgradeOperation,
): TemplateResult {
const color = operationArg.status === 'failed' ? '#f87171' : '#60a5fa';
return html`
<div style="
background: var(--ci-shade-1, #09090b);
border: 1px solid ${color};
border-radius: 8px;
padding: 16px;
margin-bottom: 16px;
">
<div style="display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;">
<div>
<div style="font-size: 14px; font-weight: 600; color: var(--ci-shade-7, #e4e4e7);">
Upgrade ${operationArg.fromVersion} &rarr; ${operationArg.targetVersion}: ${operationArg.step}
</div>
<div style="font-size: 12px; color: var(--ci-shade-4, #71717a); margin-top: 4px;">
${operationArg.status === 'running' ? 'Operation is running in the background.' : operationArg.error || 'Operation finished.'}
</div>
</div>
<span style="font-size: 12px; color: ${color}; text-transform: uppercase; letter-spacing: 0.04em;">
${operationArg.status}
</span>
</div>
<div style="
margin-top: 12px;
padding: 10px 12px;
background: var(--ci-shade-0, #030305);
border-radius: 6px;
color: var(--ci-shade-5, #a1a1aa);
font-family: monospace;
font-size: 12px;
line-height: 1.5;
max-height: 130px;
overflow: auto;
white-space: pre-wrap;
">${operationArg.progressLines.slice(-8).join('\n')}</div>
${operationArg.warnings.length > 0 ? html`
<div style="margin-top: 10px; color: #fbbf24; font-size: 12px;">
${operationArg.warnings.join(' | ')}
</div>
` : ''}
</div>
`;
}
private renderBackupsView(): TemplateResult {
return html`
<ob-sectionheading>Backups</ob-sectionheading>
+121 -29
View File
@@ -48,31 +48,45 @@ export class ObViewSettings extends DeesElement {
cssManager.defaultStyles,
shared.viewHostCss,
css`
.gateway-card {
dees-tile {
display: block;
margin-bottom: 24px;
border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
border-radius: 12px;
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
overflow: hidden;
box-shadow: 0 1px 2px ${cssManager.bdTheme('rgba(0,0,0,0.04)', 'rgba(0,0,0,0.2)')};
}
.gateway-header {
padding: 16px 20px;
border-bottom: 1px solid ${cssManager.bdTheme('#f4f4f5', '#27272a')};
background: ${cssManager.bdTheme('#fafafa', '#101013')};
height: 36px;
display: flex;
align-items: center;
padding: 0 16px;
width: 100%;
box-sizing: border-box;
}
.gateway-heading {
flex: 1;
display: flex;
align-items: baseline;
gap: 8px;
min-width: 0;
}
.gateway-title {
font-size: 15px;
font-weight: 600;
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
font-size: 13px;
font-weight: 500;
letter-spacing: -0.01em;
color: var(--dees-color-text-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.gateway-subtitle {
margin-top: 4px;
font-size: 13px;
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
font-size: 12px;
color: var(--dees-color-text-muted);
letter-spacing: -0.01em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.gateway-content {
@@ -176,8 +190,51 @@ export class ObViewSettings extends DeesElement {
.gateway-footer {
display: flex;
flex-direction: row;
justify-content: flex-end;
padding: 0 20px 20px;
align-items: center;
gap: 0;
height: 36px;
width: 100%;
box-sizing: border-box;
}
.tile-button {
padding: 0 16px;
height: 100%;
text-align: center;
font-size: 12px;
font-weight: 500;
cursor: pointer;
user-select: none;
transition: all 0.15s ease;
background: transparent;
border: none;
border-left: 1px solid var(--dees-color-border-subtle);
color: var(--dees-color-text-muted);
white-space: nowrap;
display: flex;
align-items: center;
gap: 6px;
}
.tile-button:first-child {
border-left: none;
}
.tile-button:hover {
background: var(--dees-color-hover);
color: var(--dees-color-text-primary);
}
.tile-button.primary {
color: ${cssManager.bdTheme('hsl(217.2 91.2% 59.8%)', 'hsl(213.1 93.9% 67.8%)')};
font-weight: 600;
}
.tile-button.primary:hover {
background: ${cssManager.bdTheme('hsl(217.2 91.2% 59.8% / 0.08)', 'hsl(213.1 93.9% 67.8% / 0.08)')};
color: ${cssManager.bdTheme('hsl(217.2 91.2% 50%)', 'hsl(213.1 93.9% 75%)')};
}
@media (max-width: 700px) {
@@ -201,12 +258,14 @@ export class ObViewSettings extends DeesElement {
public render(): TemplateResult {
return html`
<ob-sectionheading>Settings</ob-sectionheading>
${this.renderAdminUiSettings()}
${this.renderExternalGatewaySettings()}
<sz-settings-view
.settings=${this.settingsState.settings || {
darkMode: true,
cloudflareToken: '',
cloudflareZoneId: '',
adminUiDomain: '',
dcrouterMode: 'managed',
dcrouterManagedImage: 'code.foss.global/serve.zone/dcrouter:latest',
dcrouterManagedOpsPort: 3300,
@@ -244,14 +303,39 @@ export class ObViewSettings extends DeesElement {
`;
}
private renderAdminUiSettings(): TemplateResult {
const settings = this.settingsState.settings;
return html`
<dees-tile>
<div slot="header" class="gateway-header">
<div class="gateway-heading">
<span class="gateway-title">Onebox Admin UI</span>
<span class="gateway-subtitle">Configure the public hostname for this Onebox dashboard</span>
</div>
</div>
<div class="gateway-content">
${this.renderGatewayInput('adminUiDomain', 'Admin UI Domain', settings?.adminUiDomain || '', 'Example: onebox.example.com. Leave empty to disable the public Admin UI route.')}
${this.renderGatewayReadonly('Local Target', 'Onebox OpsServer on port 3000', 'The external gateway forwards to SmartProxy, which forwards this hostname to the Onebox Admin UI.')}
</div>
<div slot="footer" class="gateway-footer">
<button class="tile-button primary" type="button" @click=${() => this.saveAdminUiSettings()}>
Save Admin UI Domain
</button>
</div>
</dees-tile>
`;
}
private renderExternalGatewaySettings(): TemplateResult {
const settings = this.settingsState.settings;
const mode = settings?.dcrouterMode || 'managed';
return html`
<section class="gateway-card">
<div class="gateway-header">
<div class="gateway-title">dcrouter Gateway</div>
<div class="gateway-subtitle">Run a local managed dcrouter or delegate routing, DNS, and certificates to an external dcrouter.</div>
<dees-tile>
<div slot="header" class="gateway-header">
<div class="gateway-heading">
<span class="gateway-title">dcrouter Gateway</span>
<span class="gateway-subtitle">Run a local managed dcrouter or delegate routing to an external dcrouter</span>
</div>
</div>
<div class="gateway-mode-row">
${this.renderModeButton('managed', 'Managed Local', mode)}
@@ -277,15 +361,12 @@ export class ObViewSettings extends DeesElement {
<div class="gateway-disabled">dcrouter route delegation is disabled. Onebox will keep using its local SmartProxy directly.</div>
`}
</div>
<div class="gateway-footer">
<dees-button
.text=${'Save dcrouter Settings'}
.type=${'default'}
.icon=${'lucide:Save'}
@click=${() => this.saveExternalGatewaySettings()}
></dees-button>
<div slot="footer" class="gateway-footer">
<button class="tile-button primary" type="button" @click=${() => this.saveExternalGatewaySettings()}>
Save dcrouter Settings
</button>
</div>
</section>
</dees-tile>
`;
}
@@ -329,7 +410,7 @@ export class ObViewSettings extends DeesElement {
isPassword = false,
): TemplateResult {
return html`
<div class="gateway-field ${key === 'dcrouterGatewayUrl' ? 'full' : ''}">
<div class="gateway-field ${key === 'dcrouterGatewayUrl' || key === 'adminUiDomain' ? 'full' : ''}">
<dees-input-text
.key=${key}
.label=${label}
@@ -393,4 +474,15 @@ export class ObViewSettings extends DeesElement {
});
await appstate.settingsStatePart.dispatchAction(appstate.fetchManagedDcRouterStatusAction, null);
}
private async saveAdminUiSettings(): Promise<void> {
const settings = this.settingsState.settings;
if (!settings) return;
await appstate.settingsStatePart.dispatchAction(appstate.updateSettingsAction, {
settings: {
adminUiDomain: settings.adminUiDomain || '',
},
});
}
}
+142 -21
View File
@@ -12,19 +12,30 @@ type IExecutionEnvironment = import('@design.estate/dees-catalog').IExecutionEnv
type IFileEntry = import('@design.estate/dees-catalog').IFileEntry;
type IFileWatcher = import('@design.estate/dees-catalog').IFileWatcher;
type IProcessHandle = import('@design.estate/dees-catalog').IProcessHandle;
type IWorkspaceShellCommand = interfaces.requests.IWorkspaceShellCommand;
const domtools = plugins.deesElement.domtools;
interface IWorkspaceProcessState {
outputController: ReadableStreamDefaultController<string>;
resolveExit: (exitCodeArg: number) => void;
}
export class BackendExecutionEnvironment implements IExecutionEnvironment {
readonly type = 'backend' as const;
private _ready = false;
private identity: interfaces.data.IIdentity;
private processRouter = new plugins.domtools.plugins.typedrequest.TypedRouter();
private processSocket: InstanceType<typeof plugins.typedsocket.TypedSocket> | null = null;
private processSocketPromise: Promise<InstanceType<typeof plugins.typedsocket.TypedSocket>> | null = null;
private processStates = new Map<string, IWorkspaceProcessState>();
constructor(
private serviceName: string,
identity: interfaces.data.IIdentity,
) {
this.identity = identity;
this.registerProcessSocketHandlers();
}
get ready(): boolean {
@@ -44,6 +55,12 @@ export class BackendExecutionEnvironment implements IExecutionEnvironment {
}
async destroy(): Promise<void> {
for (const processId of Array.from(this.processStates.keys())) {
await this.killProcess(processId).catch(() => {});
}
await this.processSocket?.stop().catch(() => {});
this.processSocket = null;
this.processSocketPromise = null;
this._ready = false;
}
@@ -103,38 +120,142 @@ export class BackendExecutionEnvironment implements IExecutionEnvironment {
}
async spawn(command: string, args?: string[]): Promise<IProcessHandle> {
// For interactive shell: execute the command via the workspace exec API
// and return a process handle that bridges stdin/stdout
const cmd = args ? [command, ...args] : [command];
const fullCommand = cmd.join(' ');
const socket = await this.ensureProcessSocket();
const processId = crypto.randomUUID();
await socket.setTag(`workspaceProcess:${processId}`, true);
// Use a non-interactive exec for now — full interactive shell would need
// TypedSocket bidirectional streaming (to be implemented)
const result = await this.fireRequest<interfaces.requests.IReq_WorkspaceExec>(
'workspaceExec',
{ command: cmd[0], args: cmd.slice(1) },
);
// Create a ReadableStream from the exec output
let resolveExit: (exitCodeArg: number) => void = () => {};
const exit = new Promise<number>((resolve) => {
resolveExit = resolve;
});
const output = new ReadableStream<string>({
start(controller) {
if (result.stdout) controller.enqueue(result.stdout);
if (result.stderr) controller.enqueue(result.stderr);
controller.close();
start: (controller) => {
this.processStates.set(processId, {
outputController: controller,
resolveExit,
});
},
cancel: async () => {
await this.killProcess(processId).catch(() => {});
},
});
// Create a writable stream (no-op for non-interactive)
const inputStream = new WritableStream<string>();
try {
await socket.createTypedRequest<interfaces.requests.IReq_WorkspaceStartProcess>(
'workspaceStartProcess',
).fire({
identity: this.identity,
serviceName: this.serviceName,
processId,
command,
args,
});
} catch (error) {
const processState = this.processStates.get(processId);
this.processStates.delete(processId);
await socket.removeTag(`workspaceProcess:${processId}`).catch(() => {});
try {
processState?.outputController.error(error);
} catch {
// The stream may already have been cancelled by the terminal.
}
throw error;
}
const input = new WritableStream<string>({
write: async (chunkArg) => {
await socket.createTypedRequest<interfaces.requests.IReq_WorkspaceProcessInput>(
'workspaceProcessInput',
).fire({
identity: this.identity,
processId,
input: chunkArg,
});
},
abort: async () => {
await this.killProcess(processId).catch(() => {});
},
});
return {
output,
input: inputStream,
exit: Promise.resolve(result.exitCode),
kill: () => {},
input,
exit,
kill: () => {
void this.killProcess(processId);
},
};
}
async getShellCommand(): Promise<IWorkspaceShellCommand> {
const result = await this.fireRequest<interfaces.requests.IReq_WorkspaceGetShellCommand>(
'workspaceGetShellCommand',
{},
);
return result.shellCommand;
}
private registerProcessSocketHandlers(): void {
this.processRouter.addTypedHandler(
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushWorkspaceProcessOutput>(
'pushWorkspaceProcessOutput',
async (dataArg: interfaces.requests.IReq_PushWorkspaceProcessOutput['request']) => {
this.processStates.get(dataArg.processId)?.outputController.enqueue(dataArg.output);
return {};
},
),
);
this.processRouter.addTypedHandler(
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushWorkspaceProcessExit>(
'pushWorkspaceProcessExit',
async (dataArg: interfaces.requests.IReq_PushWorkspaceProcessExit['request']) => {
this.completeProcessState(dataArg.processId, dataArg.exitCode);
await this.processSocket?.removeTag(`workspaceProcess:${dataArg.processId}`).catch(() => {});
return {};
},
),
);
}
private async ensureProcessSocket(): Promise<InstanceType<typeof plugins.typedsocket.TypedSocket>> {
if (this.processSocket) return this.processSocket;
if (!this.processSocketPromise) {
this.processSocketPromise = plugins.typedsocket.TypedSocket.createClient(
this.processRouter,
plugins.typedsocket.TypedSocket.useWindowLocationOriginUrl(),
{ autoReconnect: true },
);
}
this.processSocket = await this.processSocketPromise;
return this.processSocket;
}
private completeProcessState(processIdArg: string, exitCodeArg: number): void {
const processState = this.processStates.get(processIdArg);
if (!processState) return;
try {
processState.outputController.close();
} catch {
// The terminal may already have cancelled the stream.
}
processState.resolveExit(exitCodeArg);
this.processStates.delete(processIdArg);
}
private async killProcess(processIdArg: string): Promise<void> {
const socket = this.processSocket;
if (!socket) return;
await socket.createTypedRequest<interfaces.requests.IReq_WorkspaceKillProcess>(
'workspaceKillProcess',
).fire({
identity: this.identity,
processId: processIdArg,
}).catch(() => {});
this.completeProcessState(processIdArg, -1);
await socket.removeTag(`workspaceProcess:${processIdArg}`).catch(() => {});
}
/**
* Helper to fire TypedRequests to the workspace API
*/