Having this build file (some stuff redacted)
containerBackend(): Container {
return dag
.container()
.from("sbtscala/scala-sbt")
.withDirectory("/", src)
.withWorkdir("/");
}
async buildBackend_(backendJar: File, arch: string): Promise<Container> {
const backendNative = await dag
.container({ platform: arch as any })
.from("native-image-community:23")
.withWorkdir("/")
.withFile("/a.jar", backendJar)
.withExec(["native-image",".."])
.file("/app");
return dag
.container({ platform: arch as any })
.from("scratch")
.withWorkdir("/")
.withFile("/app", backendNative)
.withExec(["chmod", "+x", "/app"])
.withEntrypoint(["/app"]);
}
@func()
async buildBackend(): Promise<string> {
const platforms = ["linux/amd64", "linux/arm64"];
const backendJar = await this.containerBackend()
.withExec(["sbt", "assembly"])
.file("backend.jar");
const containers = await Promise.all(platforms.map(x => this.buildBackend_(backendJar, x)));
return dag.container().publish("container", { platformVariants: containers });
}
To make this build optimal in terms of building I would to construct a DAG which builds
containerBackendonce- pass on the jar to two parallel jobs which use the graal native image and return the containers
- use the returned containers to publish it
This is a typical fan out -> fan in thing. However:
- Since
buildBackend_returns aPromise<Container>it builds them in sequence? - I guess it's hard to constrain/determine that some parts always yield the same result, if that would be the case it would be easier to construct a DAG and optimize and create an optimal build plan.. is there any article how this optimally or recommendations ?