sdk beta.6 (#2885)

beta.6
This commit is contained in:
Aiden McClelland
2025-04-22 12:00:34 -06:00
committed by GitHub
parent 113154702f
commit c85ea7d8fa
8 changed files with 45 additions and 38 deletions

View File

@@ -37,7 +37,7 @@
}, },
"../sdk/dist": { "../sdk/dist": {
"name": "@start9labs/start-sdk", "name": "@start9labs/start-sdk",
"version": "0.3.6-beta.4", "version": "0.4.0-beta.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@iarna/toml": "^2.2.5", "@iarna/toml": "^2.2.5",

View File

@@ -8,9 +8,10 @@ use rpc_toolkit::{
use crate::context::{CliContext, DiagnosticContext, RpcContext}; use crate::context::{CliContext, DiagnosticContext, RpcContext};
use crate::init::SYSTEM_REBUILD_PATH; use crate::init::SYSTEM_REBUILD_PATH;
use crate::prelude::*;
use crate::shutdown::Shutdown; use crate::shutdown::Shutdown;
use crate::util::io::delete_file; use crate::util::io::delete_file;
use crate::{Error, DATA_DIR}; use crate::DATA_DIR;
pub fn diagnostic<C: Context>() -> ParentHandler<C> { pub fn diagnostic<C: Context>() -> ParentHandler<C> {
ParentHandler::new() ParentHandler::new()
@@ -74,7 +75,8 @@ pub fn restart(ctx: DiagnosticContext) -> Result<(), Error> {
.map(|guid| (guid, Path::new(DATA_DIR).to_owned())), .map(|guid| (guid, Path::new(DATA_DIR).to_owned())),
restart: true, restart: true,
}) })
.expect("receiver dropped"); .map_err(|_| eyre!("receiver dropped"))
.log_err();
Ok(()) Ok(())
} }
pub async fn rebuild(ctx: DiagnosticContext) -> Result<(), Error> { pub async fn rebuild(ctx: DiagnosticContext) -> Result<(), Error> {

View File

@@ -91,8 +91,8 @@ pub async fn shutdown(ctx: RpcContext) -> Result<(), Error> {
export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())), export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())),
restart: false, restart: false,
})) }))
.map_err(|_| ()) .map_err(|_| eyre!("receiver dropped"))
.expect("receiver dropped"); .log_err();
Ok(()) Ok(())
} }
@@ -112,8 +112,8 @@ pub async fn restart(ctx: RpcContext) -> Result<(), Error> {
export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())), export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())),
restart: true, restart: true,
})) }))
.map_err(|_| ()) .map_err(|_| eyre!("receiver dropped"))
.expect("receiver dropped"); .log_err();
Ok(()) Ok(())
} }

View File

