Major migration to Deno runtime following the nupst project pattern: Core Changes: - Created deno.json configuration with tasks, imports, and settings - Created mod.ts as main entry point with Deno permissions - Updated all TypeScript imports from .js to .ts extensions - Replaced Node.js APIs (process.exit) with Deno equivalents (Deno.exit) - Updated path imports to use @std/path from JSR Dependencies: - Migrated all npm dependencies to use npm: prefix in import map - Added Deno standard library imports (@std/path, @std/assert) - Configured import aliases for all @push.rocks and @serve.zone packages Build & Distribution: - Created install.sh for downloading pre-compiled binaries - Created uninstall.sh for clean system removal - Created scripts/compile-all.sh for multi-platform compilation - Supports Linux (x64, ARM64), macOS (x64, ARM64), Windows (x64) Testing: - Migrated tests to Deno test framework using @std/assert - Created test.simple.ts for basic verification - Updated test structure to use Deno.test instead of tap CI/CD: - Created .gitea/workflows/ci.yml for type checking, linting, and builds - Created .gitea/workflows/release.yml for automated releases - Created .gitea/release-template.md for release documentation Cleanup: - Removed package.json, pnpm-lock.yaml, tsconfig.json - Removed Node.js CLI files (cli.js, cli.child.ts, cli.ts.js) - Removed dist_ts/ compiled output directory - Removed npmextra.json configuration This migration enables standalone binary distribution without Node.js runtime dependency while maintaining all existing functionality.
95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
import * as plugins from './spark.plugins.ts';
|
|
import * as paths from './spark.paths.ts';
|
|
import { Spark } from './spark.classes.spark.ts';
|
|
import { logger } from './spark.logging.ts';
|
|
|
|
/**
|
|
* this class takes care of updating the services that are managed by spark
|
|
*/
|
|
export class SparkServicesManager {
|
|
public sparkRef: Spark;
|
|
public dockerHost: plugins.docker.DockerHost;
|
|
public smartupdate: plugins.smartupdate.SmartUpdate;
|
|
|
|
/**
|
|
* the services that are managed by spark
|
|
*/
|
|
services: Array<{
|
|
name: string;
|
|
image: string;
|
|
url: string;
|
|
port: string;
|
|
environment: string;
|
|
secretJson: any;
|
|
}> = [];
|
|
|
|
constructor(sparkrefArg: Spark) {
|
|
this.sparkRef = sparkrefArg;
|
|
this.dockerHost = new plugins.docker.DockerHost({});
|
|
this.smartupdate = new plugins.smartupdate.SmartUpdate();
|
|
}
|
|
|
|
/**
|
|
* start the instance
|
|
*/
|
|
public async start() {
|
|
await this.dockerHost.activateSwarm();
|
|
}
|
|
|
|
public async updateServices() {
|
|
for (const service of this.services) {
|
|
const existingService = await plugins.docker.DockerService.getServiceByName(
|
|
this.dockerHost,
|
|
service.name
|
|
);
|
|
const existingServiceSecret = await plugins.docker.DockerSecret.getSecretByName(
|
|
this.dockerHost,
|
|
`${service.name}Secret`
|
|
);
|
|
if (existingService) {
|
|
const needsUpdate: boolean = await existingService.needsUpdate();
|
|
if (!needsUpdate) {
|
|
logger.log('info', `service >>${service.name}<< not needing update.`);
|
|
// we simply return here to end the functions
|
|
return;
|
|
}
|
|
// continuing here means we need to update the service
|
|
logger.log('ok', `${service.name} needs to be updated!`);
|
|
await existingService.remove();
|
|
await existingServiceSecret.remove();
|
|
}
|
|
if (!existingService && existingServiceSecret) {
|
|
await existingServiceSecret.remove();
|
|
}
|
|
|
|
const newServiceImage = await plugins.docker.DockerImage.createFromRegistry(
|
|
this.dockerHost,
|
|
{
|
|
creationObject: {
|
|
imageUrl: service.image,
|
|
},
|
|
}
|
|
);
|
|
const newServiceSecret = await plugins.docker.DockerSecret.createSecret(this.dockerHost, {
|
|
name: `${service.name}Secret`,
|
|
contentArg: plugins.smartjson.stringify(service.secretJson),
|
|
version: await newServiceImage.getVersion(),
|
|
labels: {},
|
|
});
|
|
|
|
const newService = await plugins.docker.DockerService.createService(this.dockerHost, {
|
|
image: newServiceImage,
|
|
labels: {},
|
|
name: service.name,
|
|
networkAlias: service.name,
|
|
networks: [],
|
|
secrets: [newServiceSecret],
|
|
ports: [`${service.port}:${service.secretJson.SERVEZONE_PORT}`],
|
|
});
|
|
logger.log('ok', `updated service >>${newService.Spec.Name}<<!`);
|
|
}
|
|
|
|
logger.log('success', `updated ${this.services.length} services!`);
|
|
}
|
|
}
|