feat(appstore): add service volumes and published ports
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { BaseMigration } from './base-migration.ts';
|
||||
import type { TQueryFunction } from '../types.ts';
|
||||
|
||||
export class Migration016ServiceVolumes extends BaseMigration {
|
||||
readonly version = 16;
|
||||
readonly description = 'Add persistent volume declarations to services';
|
||||
|
||||
up(query: TQueryFunction): void {
|
||||
query(`ALTER TABLE services ADD COLUMN volumes TEXT DEFAULT '[]'`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { BaseMigration } from './base-migration.ts';
|
||||
import type { TQueryFunction } from '../types.ts';
|
||||
|
||||
export class Migration017ServicePublishedPorts extends BaseMigration {
|
||||
readonly version = 17;
|
||||
readonly description = 'Add raw published port declarations to services';
|
||||
|
||||
up(query: TQueryFunction): void {
|
||||
query(`ALTER TABLE services ADD COLUMN published_ports TEXT DEFAULT '[]'`);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import { Migration012GfsRetention } from './migration-012-gfs-retention.ts';
|
||||
import { Migration013AppTemplateVersion } from './migration-013-app-template-version.ts';
|
||||
import { Migration014ContainerArchive } from './migration-014-containerarchive.ts';
|
||||
import { Migration015SmartProxyPlatformService } from './migration-015-smartproxy-platform-service.ts';
|
||||
import { Migration016ServiceVolumes } from './migration-016-service-volumes.ts';
|
||||
import { Migration017ServicePublishedPorts } from './migration-017-service-published-ports.ts';
|
||||
import type { BaseMigration } from './base-migration.ts';
|
||||
|
||||
export class MigrationRunner {
|
||||
@@ -48,6 +50,8 @@ export class MigrationRunner {
|
||||
new Migration013AppTemplateVersion(),
|
||||
new Migration014ContainerArchive(),
|
||||
new Migration015SmartProxyPlatformService(),
|
||||
new Migration016ServiceVolumes(),
|
||||
new Migration017ServicePublishedPorts(),
|
||||
].sort((a, b) => a.version - b.version);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,17 +14,19 @@ export class ServiceRepository extends BaseRepository {
|
||||
const now = Date.now();
|
||||
this.query(
|
||||
`INSERT INTO services (
|
||||
name, image, registry, env_vars, port, domain, container_id, status,
|
||||
name, image, registry, env_vars, volumes, published_ports, port, domain, container_id, status,
|
||||
created_at, updated_at,
|
||||
use_onebox_registry, registry_repository, registry_image_tag,
|
||||
auto_update_on_push, image_digest, platform_requirements,
|
||||
app_template_id, app_template_version
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
service.name,
|
||||
service.image,
|
||||
service.registry || null,
|
||||
JSON.stringify(service.envVars),
|
||||
JSON.stringify(service.volumes || []),
|
||||
JSON.stringify(service.publishedPorts || []),
|
||||
service.port,
|
||||
service.domain || null,
|
||||
service.containerID || null,
|
||||
@@ -82,6 +84,14 @@ export class ServiceRepository extends BaseRepository {
|
||||
fields.push('env_vars = ?');
|
||||
values.push(JSON.stringify(updates.envVars));
|
||||
}
|
||||
if (updates.volumes !== undefined) {
|
||||
fields.push('volumes = ?');
|
||||
values.push(JSON.stringify(updates.volumes));
|
||||
}
|
||||
if (updates.publishedPorts !== undefined) {
|
||||
fields.push('published_ports = ?');
|
||||
values.push(JSON.stringify(updates.publishedPorts));
|
||||
}
|
||||
if (updates.port !== undefined) {
|
||||
fields.push('port = ?');
|
||||
values.push(updates.port);
|
||||
@@ -169,18 +179,42 @@ export class ServiceRepository extends BaseRepository {
|
||||
}
|
||||
}
|
||||
|
||||
let volumes = [];
|
||||
const volumesRaw = row.volumes ?? row[20];
|
||||
if (volumesRaw && volumesRaw !== 'undefined' && volumesRaw !== 'null') {
|
||||
try {
|
||||
volumes = JSON.parse(String(volumesRaw));
|
||||
} catch (e) {
|
||||
logger.warn(`Failed to parse volumes for service: ${getErrorMessage(e)}`);
|
||||
volumes = [];
|
||||
}
|
||||
}
|
||||
|
||||
let publishedPorts = [];
|
||||
const publishedPortsRaw = row.published_ports;
|
||||
if (publishedPortsRaw && publishedPortsRaw !== 'undefined' && publishedPortsRaw !== 'null') {
|
||||
try {
|
||||
publishedPorts = JSON.parse(String(publishedPortsRaw));
|
||||
} catch (e) {
|
||||
logger.warn(`Failed to parse published_ports for service: ${getErrorMessage(e)}`);
|
||||
publishedPorts = [];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: Number(row.id || row[0]),
|
||||
name: String(row.name || row[1]),
|
||||
image: String(row.image || row[2]),
|
||||
registry: (row.registry || row[3]) ? String(row.registry || row[3]) : undefined,
|
||||
envVars,
|
||||
port: Number(row.port || row[5]),
|
||||
domain: (row.domain || row[6]) ? String(row.domain || row[6]) : undefined,
|
||||
containerID: (row.container_id || row[7]) ? String(row.container_id || row[7]) : undefined,
|
||||
status: String(row.status || row[8]) as IService['status'],
|
||||
createdAt: Number(row.created_at || row[9]),
|
||||
updatedAt: Number(row.updated_at || row[10]),
|
||||
volumes,
|
||||
publishedPorts,
|
||||
port: Number(row.port ?? row[6] ?? row[5]),
|
||||
domain: (row.domain ?? row[7] ?? row[6]) ? String(row.domain ?? row[7] ?? row[6]) : undefined,
|
||||
containerID: (row.container_id ?? row[8] ?? row[7]) ? String(row.container_id ?? row[8] ?? row[7]) : undefined,
|
||||
status: String(row.status ?? row[9] ?? row[8]) as IService['status'],
|
||||
createdAt: Number(row.created_at ?? row[10] ?? row[9]),
|
||||
updatedAt: Number(row.updated_at ?? row[11] ?? row[10]),
|
||||
useOneboxRegistry: row.use_onebox_registry ? Boolean(row.use_onebox_registry) : undefined,
|
||||
registryRepository: row.registry_repository ? String(row.registry_repository) : undefined,
|
||||
registryImageTag: row.registry_image_tag ? String(row.registry_image_tag) : undefined,
|
||||
|
||||
Reference in New Issue
Block a user