sdk tweaks (#2858)

* sdk tweaks

* beta.20

* alpha.18
This commit is contained in:
Aiden McClelland
2025-04-07 13:55:38 -06:00
committed by GitHub
parent 6ecaeb4fde
commit 20d3b5288c
16 changed files with 139 additions and 61 deletions

View File

@@ -9,6 +9,7 @@ import { Manifest } from "./matchManifest"
import { DockerProcedureContainer } from "./DockerProcedureContainer"
import * as cp from "child_process"
import { Effects } from "../../../Models/Effects"
import { Mounts } from "@start9labs/start-sdk/package/lib/mainFn/Mounts"
export const execFile = promisify(cp.execFile)
export const polyfillEffects = (
effects: Effects,
@@ -111,7 +112,7 @@ export const polyfillEffects = (
effects,
{ imageId: manifest.main.image },
commands,
{},
{ mounts: Mounts.of() },
commands.join(" "),
)
.then((x: any) => ({
@@ -168,17 +169,12 @@ export const polyfillEffects = (
{ imageId: manifest.main.image },
commands,
{
mounts: [
{
mountpoint: "/drive",
options: {
type: "volume",
id: input.volumeId,
subpath: null,
readonly: false,
},
},
],
mounts: Mounts.of().addVolume(
input.volumeId,
null,
"/drive",
false,
),
},
commands.join(" "),
)
@@ -210,17 +206,12 @@ export const polyfillEffects = (
{ imageId: manifest.main.image },
commands,
{
mounts: [
{
mountpoint: "/drive",
options: {
type: "volume",
id: input.volumeId,
subpath: null,
readonly: false,
},
},
],
mounts: Mounts.of().addVolume(
input.volumeId,
null,
"/drive",
false,
),
},
commands.join(" "),
)

2
core/Cargo.lock generated
View File

@@ -5952,7 +5952,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "start-os"
version = "0.3.6-alpha.17"
version = "0.3.6-alpha.18"
dependencies = [
"aes 0.7.5",
"async-acme",

View File

@@ -14,7 +14,7 @@ keywords = [
name = "start-os"
readme = "README.md"
repository = "https://github.com/Start9Labs/start-os"
version = "0.3.6-alpha.17" # VERSION_BUMP
version = "0.3.6-alpha.18" # VERSION_BUMP
license = "MIT"
[lib]

View File

@@ -37,8 +37,9 @@ mod v0_3_6_alpha_14;
mod v0_3_6_alpha_15;
mod v0_3_6_alpha_16;
mod v0_3_6_alpha_17;
mod v0_3_6_alpha_18;
pub type Current = v0_3_6_alpha_17::Version; // VERSION_BUMP
pub type Current = v0_3_6_alpha_18::Version; // VERSION_BUMP
impl Current {
#[instrument(skip(self, db))]
@@ -140,7 +141,8 @@ enum Version {
V0_3_6_alpha_14(Wrapper<v0_3_6_alpha_14::Version>),
V0_3_6_alpha_15(Wrapper<v0_3_6_alpha_15::Version>),
V0_3_6_alpha_16(Wrapper<v0_3_6_alpha_16::Version>),
V0_3_6_alpha_17(Wrapper<v0_3_6_alpha_17::Version>), // VERSION_BUMP
V0_3_6_alpha_17(Wrapper<v0_3_6_alpha_17::Version>),
V0_3_6_alpha_18(Wrapper<v0_3_6_alpha_18::Version>), // VERSION_BUMP
Other(exver::Version),
}
@@ -181,7 +183,8 @@ impl Version {
Self::V0_3_6_alpha_14(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_15(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_16(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_17(v) => DynVersion(Box::new(v.0)), // VERSION_BUMP
Self::V0_3_6_alpha_17(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_18(v) => DynVersion(Box::new(v.0)), // VERSION_BUMP
Self::Other(v) => {
return Err(Error::new(
eyre!("unknown version {v}"),
@@ -214,7 +217,8 @@ impl Version {
Version::V0_3_6_alpha_14(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_15(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_16(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_17(Wrapper(x)) => x.semver(), // VERSION_BUMP
Version::V0_3_6_alpha_17(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_18(Wrapper(x)) => x.semver(), // VERSION_BUMP
Version::Other(x) => x.clone(),
}
}

View File

@@ -0,0 +1,36 @@
use exver::{PreReleaseSegment, VersionRange};
use super::v0_3_5::V0_3_0_COMPAT;
use super::{v0_3_6_alpha_17, VersionT};
use crate::prelude::*;
lazy_static::lazy_static! {
static ref V0_3_6_alpha_18: exver::Version = exver::Version::new(
[0, 3, 6],
[PreReleaseSegment::String("alpha".into()), 18.into()]
);
}
#[derive(Clone, Copy, Debug, Default)]
pub struct Version;
impl VersionT for Version {
type Previous = v0_3_6_alpha_17::Version;
type PreUpRes = ();
async fn pre_up(self) -> Result<Self::PreUpRes, Error> {
Ok(())
}
fn semver(self) -> exver::Version {
V0_3_6_alpha_18.clone()
}
fn compat(self) -> &'static VersionRange {
&V0_3_0_COMPAT
}
fn up(self, _db: &mut Value, _: Self::PreUpRes) -> Result<(), Error> {
Ok(())
}
fn down(self, _db: &mut Value) -> Result<(), Error> {
Ok(())
}
}

View File

@@ -61,7 +61,7 @@ PLATFORM_CONFIG_EXTRAS=()
if [ "${IB_TARGET_PLATFORM}" = "raspberrypi" ]; then
PLATFORM_CONFIG_EXTRAS+=( --firmware-binary false )
PLATFORM_CONFIG_EXTRAS+=( --firmware-chroot false )
PLATFORM_CONFIG_EXTRAS+=( --linux-packages linux-image-6.6.51+rpt )
PLATFORM_CONFIG_EXTRAS+=( --linux-packages linux-image-6.12.20+rpt )
PLATFORM_CONFIG_EXTRAS+=( --linux-flavours "rpi-v8 rpi-2712" )
elif [ "${IB_TARGET_PLATFORM}" = "rockchip64" ]; then
PLATFORM_CONFIG_EXTRAS+=( --linux-flavours rockchip64 )
@@ -206,8 +206,8 @@ if [ "${IB_TARGET_PLATFORM}" = "raspberrypi" ]; then
echo "Configuring raspi kernel '\$v'"
extract-ikconfig "/usr/lib/modules/\$v/kernel/kernel/configs.ko.xz" > /boot/config-\$v
done
mkinitramfs -c gzip -o /boot/initramfs8 6.6.74-v8+
mkinitramfs -c gzip -o /boot/initramfs_2712 6.6.74-v8-16k+
mkinitramfs -c gzip -o /boot/initramfs8 6.12.20-v8+
mkinitramfs -c gzip -o /boot/initramfs_2712 6.12.20-v8-16k+
fi
useradd --shell /bin/bash -G startos -m start9

View File

@@ -33,18 +33,6 @@ export const knownProtocols = {
secure: { ssl: false },
defaultPort: 22,
},
bitcoin: {
secure: { ssl: false },
defaultPort: 8333,
},
lightning: {
secure: { ssl: true },
defaultPort: 9735,
},
grpc: {
secure: { ssl: true },
defaultPort: 50051,
},
dns: {
secure: { ssl: false },
defaultPort: 53,

View File

@@ -47,7 +47,12 @@ import { GetSystemSmtp } from "./util"
import { nullIfEmpty } from "./util"
import { getServiceInterface, getServiceInterfaces } from "./util"
import { getStore } from "./store/getStore"
import { CommandOptions, MountOptions, SubContainer } from "./util/SubContainer"
import {
CommandOptions,
ExitError,
MountOptions,
SubContainer,
} from "./util/SubContainer"
import { splitCommand } from "./util"
import { Mounts } from "./mainFn/Mounts"
import { setupDependencies } from "../../base/lib/dependencies/setupDependencies"
@@ -72,7 +77,7 @@ import * as actions from "../../base/lib/actions"
import { setupInit } from "./inits/setupInit"
import * as fs from "node:fs/promises"
export const OSVersion = testTypeVersion("0.3.6-alpha.17")
export const OSVersion = testTypeVersion("0.3.6-alpha.18")
// prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> =
@@ -286,7 +291,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
},
command: T.CommandType,
options: CommandOptions & {
mounts?: { mountpoint: string; options: MountOptions }[]
mounts: Mounts<Manifest>
},
/**
* A name to use to refer to the ephemeral subcontainer for debugging purposes
@@ -583,7 +588,10 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
})
* ```
*/
setupInstall: (fn: InstallFn<Manifest, Store>) => Install.of(fn),
setupInstall: (
fn: InstallFn<Manifest, Store>,
preFn?: InstallFn<Manifest, Store>,
) => Install.of(fn, preFn),
/**
* @description Use this function to determine how this service will be hosted and served. The function executes on service install, service update, and inputSpec save.
*
@@ -1132,7 +1140,7 @@ export async function runCommand<Manifest extends T.SDKManifest>(
image: { imageId: keyof Manifest["images"] & T.ImageId; sharedRun?: boolean },
command: T.CommandType,
options: CommandOptions & {
mounts?: { mountpoint: string; options: MountOptions }[]
mounts: Mounts<Manifest>
},
name?: string,
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> {
@@ -1150,7 +1158,7 @@ export async function runCommand<Manifest extends T.SDKManifest>(
return SubContainer.with(
effects,
image,
options.mounts || [],
options.mounts.build(),
name ||
commands
.map((c) => {
@@ -1161,6 +1169,13 @@ export async function runCommand<Manifest extends T.SDKManifest>(
}
})
.join(" "),
(subcontainer) => subcontainer.exec(commands),
async (subcontainer) => {
const res = await subcontainer.exec(commands)
if (res.exitCode || res.exitSignal) {
throw new ExitError(commands[0], res)
} else {
return res
}
},
)
}

View File

@@ -3,6 +3,7 @@ import { ExtendedVersion } from "../../../base/lib/exver"
import { UpdateServiceInterfaces } from "../../../base/lib/interfaces/setupInterfaces"
import { ExposedStorePaths } from "../../../base/lib/types"
import * as T from "../../../base/lib/types"
import { StorePath } from "../util"
import { VersionGraph } from "../version/VersionGraph"
import { Install } from "./setupInstall"
import { Uninstall } from "./setupUninstall"
@@ -16,6 +17,7 @@ export function setupInit<Manifest extends T.SDKManifest, Store>(
effects: T.Effects
}) => Promise<null | void | undefined>,
actions: Actions<Store, any>,
initStore: Store,
exposedStore: ExposedStorePaths,
): {
packageInit: T.ExpectedExports.packageInit
@@ -53,6 +55,14 @@ export function setupInit<Manifest extends T.SDKManifest, Store>(
}
},
containerInit: async (opts) => {
const prev = await opts.effects.getDataVersion()
if (!prev) {
await opts.effects.store.set({
path: "" as StorePath,
value: initStore,
})
await install.preInstall(opts)
}
await setServiceInterfaces({
...opts,
})

View File

@@ -4,11 +4,15 @@ export type InstallFn<Manifest extends T.SDKManifest, Store> = (opts: {
effects: T.Effects
}) => Promise<null | void | undefined>
export class Install<Manifest extends T.SDKManifest, Store> {
private constructor(readonly fn: InstallFn<Manifest, Store>) {}
private constructor(
readonly fn: InstallFn<Manifest, Store>,
readonly preFn?: InstallFn<Manifest, Store>,
) {}
static of<Manifest extends T.SDKManifest, Store>(
fn: InstallFn<Manifest, Store>,
preFn?: InstallFn<Manifest, Store>,
) {
return new Install(fn)
return new Install(fn, preFn)
}
async install({ effects }: Parameters<T.ExpectedExports.packageInit>[0]) {
@@ -16,10 +20,18 @@ export class Install<Manifest extends T.SDKManifest, Store> {
effects,
})
}
async preInstall({ effects }: Parameters<T.ExpectedExports.packageInit>[0]) {
this.preFn &&
(await this.preFn({
effects,
}))
}
}
export function setupInstall<Manifest extends T.SDKManifest, Store>(
fn: InstallFn<Manifest, Store>,
preFn?: InstallFn<Manifest, Store>,
) {
return Install.of(fn)
return Install.of(fn, preFn)
}

View File

@@ -172,7 +172,7 @@ export class Daemons<Manifest extends T.SDKManifest, Ids extends string>
daemon,
daemonIndex,
options.requires
.map((x) => this.ids.indexOf(id as any))
.map((x) => this.ids.indexOf(x))
.filter((x) => x >= 0)
.map((id) => this.healthDaemons[id]),
id,

View File

@@ -467,3 +467,25 @@ export type MountOptionsBackup = {
function wait(time: number) {
return new Promise((resolve) => setTimeout(resolve, time))
}
export class ExitError extends Error {
constructor(
readonly command: string,
readonly result: {
exitCode: number | null
exitSignal: T.Signals | null
stdout: string | Buffer
stderr: string | Buffer
},
) {
let message: string
if (result.exitCode) {
message = `${command} failed with exit code ${result.exitCode}: ${result.stderr}`
} else if (result.exitSignal) {
message = `${command} terminated with signal ${result.exitSignal}: ${result.stderr}`
} else {
message = `${command} succeeded: ${result.stdout}`
}
super(message)
}
}

View File

@@ -1,12 +1,12 @@
{
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.19",
"version": "0.3.6-beta.20",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.19",
"version": "0.3.6-beta.20",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",

View File

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

4
web/package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "startos-ui",
"version": "0.3.6-alpha.17",
"version": "0.3.6-alpha.18",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "startos-ui",
"version": "0.3.6-alpha.17",
"version": "0.3.6-alpha.18",
"license": "MIT",
"dependencies": {
"@angular/animations": "^14.1.0",

View File

@@ -1,6 +1,6 @@
{
"name": "startos-ui",
"version": "0.3.6-alpha.17",
"version": "0.3.6-alpha.18",
"author": "Start9 Labs, Inc",
"homepage": "https://start9.com/",
"license": "MIT",