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": {
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.4",
"version": "0.4.0-beta.6",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",

View File

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

View File

@@ -298,23 +298,6 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
nullIfEmpty,
useEntrypoint: (overrideCmd?: string[]) =>
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.
*
@@ -785,13 +768,13 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
return SubContainer.of(effects, image, mounts, name)
},
/**
* @description Create a new SubContainer
* @description Run a function with a temporary SubContainer
* @param effects
* @param image - what container image to use
* @param mounts - what to mount to the subcontainer
* @param name - a name to use to refer to the ephemeral subcontainer for debugging purposes
*/
with<T>(
withTemp<T>(
effects: T.Effects,
image: {
imageId: T.ImageId & keyof Manifest["images"]
@@ -801,7 +784,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
name: string,
fn: (subContainer: SubContainer<Manifest>) => Promise<T>,
): Promise<T> {
return SubContainer.with(effects, image, mounts, name, fn)
return SubContainer.withTemp(effects, image, mounts, name, fn)
},
},
List: {
@@ -1194,7 +1177,7 @@ export async function runCommand<Manifest extends T.SDKManifest>(
commands = imageMeta.entrypoint ?? []
commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? []))
} else commands = splitCommand(command)
return SubContainer.with(
return SubContainer.withTemp(
effects,
image,
options.mounts,

View File

@@ -76,6 +76,26 @@ export class Backups<M extends T.SDKManifest> {
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(
volume: M["volumes"][number],
options?: Partial<{
@@ -128,6 +148,7 @@ export class Backups<M extends T.SDKManifest> {
}
async restoreBackup(effects: T.Effects) {
this.preRestore(effects as BackupEffects)
const store = await fs
.readFile("/media/startos/backup/store.json", {
encoding: "utf-8",
@@ -150,13 +171,14 @@ export class Backups<M extends T.SDKManifest> {
},
})
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
}
}

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
{
"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",
"main": "./package/lib/index.js",
"types": "./package/lib/index.d.ts",