Skip to content

Commit

Permalink
fix: Dependency (#2784)
Browse files Browse the repository at this point in the history
* fix: Dependency

* fix: set deps during container init
  • Loading branch information
Blu-J authored Nov 13, 2024
1 parent c088ab7 commit db6fc66
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
83 changes: 63 additions & 20 deletions container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ export class SystemForEmbassy implements System {
await effects.setMainStatus({ status: "stopped" })
await this.exportActions(effects)
await this.exportNetwork(effects)
await this.containerSetDependencies(effects)
}
async containerSetDependencies(effects: T.Effects) {
const oldDeps: Record<string, string[]> = Object.fromEntries(
await effects
.getDependencies()
.then((x) =>
x.flatMap((x) =>
x.kind === "running" ? [[x.id, x?.healthChecks || []]] : [],
),
)
.catch(() => []),
)
await this.setDependencies(effects, oldDeps)
}

async exit(): Promise<void> {
Expand Down Expand Up @@ -650,7 +664,7 @@ export class SystemForEmbassy implements System {
),
)
const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {}
await this.setConfigSetConfig(effects, dependsOn)
await this.setDependencies(effects, dependsOn)
return
} else if (setConfigValue.type === "script") {
const moduleCode = await this.moduleCode
Expand All @@ -673,31 +687,60 @@ export class SystemForEmbassy implements System {
}),
)
const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {}
await this.setConfigSetConfig(effects, dependsOn)
await this.setDependencies(effects, dependsOn)
return
}
}
private async setConfigSetConfig(
private async setDependencies(
effects: Effects,
dependsOn: { [x: string]: readonly string[] },
rawDepends: { [x: string]: readonly string[] },
) {
const dependsOn: Record<string, readonly string[] | null> = {
...Object.fromEntries(
Object.entries(this.manifest.dependencies || {})?.map((x) => [
x[0],
null,
]) || [],
),
...rawDepends,
}
await effects.setDependencies({
dependencies: Object.entries(dependsOn).flatMap(([key, value]) => {
const dependency = this.manifest.dependencies?.[key]
if (!dependency) return []
const versionRange = dependency.version
const registryUrl = DEFAULT_REGISTRY
const kind = "running"
return [
{
id: key,
versionRange,
registryUrl,
kind,
healthChecks: [...value],
},
]
}),
dependencies: Object.entries(dependsOn).flatMap(
([key, value]): T.Dependencies => {
const dependency = this.manifest.dependencies?.[key]
if (!dependency) return []
if (value == null) {
const versionRange = dependency.version
if (dependency.requirement.type === "required") {
return [
{
id: key,
versionRange,
kind: "running",
healthChecks: [],
},
]
}
return [
{
kind: "exists",
id: key,
versionRange,
},
]
}
const versionRange = dependency.version
const kind = "running"
return [
{
id: key,
versionRange,
kind,
healthChecks: [...value],
},
]
},
),
})
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions web/projects/ui/src/app/services/api/api.fixures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,11 @@ export module Mock {
name: 'Datetime',
required: false,
}),
file: ISB.Value.file({
name: 'File',
required: false,
extensions: ['png', 'pdf'],
}),
// file: ISB.Value.file({
// name: 'File',
// required: false,
// extensions: ['png', 'pdf'],
// }),
users: ISB.Value.multiselect({
name: 'Users',
default: [],
Expand Down

0 comments on commit db6fc66

Please sign in to comment.