@@ -298,23 +298,6 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
nullIfEmpty, nullIfEmpty,
useEntrypoint: (overrideCmd?: string[]) => useEntrypoint: (overrideCmd?: string[]) =>
new T.UseEntrypoint(overrideCmd), new T.UseEntrypoint(overrideCmd),
runCommand: async <A extends string>(
effects: Effects,
image: {
imageId: keyof Manifest["images"] & T.ImageId
sharedRun?: boolean
},
command: T.CommandType,
options: CommandOptions & {
mounts: Mounts<Manifest> | null
},
/**
* A name to use to refer to the ephemeral subcontainer for debugging purposes
*/
name?: string,
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> => {
return runCommand<Manifest>(effects, image, command, options, name)
},
/** /**
* @description Use this class to create an Action. By convention, each Action should receive its own file. * @description Use this class to create an Action. By convention, each Action should receive its own file.
* *
@@ -785,13 +768,13 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
return SubContainer.of(effects, image, mounts, name) return SubContainer.of(effects, image, mounts, name)
}, },
/** /**
* @description Create a new SubContainer * @description Run a function with a temporary SubContainer
* @param effects * @param effects
* @param image - what container image to use * @param image - what container image to use
* @param mounts - what to mount to the subcontainer * @param mounts - what to mount to the subcontainer
* @param name - a name to use to refer to the ephemeral subcontainer for debugging purposes * @param name - a name to use to refer to the ephemeral subcontainer for debugging purposes
*/ */
with<T>( withTemp<T>(
effects: T.Effects, effects: T.Effects,
image: { image: {
imageId: T.ImageId & keyof Manifest["images"] imageId: T.ImageId & keyof Manifest["images"]
@@ -801,7 +784,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
name: string, name: string,
fn: (subContainer: SubContainer<Manifest>) => Promise<T>, fn: (subContainer: SubContainer<Manifest>) => Promise<T>,
): Promise<T> { ): Promise<T> {
return SubContainer.with(effects, image, mounts, name, fn) return SubContainer.withTemp(effects, image, mounts, name, fn)
}, },
}, },
List: { List: {
@@ -1194,7 +1177,7 @@ export async function runCommand<Manifest extends T.SDKManifest>(
commands = imageMeta.entrypoint ?? [] commands = imageMeta.entrypoint ?? []
commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? [])) commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? []))
} else commands = splitCommand(command) } else commands = splitCommand(command)
return SubContainer.with( return SubContainer.withTemp(
effects, effects,
image, image,
options.mounts, options.mounts,

View File

@@ -76,6 +76,26 @@ export class Backups<M extends T.SDKManifest> {
return this return this
} }
setPreBackup(fn: (effects: BackupEffects) => Promise<void>) {
this.preBackup = fn
return this
}
setPostBackup(fn: (effects: BackupEffects) => Promise<void>) {
this.postBackup = fn
return this
}
setPreRestore(fn: (effects: BackupEffects) => Promise<void>) {
this.preRestore = fn
return this
}
setPostRestore(fn: (effects: BackupEffects) => Promise<void>) {
this.postRestore = fn
return this
}
addVolume( addVolume(
volume: M["volumes"][number], volume: M["volumes"][number],
options?: Partial<{ options?: Partial<{
@@ -128,6 +148,7 @@ export class Backups<M extends T.SDKManifest> {
} }
async restoreBackup(effects: T.Effects) { async restoreBackup(effects: T.Effects) {
this.preRestore(effects as BackupEffects)
const store = await fs const store = await fs
.readFile("/media/startos/backup/store.json", { .readFile("/media/startos/backup/store.json", {
encoding: "utf-8", encoding: "utf-8",
@@ -150,13 +171,14 @@ export class Backups<M extends T.SDKManifest> {
}, },
}) })
await rsyncResults.wait() await rsyncResults.wait()
const dataVersion = await fs
.readFile("/media/startos/backup/dataVersion.txt", {
encoding: "utf-8",
})
.catch((_) => null)
if (dataVersion) await effects.setDataVersion({ version: dataVersion })
} }
const dataVersion = await fs
.readFile("/media/startos/backup/dataVersion.txt", {
encoding: "utf-8",
})
.catch((_) => null)
if (dataVersion) await effects.setDataVersion({ version: dataVersion })
this.postRestore(effects as BackupEffects)
return return
} }
} }

View File

@@ -149,7 +149,7 @@ export class SubContainer<
} }
} }
static async with< static async withTemp<
Manifest extends T.SDKManifest, Manifest extends T.SDKManifest,
T, T,
Effects extends T.Effects, Effects extends T.Effects,

View File

@@ -1,12 +1,12 @@
{ {
"name": "@start9labs/start-sdk", "name": "@start9labs/start-sdk",
"version": "0.4.0-beta.5", "version": "0.4.0-beta.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@start9labs/start-sdk", "name": "@start9labs/start-sdk",
"version": "0.4.0-beta.5", "version": "0.4.0-beta.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@iarna/toml": "^3.0.0", "@iarna/toml": "^3.0.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@start9labs/start-sdk", "name": "@start9labs/start-sdk",
"version": "0.4.0-beta.5", "version": "0.4.0-beta.6",
"description": "Software development kit to facilitate packaging services for StartOS", "description": "Software development kit to facilitate packaging services for StartOS",
"main": "./package/lib/index.js", "main": "./package/lib/index.js",
"types": "./package/lib/index.d.ts", "types": "./package/lib/index.d.ts",