@h-ai/deploy 0.1.0-alpha.65 → 0.1.0-alpha.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +46 -169
- package/README.ja.md +46 -169
- package/README.md +88 -144
- package/dist/index.d.ts +51 -26
- package/dist/index.js +486 -470
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -1,202 +1,79 @@
|
|
|
1
1
|
# @h-ai/deploy
|
|
2
2
|
|
|
3
|
-
[简体中文](
|
|
3
|
+
[简体中文](README.md) | [English](README.en.md) | [日本語](README.ja.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Deploy consumes existing artifacts. It never compiles source or builds images. Build once, deploy the same images to multiple environments.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Follow the [usage guide](../../docs/usage/README.en.md) for the complete creation, development, build, and deployment workflow. This page focuses on deployment requirements, the SDK, and module development.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Build
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| ------------ | --------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
13
|
-
| `docker-ssh` | Native Node services or SvelteKit with adapter-node | Build locally, upload over SSH, run Compose on Linux and check HTTP health |
|
|
14
|
-
| `vercel` | SvelteKit with adapter-vercel | Build, upload, set environment variables and wait for deployment; requires internet |
|
|
11
|
+
Node `^22.22.2 || ^24.15.0 || >=26.0.0`, pnpm 12.11.2; Windows: `pnpm.cmd`. Node 20 / pnpm 9.5.0 are unsupported.
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
**Fullstack API and Web are separate deployments.** `hai deploy packages/my-app-serv` deploys the API only. The root template Dockerfile has `runtime` and `web` targets for API and static Web images. Upload and run Web separately, setting `PUBLIC_API_BASE` and API CORS. There is no command to publish both together, nor automatic domain, TLS or reverse proxy configuration.
|
|
22
|
-
|
|
23
|
-
## Command-line deployment
|
|
24
|
-
|
|
25
|
-
### 1. Install and prepare
|
|
26
|
-
|
|
27
|
-
Node must satisfy `^22.22.2 || ^24.15.0 || >=26.0.0`; generated projects pin `pnpm@12.11.2`. Node 20 / pnpm 9.5.0 are unsupported. Use `pnpm.cmd` in Windows PowerShell.
|
|
28
|
-
|
|
29
|
-
In the generated workspace root, install CLI/SDK versions matching the application's framework and retain the lockfile. Installation needs a package source or complete offline dependencies:
|
|
30
|
-
|
|
31
|
-
```powershell
|
|
32
|
-
pnpm.cmd add -Dw @h-ai/cli @h-ai/deploy
|
|
33
|
-
pnpm.cmd exec hai --help
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Creation with `--features deploy` already adds the local SDK, but does not install a global `hai`. With a global CLI, run `hai deploy` directly. The template's `pnpm run deploy` packages artifacts; it does not invoke this deployment command.
|
|
37
|
-
|
|
38
|
-
For docker-ssh, prepare:
|
|
39
|
-
|
|
40
|
-
- A running local Docker/Podman engine capable of building Linux images for the server architecture. Windows needs the corresponding virtualization/WSL2/VM environment; a client alone is insufficient. `auto` prefers Podman; Docker can be selected explicitly.
|
|
41
|
-
- Local `ssh` and `scp`, noninteractive key/agent authentication and the server host fingerprint.
|
|
42
|
-
- Remote Docker/Podman with its `compose` command. The SSH user must run containers and write the deployment directory. Windows must reach SSH and the exposed application port.
|
|
43
|
-
- `config/_deploy.yml` in the target package and `.env.prod` or `.env.test` in the environment directory. Missing environment files stop deployment.
|
|
44
|
-
|
|
45
|
-
### 2. Configure target and environment
|
|
46
|
-
|
|
47
|
-
Minimal `config/_deploy.yml` for Docker; supply machine-specific target details through the whole-object `HAI_DEPLOY_PROVIDER` override in `.env.local`:
|
|
48
|
-
|
|
49
|
-
```yaml
|
|
50
|
-
provider:
|
|
51
|
-
type: docker-ssh
|
|
52
|
-
container:
|
|
53
|
-
runtime: docker
|
|
54
|
-
s3Engine: rustfs
|
|
55
|
-
services: {}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Replace the host, user, ports and key path for your environment. Never commit `.env.local`:
|
|
59
|
-
|
|
60
|
-
```dotenv
|
|
61
|
-
HAI_DEPLOY_PROVIDER='{"type":"docker-ssh","ssh":{"host":"10.0.0.20","port":22,"username":"deploy","identityFile":"C:/Users/me/.ssh/hai_deploy"},"remote":{"baseDir":"/opt/hai/apps","runtime":"docker"},"expose":{"type":"port","containerPort":3000,"hostPort":18080}}'
|
|
13
|
+
```sh
|
|
14
|
+
pnpm build # source only; no environment selection
|
|
15
|
+
pnpm build --target docker # reachable Podman first, then Docker
|
|
16
|
+
pnpm build --target docker --runtime docker
|
|
17
|
+
pnpm build --target desktop --platform windows --arch x64
|
|
62
18
|
```
|
|
63
19
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Precedence: `.env` → `.env.<mode>` → `.env.local` → process environment. Parent JSON such as `HAI_DB` overrides child variables. `.env.example` documents all fields and enums. Commit `.env` and `.env.dev/test/prod`; keep real credentials in `.env.local`. Fullstack's first start also needs a private `HAI_ADMIN_DEFAULT_PASSWORD` satisfying the IAM password policy.
|
|
67
|
-
|
|
68
|
-
Fullstack production also requires an explicit Web Origin in `.env.prod`, such as `HAI_SERV_CORS_ORIGIN=https://app.hai.internal`; the default `*` prevents production startup. Production refresh cookies use Secure, so Web/API need trusted HTTPS endpoints. Exposing HTTP ports alone does not validate complete login/session refresh.
|
|
20
|
+
`hai.build.json` describes Docker targets and Tauri directories. Images and SHA-256 manifest are under `.hai/build/docker/<buildId>`. API/Web share one build ID; latest changes only after complete success. Tauri runs on the matching Windows/Linux/macOS host with Rust targets, SDKs and packaging tools installed; installers are under `src-tauri/target/<target>/release/bundle`. Build has no dev/test/prod mode and excludes deployment credentials.
|
|
69
21
|
|
|
70
|
-
|
|
22
|
+
Versions come from the application root package.json.version. For version 1.2.3, archives are app-1.2.3.tar/web-1.2.3.tar and Compose is docker-compose-1.2.3.yml. Manifest version: 2 is its format; appVersion is the application version. --output release-prod.tar becomes release-prod-1.2.3.tar, and Tauri receives the same root version. See the [complete guide](../../docs/usage/README.en.md) for defaults and examples.
|
|
71
23
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```powershell
|
|
75
|
-
pnpm.cmd exec hai deploy packages/my-app-serv --env prod --env-dir .
|
|
76
|
-
```
|
|
24
|
+
## Deployment
|
|
77
25
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
pnpm
|
|
26
|
+
```sh
|
|
27
|
+
pnpm run deploy --env test
|
|
28
|
+
pnpm run deploy --env prod --artifact-dir .hai/build/docker/<buildId> --skip-middleware
|
|
29
|
+
pnpm run deploy --env prod --bundle-only --output release-prod.tar
|
|
30
|
+
# equivalent fullstack CLI invocation
|
|
31
|
+
pnpm exec hai deploy packages/my-app-serv --env prod --env-dir .
|
|
84
32
|
```
|
|
85
33
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
`--project-name <name>` sets the name; an explicit environment adds a suffix. **`--skip-build` currently skips only Vercel application builds. docker-ssh always builds an image and has no option to deploy a specified existing image directly.** Failures return a nonzero exit code.
|
|
89
|
-
|
|
90
|
-
## docker-ssh execution and files
|
|
91
|
-
|
|
92
|
-
1. Use the target package's Dockerfile, or generate a fallback with the workspace root as context. Fullstack service packages use the fallback by default, not the root Web target.
|
|
93
|
-
2. Build the image locally and export a tar with `docker/podman save`.
|
|
94
|
-
3. Check the remote engine and Compose over SSH, upload the tar with SCP, then run `load` remotely.
|
|
95
|
-
4. Generate `compose.yml`, `.env.runtime` and `start-<mode>.sh` locally and upload each to `<baseDir>/<projectName>-<mode>/`. These are separate from the image archive; no single Compose bundle is uploaded and no source build runs on Linux.
|
|
96
|
-
5. The remote script sets `HAI_DEPLOY_ENVIRONMENT`/`HAI_CORE_ENV` and runs `compose --env-file .env.runtime ... up -d`. The SDK checks native `/health` or SvelteKit `/` from the local machine before succeeding.
|
|
97
|
-
|
|
98
|
-
Local artifacts live in the target package's Git-ignored `.hai/deploy/<mode>/`. Remote `.env.runtime` uses mode `600`. Retain local artifacts for repeat deployment: keep unchanged preserves services/volumes from the previous local Compose, not arbitrary server-side Compose definitions. Exclude private environment files and deployment archives from image contexts.
|
|
99
|
-
|
|
100
|
-
## Fully offline deployment
|
|
101
|
-
|
|
102
|
-
Offline means no internet; Windows and Linux must still communicate over an internal SSH/HTTP network. Vercel and cloud provisioning are unavailable.
|
|
103
|
-
|
|
104
|
-
### Materials to bring in advance
|
|
34
|
+
Requires matching `@h-ai/cli` / `@h-ai/deploy`, `_deploy.yml`, lockfile and `.env.<mode>`. Missing environment files stop deployment. Public `.env`, `.env.dev/test/prod` and documented `.env.example` are committed; private `.env.local` is ignored. Priority: process > local > mode > base. SSH fields/tokens can be stored in private `HAI_DEPLOY_PROVIDER` JSON. Bundle-only needs no SSH config or local container engine.
|
|
105
35
|
|
|
106
|
-
|
|
107
|
-
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
108
|
-
| Windows tools | Compatible Node (for example a supported Node 24), pnpm 12.11.2, installed CLI/SDK and transitive dependencies, OpenSSH, initialized and runnable Linux container engine |
|
|
109
|
-
| Project | Complete source, pinned lockfile, environment files and private credentials; `pnpm.cmd exec hai --help` must work offline. Avoid on-demand `npx` / `pnpm dlx` downloads |
|
|
110
|
-
| Linux | Docker CLI/Engine, Compose plugin (`docker compose version` works), authorized SSH key, container permissions, writable deployment directory, ports and disk space. Host Node/pnpm are unnecessary for running images |
|
|
111
|
-
| Images | API, Web and middleware images matching Linux CPU architecture and exact Compose names/tags; import with `docker load -i <archive.tar>` |
|
|
112
|
-
| Application | PostgreSQL database/account, Redis connection/password, RustFS keys/bucket and initial administrator password. Existing services must already run and be reachable from the app container; `localhost` means that container |
|
|
36
|
+
The wizard traverses only lockfile runtime dependencies, excluding dev/peer. Select default, custom or keep for each middleware; `--skip-middleware` bypasses all middleware work. Compose supports PostgreSQL/MySQL/Redis/RustFS/MinIO/Qdrant/pgvector/Chroma/OpenLDAP/Mailpit. Optional cloud provisioning supports Neon/Upstash/R2/Resend/Aliyun SMS and requires network access.
|
|
113
37
|
|
|
114
|
-
|
|
38
|
+
Optional `container.s3Engine` defaults to rustfs and chooses RustFS/MinIO only when creating a Compose S3 service. Existing custom S3 services are unaffected. Use `--skip-middleware` to bypass middleware setup; the SDK field is `skipMiddleware`.
|
|
115
39
|
|
|
116
|
-
|
|
40
|
+
A single private tar contains Compose, runtime env, app/web images, optional Web proxy, checksums, README and `start-<mode>.sh`. SSH uploads this tar, extracts and starts it remotely. No source upload or remote build. With app/web images, Web exposes the public port and proxies the internal API on the same origin; no API secrets enter Web. Online success requires both health checks. Vercel uploads existing `.vercel/output` , sets runtime variables and never builds locally.
|
|
117
41
|
|
|
118
|
-
|
|
42
|
+
## Offline / manual transfer
|
|
119
43
|
|
|
120
|
-
|
|
44
|
+
Prepare supported Node/pnpm and installed project CLI/SDK dependencies on Windows, plus the complete prebuilt image directory for the Linux server architecture. Deploy requires tar locally; automatic mode also needs ssh/scp, trusted host keys and reachable SSH/application ports. Bundle-only works with removable media and no network between machines.
|
|
121
45
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```powershell
|
|
125
|
-
docker build --target runtime -t my-app-api:offline .
|
|
126
|
-
docker build --target web -t my-app-web:offline .
|
|
127
|
-
docker save -o my-app-images.tar my-app-api:offline my-app-web:offline
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Import the archive into the offline Windows Linux engine with `docker load -i my-app-images.tar`. Create `packages/my-app-serv/Dockerfile` containing only:
|
|
131
|
-
|
|
132
|
-
```dockerfile
|
|
133
|
-
FROM my-app-api:offline
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Add a service-package `.dockerignore` containing `*`. This makes the SDK's mandatory build reuse the finished API without package installation. Rebuild the finished image after source changes. Configure the target, then run the deployment command above. To create middleware containers, select `HAI_DB_TYPE=postgresql`, `HAI_CACHE_TYPE=redis`, `HAI_STORAGE_TYPE=s3` in `.env.prod` and choose defaults in the wizard. For existing services, enter custom connections; once complete, `--skip-middleware` is available. The SDK uploads the API image. Rehearse with internet disconnected to confirm the builder needs no network.
|
|
137
|
-
|
|
138
|
-
Transfer the Web image separately. This example assumes separately prepared internal TLS endpoints `https://app.hai.internal` and `https://api.hai.internal`, proxying Web port 18081 and API port 18080. Bring proxy configuration/images and certificates, configure internal DNS/hosts and client certificate trust, then run over SSH:
|
|
46
|
+
Linux needs Docker/Podman, compose, sh, tar, sha256sum, writable deployment/data directories and container permissions. Middleware images must already be loaded with the exact names/tags printed in the bundle README; app/web archives are included. Missing images stop startup without downloading. Custom connections require reachable running services, accounts, databases/buckets and credentials.
|
|
139
47
|
|
|
140
48
|
```sh
|
|
141
|
-
|
|
142
|
-
|
|
49
|
+
mkdir -p release && chmod 700 release
|
|
50
|
+
tar -xf release-prod-1.2.3.tar -C release
|
|
51
|
+
cd release
|
|
52
|
+
HAI_DEPLOY_PROVIDER_REMOTE_RUNTIME=docker sh start-prod.sh
|
|
143
53
|
```
|
|
144
54
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
Official references: Docker [save](https://docs.docker.com/reference/cli/docker/image/save/) / [load](https://docs.docker.com/reference/cli/docker/image/load/), [pnpm install](https://pnpm.io/cli/install), [Compose plugin installation](https://docs.docker.com/compose/install/linux/).
|
|
148
|
-
|
|
149
|
-
## SDK and failures
|
|
150
|
-
|
|
151
|
-
Scripts do not need the CLI. Supply parsed configuration; use public `loadDeploymentEnvironment` / `loadDeploymentConfig` for the same environment resolution:
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
import type { DeployConfigInput } from '@h-ai/deploy'
|
|
155
|
-
import { deploy } from '@h-ai/deploy'
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 使用现有中间件发布生产 API,并释放部署模块。
|
|
159
|
-
* @param config - 从部署环境解析得到的配置
|
|
160
|
-
* @returns 初始化或部署的 HaiResult,由调用者检查 success
|
|
161
|
-
* @example `const result = await publish(config)`
|
|
162
|
-
*/
|
|
163
|
-
export async function publish(config: DeployConfigInput) {
|
|
164
|
-
const initialized = await deploy.init(config)
|
|
165
|
-
if (!initialized.success)
|
|
166
|
-
return initialized
|
|
167
|
-
try {
|
|
168
|
-
return await deploy.deployApp('./packages/my-app-serv', {
|
|
169
|
-
environment: 'prod',
|
|
170
|
-
envDir: '.',
|
|
171
|
-
skipProvision: true,
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
await deploy.close()
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
```
|
|
55
|
+
The tar contains secrets: restrict permissions and never commit it. `packaged` means no server has been started or health-checked. After manual startup, use `docker compose -f docker-compose-1.2.3.yml --env-file .env.runtime ps` (or logs), then verify Web, /health, real login/refresh, restart and persistence. Production sessions need HTTPS, trusted certificates, DNS and correct CORS; TLS is managed separately.
|
|
179
56
|
|
|
180
|
-
|
|
57
|
+
Prebuilt deployment needs no local container engine, Linux Node base image, compiler, CUDA or SQLite download. Fully offline **building** separately needs Linux base images, pnpm/Corepack, complete Linux dependency caches and SQLite prebuilds matching driver/ABI/architecture/libc. Windows node_modules are insufficient. Use `pnpm build --target docker --sqlite-prebuild-mirror http://trusted-host/better-sqlite3` when appropriate. No AI runtime dependency means no AI/CUDA installation. Cloud services are unsuitable offline. Prove offline behavior by actually disconnecting; online tests do not establish it.
|
|
181
58
|
|
|
182
|
-
|
|
59
|
+
## SDK / development
|
|
183
60
|
|
|
184
|
-
|
|
61
|
+
Call `deploy.init(config)`, check success, then `deploy.deployApp(appDir, { environment: 'prod', envDir: '.', artifactDir, bundleOnly: true })`, check success and finally `deploy.close()`. `deploy.scan` / credentials do not require init. Results return bundlePath/instructions for packaged mode, URL and health status for automatic deployment.
|
|
185
62
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
pnpm
|
|
190
|
-
pnpm
|
|
191
|
-
pnpm
|
|
192
|
-
pnpm
|
|
193
|
-
pnpm
|
|
63
|
+
```sh
|
|
64
|
+
pnpm --filter @h-ai/deploy typecheck
|
|
65
|
+
pnpm --filter @h-ai/deploy lint
|
|
66
|
+
pnpm --filter @h-ai/deploy build
|
|
67
|
+
pnpm --filter @h-ai/deploy test
|
|
68
|
+
pnpm --filter @h-ai/cli test
|
|
69
|
+
pnpm --filter @h-ai/cli test:scaffold-gates
|
|
70
|
+
pnpm --filter @h-ai/cli test:deploy-gates
|
|
194
71
|
```
|
|
195
72
|
|
|
196
|
-
|
|
73
|
+
Deploy gates generate fullstack from current archives, build API/Web once, exercise SSH and manual bundle startup and run real browser flows. Tests clean temporary projects, images, containers, screenshots/reports and helper processes in finally/teardown even on failure. Native installer acceptance requires each OS. See [configuration and middleware](../cli/templates/skills/hai-deploy/middleware.md) and [complete examples](README.md).
|
|
197
74
|
|
|
198
|
-
|
|
75
|
+
Deploy gates do not forward host proxies by default. To download build dependencies through a proxy, set test-only `HAI_DEPLOY_E2E_CONTAINER_PROXY` (unset by default), for example `$env:HAI_DEPLOY_E2E_CONTAINER_PROXY='http://host.containers.internal:10808'` in PowerShell for Windows Podman. The address must be reachable from build containers; it is not written to application configuration or release images.
|
|
199
76
|
|
|
200
|
-
|
|
77
|
+
Test-only `HAI_DEPLOY_E2E_CONTAINER_NETWORK` is unset by default and forwards its value to build's `--network`. For example, rootless Podman can use `$env:HAI_DEPLOY_E2E_CONTAINER_NETWORK='pasta'`. Build and run networks may differ; verify the proxy address on the build network too.
|
|
201
78
|
|
|
202
|
-
|
|
79
|
+
On Windows, set test-only HAI_CLI_NATIVE_BUILD=1 (unset by default), then run `pnpm --filter @h-ai/cli test:scaffold-gates -t "fullstack scaffold"`. With Rust/MSVC/Windows SDK installed, it additionally builds the generated Tauri installer and checks that root version 2.4.6 appears in the exe filename. The temporary project and native output are cleaned automatically.
|
package/README.ja.md
CHANGED
|
@@ -1,202 +1,79 @@
|
|
|
1
1
|
# @h-ai/deploy
|
|
2
2
|
|
|
3
|
-
[简体中文](
|
|
3
|
+
[简体中文](README.md) | [English](README.en.md) | [日本語](README.ja.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
deploy は既存の成果物だけを配布します。ソースのコンパイルやイメージのビルドは行いません。同じイメージを複数環境へ配布できます。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
作成、開発、ビルド、デプロイの全体は[使用ガイド](../../docs/usage/README.ja.md)を参照してください。本ページではデプロイの準備、SDK、モジュール開発を説明します。
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## ビルド
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| ------------ | -------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
13
|
-
| `docker-ssh` | Node サービス、adapter-node を使う SvelteKit | ローカルでイメージをビルドし、SSH で転送、Linux の Compose で起動、HTTP ヘルスチェック |
|
|
14
|
-
| `vercel` | adapter-vercel を使う SvelteKit | ビルド、転送、環境変数設定、結果の待機。インターネット接続が必要 |
|
|
11
|
+
Node `^22.22.2 || ^24.15.0 || >=26.0.0` と pnpm 12.11.2 を使用します。Windows では `pnpm.cmd` を実行してください。Node 20 / pnpm 9.5.0 は対象外です。
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
**fullstack の API と Web は別々にデプロイします。** `hai deploy packages/my-app-serv` は API のみが対象です。ルート Dockerfile の `runtime` / `web` target で API / 静的 Web イメージをビルドできます。Web は別途転送・起動し、`PUBLIC_API_BASE` と API の CORS を設定します。同時公開コマンド、ドメイン・TLS・リバースプロキシの自動設定はありません。
|
|
22
|
-
|
|
23
|
-
## コマンドラインでの利用
|
|
24
|
-
|
|
25
|
-
### 1. インストールと準備
|
|
26
|
-
|
|
27
|
-
Node は `^22.22.2 || ^24.15.0 || >=26.0.0` が必要です。生成プロジェクトは `pnpm@12.11.2` を固定します。Node 20 / pnpm 9.5.0 は非対応です。Windows PowerShell では `pnpm.cmd` を使います。
|
|
28
|
-
|
|
29
|
-
生成 workspace のルートでアプリのフレームワークに合う CLI/SDK をインストールし、lockfile を保持します。パッケージ配布元または完全なオフライン依存が必要です。
|
|
30
|
-
|
|
31
|
-
```powershell
|
|
32
|
-
pnpm.cmd add -Dw @h-ai/cli @h-ai/deploy
|
|
33
|
-
pnpm.cmd exec hai --help
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
作成時の `--features deploy` はローカル SDK を追加しますが、グローバル `hai` のインストールは行いません。CLI をグローバル導入済みなら `hai deploy` を直接使えます。テンプレートの `pnpm run deploy` はパッケージ作成用で、このコマンドとは異なります。
|
|
37
|
-
|
|
38
|
-
docker-ssh の前提条件:
|
|
39
|
-
|
|
40
|
-
- サーバーのアーキテクチャー向け Linux イメージをビルドできるローカル Docker/Podman エンジン。Windows は仮想化/WSL2/VM の準備・起動が必要で、クライアントだけでは不足します。`auto` は Podman 優先、Docker の明示指定も可能です。
|
|
41
|
-
- ローカル `ssh` / `scp`、非対話の鍵/agent 認証、サーバーのホスト指紋。
|
|
42
|
-
- Linux の Docker/Podman と対応する `compose` コマンド。SSH ユーザーのコンテナ実行・ディレクトリー書き込み権限。Windows から SSH とアプリ公開ポートへ接続できること。
|
|
43
|
-
- 対象パッケージの `config/_deploy.yml` と、環境ディレクトリーの `.env.prod` / `.env.test`。環境ファイルがなければ停止します。
|
|
44
|
-
|
|
45
|
-
### 2. 接続先と環境の設定
|
|
46
|
-
|
|
47
|
-
Docker 用の最小 `config/_deploy.yml` です。実際の接続先は `.env.local` の `HAI_DEPLOY_PROVIDER` オブジェクトで上書きします。
|
|
48
|
-
|
|
49
|
-
```yaml
|
|
50
|
-
provider:
|
|
51
|
-
type: docker-ssh
|
|
52
|
-
container:
|
|
53
|
-
runtime: docker
|
|
54
|
-
s3Engine: rustfs
|
|
55
|
-
services: {}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
ホスト、ユーザー、ポート、鍵のパスを実際の値に置き換えます。`.env.local` は Git に登録しません。
|
|
59
|
-
|
|
60
|
-
```dotenv
|
|
61
|
-
HAI_DEPLOY_PROVIDER='{"type":"docker-ssh","ssh":{"host":"10.0.0.20","port":22,"username":"deploy","identityFile":"C:/Users/me/.ssh/hai_deploy"},"remote":{"baseDir":"/opt/hai/apps","runtime":"docker"},"expose":{"type":"port","containerPort":3000,"hostPort":18080}}'
|
|
13
|
+
```sh
|
|
14
|
+
pnpm build # ソースだけをコンパイル。環境は選択しない
|
|
15
|
+
pnpm build --target docker # 利用可能な Podman、次に Docker
|
|
16
|
+
pnpm build --target docker --runtime docker
|
|
17
|
+
pnpm build --target desktop --platform windows --arch x64
|
|
62
18
|
```
|
|
63
19
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
上書き順は `.env` → `.env.<mode>` → `.env.local` → プロセス環境変数です。`HAI_DB` など親 JSON が子の変数より優先されます。`.env.example` に全項目・説明・列挙値を記載し、`.env` と `.env.dev/test/prod` は Git 登録、実際の認証情報は `.env.local` に保存します。fullstack 初回起動には IAM ポリシーを満たす非公開の `HAI_ADMIN_DEFAULT_PASSWORD` も必要です。
|
|
67
|
-
|
|
68
|
-
fullstack 本番は `.env.prod` に `HAI_SERV_CORS_ORIGIN=https://app.hai.internal` など明示的な Web Origin が必要です。既定の `*` では本番起動に失敗します。本番 refresh Cookie は Secure のため、Web/API に信頼済み HTTPS 入口を準備します。HTTP ポートの公開だけでログイン・セッション更新まで検証済みとは判定できません。
|
|
20
|
+
`hai.build.json` で Dockerfile のステージと Tauri ディレクトリーを指定します。イメージと SHA-256 付きマニフェストは `.hai/build/docker/<buildId>` に出力されます。API/Web は同じビルド ID を使い、すべて成功してから latest を更新します。Tauri は対象の Windows/Linux/macOS 上で実行し、対応する Rust target、SDK、パッケージツールが必要です。インストーラーは `src-tauri/target/<target>/release/bundle` に出力されます。ビルドでは dev/test/prod を選ばず、デプロイの認証情報も取り込みません。
|
|
69
21
|
|
|
70
|
-
|
|
22
|
+
版はアプリルートの package.json.version を使います。例 1.2.3 では app-1.2.3.tar、web-1.2.3.tar、docker-compose-1.2.3.yml を生成します。マニフェスト形式の版は version: 2、アプリ版は appVersion です。--output release-prod.tar は release-prod-1.2.3.tar になり、Tauri も同じ版を使います。既定値と例は[完全ガイド](../../docs/usage/README.ja.md)を参照してください。
|
|
71
23
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```powershell
|
|
75
|
-
pnpm.cmd exec hai deploy packages/my-app-serv --env prod --env-dir .
|
|
76
|
-
```
|
|
24
|
+
## デプロイ
|
|
77
25
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
pnpm
|
|
26
|
+
```sh
|
|
27
|
+
pnpm run deploy --env test
|
|
28
|
+
pnpm run deploy --env prod --artifact-dir .hai/build/docker/<buildId> --skip-middleware
|
|
29
|
+
pnpm run deploy --env prod --bundle-only --output release-prod.tar
|
|
30
|
+
# fullstack で同じ処理を直接呼ぶ場合
|
|
31
|
+
pnpm exec hai deploy packages/my-app-serv --env prod --env-dir .
|
|
84
32
|
```
|
|
85
33
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
`--project-name <name>` で名前を指定し、環境指定時は環境サフィックスが付きます。**`--skip-build` は現在 Vercel のアプリビルドのみを省略します。docker-ssh は必ずイメージをビルドし、既存イメージを直接指定するオプションはありません。** 失敗時は非ゼロ終了コードを返します。
|
|
89
|
-
|
|
90
|
-
## docker-ssh の処理とファイル
|
|
91
|
-
|
|
92
|
-
1. 対象パッケージの Dockerfile を使います。なければ workspace ルートを context にする代替 Dockerfile を生成します。fullstack サービスの既定は代替で、ルートの Web target は使いません。
|
|
93
|
-
2. ローカルでビルドし、`docker/podman save` で tar を作成します。
|
|
94
|
-
3. SSH で遠隔エンジンと Compose を確認し、SCP で tar を転送、遠隔で `load` します。
|
|
95
|
-
4. `compose.yml`、`.env.runtime`、`start-<mode>.sh` をローカル生成して個別に `<baseDir>/<projectName>-<mode>/` へ転送します。イメージとは別送で、Compose 全体の圧縮パッケージや Linux 上でのソースビルドではありません。
|
|
96
|
-
5. 遠隔スクリプトが `HAI_DEPLOY_ENVIRONMENT` / `HAI_CORE_ENV` を設定し、`compose --env-file .env.runtime ... up -d` を実行します。SDK はローカルから Node の `/health` または SvelteKit の `/` を確認して成功を返します。
|
|
97
|
-
|
|
98
|
-
ローカル成果物は対象パッケージの Git 対象外 `.hai/deploy/<mode>/` に保存します。遠隔 `.env.runtime` は権限 `600` です。再デプロイ用にローカル成果物を保持してください。「変更しない」は前回のローカル Compose のサービス/ボリュームを維持するもので、任意の遠隔 Compose を読み込みません。非公開環境ファイル・デプロイアーカイブはイメージに含めません。
|
|
99
|
-
|
|
100
|
-
## 完全オフラインのデプロイ
|
|
101
|
-
|
|
102
|
-
インターネットに接続しなくても、Windows と Linux 間の内部 SSH/HTTP 通信は必要です。Vercel・クラウド作成は利用できません。
|
|
103
|
-
|
|
104
|
-
### 事前に持ち込む材料
|
|
34
|
+
対応する版の `@h-ai/cli` / `@h-ai/deploy`、`_deploy.yml`、lockfile、`.env.<mode>` が必要です。環境ファイルがなければ処理を停止します。公開設定の `.env`、`.env.dev/test/prod` と説明付き `.env.example` は Git に登録し、私有の `.env.local` は除外します。優先順位はプロセス変数 > local > 環境別 > 基本設定です。SSH の接続情報やトークンは私有の `HAI_DEPLOY_PROVIDER` JSON に保存できます。bundle-only では SSH 設定やローカルのコンテナーエンジンは不要です。
|
|
105
35
|
|
|
106
|
-
|
|
107
|
-
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
108
|
-
| Windows | 対応 Node(条件を満たす Node 24 など)、pnpm 12.11.2、導入済み CLI/SDK と推移的依存、OpenSSH、初期化・起動済み Linux コンテナエンジン |
|
|
109
|
-
| プロジェクト | 完全なソース・固定 lockfile・環境設定・認証情報。オフラインで `pnpm.cmd exec hai --help` が成功すること。現場での `npx` / `pnpm dlx` ダウンロードを避ける |
|
|
110
|
-
| Linux | Docker CLI/Engine と Compose プラグイン(`docker compose version` 成功)、SSH 公開鍵登録、権限、公開ポート、書き込み先、ディスク容量。イメージ実行だけならホスト Node/pnpm は不要 |
|
|
111
|
-
| イメージ | Linux の CPU 構成と一致する API・Web・ミドルウェア。Compose と完全一致する名前/tag。`docker load -i <archive.tar>` で読み込む |
|
|
112
|
-
| アプリ設定 | PostgreSQL DB/アカウント、Redis 接続/パスワード、RustFS 鍵/バケット、初回管理者パスワード。既存サービスは起動・到達可能にする。`localhost` はアプリコンテナ自身 |
|
|
36
|
+
ウィザードは lockfile の実行時依存だけをたどり、dev/peer を除外します。ミドルウェアごとに既定構成、独自構成、既存設定の保持を選べます。`--skip-middleware` はミドルウェア処理全体を省略します。Compose は PostgreSQL/MySQL/Redis/RustFS/MinIO/Qdrant/pgvector/Chroma/OpenLDAP/Mailpit に対応します。任意のクラウド作成は Neon/Upstash/R2/Resend/Aliyun SMS に対応し、ネットワーク接続が必要です。
|
|
113
37
|
|
|
114
|
-
|
|
38
|
+
`container.s3Engine` は任意で、既定値は rustfs です。Compose で S3 サービスを自動作成するときだけ RustFS/MinIO を選び、独自の既存 S3 には影響しません。ミドルウェア処理の省略は CLI の `--skip-middleware`、SDK の `skipMiddleware` で指定します。
|
|
115
39
|
|
|
116
|
-
|
|
40
|
+
一つの私有 tar に Compose、実行時の環境変数、app/web イメージ、必要な Web プロキシ、チェックサム、README、`start-<mode>.sh` をまとめます。SSH でこの tar を転送し、リモートで展開・起動します。ソースの転送やリモートビルドは行いません。app/web 構成では Web の公開ポートから同一オリジンで内部 API に接続し、API の秘密情報は Web に渡しません。自動デプロイの成功には両方のヘルスチェック通過が必要です。Vercel は既存の `.vercel/output` を転送して実行時変数を設定し、ローカルビルドは行いません。
|
|
117
41
|
|
|
118
|
-
|
|
42
|
+
## オフラインと手動転送
|
|
119
43
|
|
|
120
|
-
|
|
44
|
+
Windows 側に対応する Node/pnpm、インストール済みの CLI/SDK 依存関係、Linux サーバーのアーキテクチャーに合う構築済みイメージのディレクトリー全体を準備します。ローカルには tar が必要です。自動転送では ssh/scp、信頼済みホスト鍵、SSH とアプリのポートへの接続も必要です。bundle-only なら、二台の間にネットワークがなくても外部メディアで運べます。
|
|
121
45
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```powershell
|
|
125
|
-
docker build --target runtime -t my-app-api:offline .
|
|
126
|
-
docker build --target web -t my-app-web:offline .
|
|
127
|
-
docker save -o my-app-images.tar my-app-api:offline my-app-web:offline
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
オフライン Windows の Linux エンジンに `docker load -i my-app-images.tar` で導入します。`packages/my-app-serv/Dockerfile` は次の一行にします。
|
|
131
|
-
|
|
132
|
-
```dockerfile
|
|
133
|
-
FROM my-app-api:offline
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
サービスパッケージに内容 `*` の `.dockerignore` を追加します。SDK の必須ビルドは完成 API を再利用し、パッケージを取得しません。ソース変更後は完成イメージを再作成します。接続先を設定して上記デプロイを実行してください。ミドルウェアコンテナを作成するなら `.env.prod` で `HAI_DB_TYPE=postgresql`、`HAI_CACHE_TYPE=redis`、`HAI_STORAGE_TYPE=s3` を選び、ウィザードで既定設定を使います。既存サービスはカスタム接続を設定し、完了後は `--skip-middleware` も使えます。API イメージは SDK が転送します。外部接続を切ったリハーサルで、ビルダーが通信不要であることを確認します。
|
|
137
|
-
|
|
138
|
-
Web イメージは別途転送します。以下は内網 TLS 入口 `https://app.hai.internal` / `https://api.hai.internal` が準備済みで、それぞれ Web 18081 / API 18080 を代理する前提です。プロキシ設定/イメージ・証明書を持ち込み、内部 DNS/hosts とクライアントの信頼を設定してから SSH で実行します。
|
|
46
|
+
Linux 側には Docker/Podman、compose、sh、tar、sha256sum、書き込み可能な配布・データディレクトリー、コンテナー操作権限が必要です。ミドルウェアイメージは tar 内の README に記載された名前とタグで読み込んでください。app/web のアーカイブは同梱されます。イメージが不足すると、ダウンロードせずに起動を停止します。独自接続では利用可能なサービス、アカウント、DB/バケット、認証情報を準備します。
|
|
139
47
|
|
|
140
48
|
```sh
|
|
141
|
-
|
|
142
|
-
|
|
49
|
+
mkdir -p release && chmod 700 release
|
|
50
|
+
tar -xf release-prod-1.2.3.tar -C release
|
|
51
|
+
cd release
|
|
52
|
+
HAI_DEPLOY_PROVIDER_REMOTE_RUNTIME=docker sh start-prod.sh
|
|
143
53
|
```
|
|
144
54
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
公式資料:[Docker save](https://docs.docker.com/reference/cli/docker/image/save/) / [load](https://docs.docker.com/reference/cli/docker/image/load/)、[pnpm install](https://pnpm.io/cli/install)、[Compose プラグイン](https://docs.docker.com/compose/install/linux/)。
|
|
148
|
-
|
|
149
|
-
## SDK とエラー処理
|
|
150
|
-
|
|
151
|
-
スクリプト利用に CLI は不要です。解析済み設定を渡し、同じ環境解決には公開 `loadDeploymentEnvironment` / `loadDeploymentConfig` を使います。
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
import type { DeployConfigInput } from '@h-ai/deploy'
|
|
155
|
-
import { deploy } from '@h-ai/deploy'
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 使用现有中间件发布生产 API,并释放部署模块。
|
|
159
|
-
* @param config - 从部署环境解析得到的配置
|
|
160
|
-
* @returns 初始化或部署的 HaiResult,由调用者检查 success
|
|
161
|
-
* @example `const result = await publish(config)`
|
|
162
|
-
*/
|
|
163
|
-
export async function publish(config: DeployConfigInput) {
|
|
164
|
-
const initialized = await deploy.init(config)
|
|
165
|
-
if (!initialized.success)
|
|
166
|
-
return initialized
|
|
167
|
-
try {
|
|
168
|
-
return await deploy.deployApp('./packages/my-app-serv', {
|
|
169
|
-
environment: 'prod',
|
|
170
|
-
envDir: '.',
|
|
171
|
-
skipProvision: true,
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
await deploy.close()
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
```
|
|
55
|
+
tar には秘密情報が含まれるため、アクセス権を制限し、Git に登録しないでください。`packaged` はサーバー起動やヘルスチェックをまだ行っていない状態です。手動起動後は `docker compose -f docker-compose-1.2.3.yml --env-file .env.runtime ps`(または logs)、Web、/health、実際のログインと再読み込み、再起動とデータ保持を確認します。本番のセッションには HTTPS、信頼できる証明書、DNS、正しい CORS が必要で、TLS は別途設定します。
|
|
179
56
|
|
|
180
|
-
|
|
57
|
+
構築済み成果物の配布には、ローカルのコンテナーエンジン、Linux Node ベースイメージ、コンパイラー、CUDA、SQLite のダウンロードは不要です。完全オフラインでの**ビルド**には、別途 Linux ベースイメージ、pnpm/Corepack、Linux 用依存キャッシュ一式、driver/ABI/アーキテクチャー/libc が一致する SQLite バイナリーが必要です。Windows の node_modules だけでは足りません。必要に応じて `pnpm build --target docker --sqlite-prebuild-mirror http://trusted-host/better-sqlite3` を使えます。AI の実行時依存がなければ AI/CUDA は不要です。クラウドサービスはオフラインでは使えません。完全オフラインの動作は実際に接続を切って確認してください。
|
|
181
58
|
|
|
182
|
-
|
|
59
|
+
## SDK とモジュール開発
|
|
183
60
|
|
|
184
|
-
|
|
61
|
+
`deploy.init(config)` の成功を確認してから `deploy.deployApp(appDir, { environment: 'prod', envDir: '.', artifactDir, bundleOnly: true })` を呼び、結果を確認し、最後に `deploy.close()` を実行します。`deploy.scan` と credentials は初期化不要です。packaged の結果には bundlePath/instructions、自動デプロイの結果には URL とヘルス状態が入ります。
|
|
185
62
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
pnpm
|
|
190
|
-
pnpm
|
|
191
|
-
pnpm
|
|
192
|
-
pnpm
|
|
193
|
-
pnpm
|
|
63
|
+
```sh
|
|
64
|
+
pnpm --filter @h-ai/deploy typecheck
|
|
65
|
+
pnpm --filter @h-ai/deploy lint
|
|
66
|
+
pnpm --filter @h-ai/deploy build
|
|
67
|
+
pnpm --filter @h-ai/deploy test
|
|
68
|
+
pnpm --filter @h-ai/cli test
|
|
69
|
+
pnpm --filter @h-ai/cli test:scaffold-gates
|
|
70
|
+
pnpm --filter @h-ai/cli test:deploy-gates
|
|
194
71
|
```
|
|
195
72
|
|
|
196
|
-
|
|
73
|
+
デプロイのゲートは現在のソースをパッケージ化して fullstack を生成し、API/Web を一度構築してから、SSH と手動 tar の起動、実際のブラウザー操作を検証します。失敗時も finally/teardown で一時プロジェクト、イメージ、コンテナー、スクリーンショット・レポート、補助プロセスを削除します。ネイティブインストーラーは各 OS での確認が必要です。[設定とミドルウェア](../cli/templates/skills/hai-deploy/middleware.md)、[詳細な例](README.md)も参照してください。
|
|
197
74
|
|
|
198
|
-
|
|
75
|
+
デプロイのゲートは既定でホストのプロキシを転送しません。依存のダウンロードに必要な場合、テスト専用 `HAI_DEPLOY_E2E_CONTAINER_PROXY`(既定は未設定)を設定します。Windows Podman の PowerShell の例は `$env:HAI_DEPLOY_E2E_CONTAINER_PROXY='http://host.containers.internal:10808'` です。ビルドコンテナーから到達できるアドレスを使い、アプリ設定や配布イメージには保存しません。
|
|
199
76
|
|
|
200
|
-
|
|
77
|
+
テスト専用 `HAI_DEPLOY_E2E_CONTAINER_NETWORK` は既定では未設定で、設定値を build の `--network` に渡します。rootless Podman の例は `$env:HAI_DEPLOY_E2E_CONTAINER_NETWORK='pasta'` です。build と run ではネットワークが異なる場合があるため、ビルド側でプロキシの到達性も確認してください。
|
|
201
78
|
|
|
202
|
-
|
|
79
|
+
Windows ではテスト専用 HAI_CLI_NATIVE_BUILD=1(既定は未設定)を指定し、`pnpm --filter @h-ai/cli test:scaffold-gates -t "fullstack scaffold"` を実行できます。Rust/MSVC/Windows SDK が必要で、生成 Tauri インストーラーの exe 名にルート版 2.4.6 が反映されることを確認します。一時プロジェクトとネイティブ出力も自動削除します。
|