修改docker部署方式

This commit is contained in:
ChuNa7a committed 2026-10-17 13:13:26 +08:00
1 parent a6179aba6a
commit 16e5db3b26
16 files changed
+299 -95

No files matched your search

+26 -25
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Build the API and stage external ChuSQL artifacts without committing dependencies."""
"""Build deployment images inside Docker; no host Rust or Haskell tools required."""
import argparse
from pathlib import Path
import shutil
@@ -7,28 +7,29 @@ import subprocess
root = Path(__file__).resolve().parents[1]
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--no-build', action='store_true', help='use an existing API release binary')
parser.add_argument('--chusql-source', type=Path, default=root / 'external/ChuSQL', help='initialized/built external ChuSQL checkout')
parser.add_argument('--build-database', action='store_true', help='build external database artifacts before staging')
parser.add_argument('--env-file', type=Path, help='Compose environment file (default: .env, or .env.example when absent)')
parser.add_argument('--build-database', action='store_true', help='compatibility option; database is always built inside Docker')
parser.add_argument('--sources-env-file', type=Path, help='optional second Compose env file overriding build download sources')
args = parser.parse_args()
chusql = args.chusql_source.resolve()
if not (root / 'external/ChuSQL-RustDriver/Cargo.toml').is_file():
parser.error('Initialize external dependencies with scripts/init-deps.py first.')
if not (chusql / 'chusql-core/storage/Cargo.toml').is_file():
parser.error(f'ChuSQL source is missing: {chusql}; initialize dependencies first.')
if not args.no_build:
subprocess.run(['cargo', 'build', '--locked', '--release'], cwd=root, check=True)
if args.build_database:
subprocess.run(['cargo', 'build', '--locked', '--release'], cwd=chusql / 'chusql-core/storage', check=True)
for package in ['chusql-server', 'chusql-bootstrap']:
subprocess.run(['stack', 'build', '--fast'], cwd=chusql / package, check=True)
out = root / 'deploy/bin'
out.mkdir(parents=True, exist_ok=True)
shutil.copy2(root / 'target/release/chublog-api', out / 'chublog-api')
for package, executable in [('chusql-server', 'chusql-server'), ('chusql-bootstrap', 'csql-bootstrap')]:
matches = list((chusql / package / '.stack-work/install').glob(f'*/**/bin/{executable}'))
if len(matches) != 1:
raise SystemExit(f'Expected one built {executable}, found {len(matches)}; use --build-database or select a built --chusql-source.')
shutil.copy2(matches[0], out / executable)
shutil.copy2(chusql / 'chusql-core/storage/target/release/libchusql_core_storage.so', out)
print('Prepared ignored deploy/bin. Build and run Compose on the same Debian 13 architecture.')
if shutil.which('docker') is None:
parser.error('Docker with the Compose plugin is required; see docs/deployment.md.')
for manifest in ['external/ChuSQL-RustDriver/Cargo.toml', 'external/ChuSQL/chusql-core/storage/Cargo.toml']:
if not (root / manifest).is_file():
parser.error('Initialize external dependencies with python3 scripts/init-deps.py first.')
envfile = args.env_file or (root / '.env' if (root / '.env').is_file() else root / '.env.example')
if not envfile.is_file():
parser.error(f'Environment file does not exist: {envfile}')
command = ['docker', 'compose', '--env-file', str(envfile.resolve())]
if args.sources_env_file:
if not args.sources_env_file.is_file():
parser.error(f'Source configuration does not exist: {args.sources_env_file}')
command.extend(['--env-file', str(args.sources_env_file.resolve())])
command.extend([
'-f', str(root / 'deploy/compose.yaml'),
'build', 'init', 'api', 'ssh', 'db', 'db-init', 'web',
])
try:
subprocess.run(command, cwd=root, check=True)
except subprocess.CalledProcessError as error:
raise SystemExit(error.returncode) from None
print('Deployment images built inside Docker. No host binaries were created.')