mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ export class SubContainer<
|
||||
}
|
||||
}
|
||||
|
||||
static async with<
|
||||
static async withTemp<
|
||||
Manifest extends T.SDKManifest,
|
||||
T,
|
||||
Effects extends T.Effects,
|
||||
|
||||
4
sdk/package/package-lock.json
generated
4
sdk/package/package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user