#I am getting a bit of a cryptic error
1 messages · Page 1 of 1 (latest)
Still an issue?
saw a couple of quick bugs
but I got the same error.
trying with v11.0.4
same error
@desert frost have you looked into this one yet?
I'm checking
I think it's a typescript code issue, you should try to check to return to
// publish to registry
const imageDigest = await dag
.container()
.publish(imageRepo, {platformVariants:platformVariants}) // You're not supposed to convert to a type, this might also lead to an issue
return imageDigest
Same in other part of the stack
I need to clone the repository to investigate more, but I have many things to do first so I'm not sure I can do it before tomorrow
@desert frost
BTW up here it seems that casting is required, jeremy ran into somethign similar the other day
.container({platform: platform} as ClientContainerOpts)
I tried the suggestions you made but its the same error.
{ platform: Platform as Platform }
Inside the }
Not outside
BTW the reason I am doing this is becaue its how we do it in this otehr example -- so that may b e wrong too https://github.com/dagger/dagger/blob/656832a64e12bf2ed724962d6435ff3574c8f687/docs/current_docs/integrations/snippets/java/typescript/index.ts#L34
In either case,
.container({platform: platform as Platform} )
results in the same error
Put it inside ()
I assume you mean
container({platform: (platform as Platform)})
same issue though
@zenith tinsel did you get your platform thing to work in TS the other day, this was a similar issue right? What syntax did you use?
lemme check
@func()
async publish(
source: Directory,
version: string,
registryAddress: string,
registryUsername: string,
registryPassword: Secret,
imageName: string,
): Promise<string> {
return await dag
.container({platform:"linux/amd64"} as ClientContainerOpts)
.from("eclipse-temurin:17-alpine")
.withLabel("org.opencontainers.image.title", "Java with Dagger")
.withLabel("org.opencontainers.image.version", version)
.withFile("/app/spring-petclinic-3.2.0-SNAPSHOT.jar", this.build(source))
.withEntrypoint([
"java",
"-jar",
"/app/spring-petclinic-3.2.0-SNAPSHOT.jar",
])
.withRegistryAuth(registryAddress, registryUsername, registryPassword)
.publish(`${registryAddress}/${registryUsername}/${imageName}`)
}
.container({platform:platform} as ClientContainerOpts) then?
Hmm that's strange, usually I don't do that, I do as platform and it works
I need to clone the repo and I'll add some stuff
Thanks @desert frost here's the branch: https://github.com/levlaz/dagger/tree/docs-268-multi-arch
Ty
@lucid scarab I found the error, you do a New Directory() on line 25, but you're supposed to do dag.Directory() to actually get the dagger definition.
New Directory doesn't call the Dagger API to create a directory
So it's a typo basically 😢
import { dag, Container, Directory, object, func, Platform } from "@dagger.io/dagger"
@object()
class Ts {
@func()
async build(src: Directory): Promise<string> {
// platforms to build for and push in a multi-platform image
const platforms: Platform[] = [
"linux/amd64" as Platform, // a.k.a. x86_64
"linux/arm64" as Platform, // a.k.a. aarch64
"linux/s390x" as Platform, // a.k.a. IBM S/390
]
// container registry for multi-platform image
const imageRepo = "ttl.sh/myapp:latest"
let platformVariants: Array<Container> = []
for (const platform of platforms) {
const ctr = dag
.container({platform: platform})
.from("golang:1.22-alpine")
// mount source
.withDirectory("/src", src)
// mount empty dir where built binary will live
.withDirectory("/output", dag.directory())
// ensure binary will be statically linked and thus executable
// in the final image
.withEnvVariable("CGO_ENABLED", "0")
.withWorkdir("/src")
.withExec(["go", "build", "-o", "/output/hello"])
// select output directory
const outputDir = ctr.directory("/output")
// wrap output directory in a new empty container marked
// with the same platform
const binaryCtr = await dag
.container({platform: platform})
.withRootfs(outputDir)
.sync()
platformVariants.push(binaryCtr)
}
// publish to registry
const imageDigest = await dag
.container()
.publish(imageRepo, {platformVariants: platformVariants})
return imageDigest
}
}
I just tried it and it worked
I also removed the ugly as notation, it should only be used for scalar
Thank you so much @desert frost - I appreciate you as always ❤️
Do you think there is anything we can do to make that error more obvious in the future, I could see other people running into this issue and the output is very cryptic IMO.
It's hard because it's in the nature of the language, I could technically if I transformed Directory and native dagger type into interface so they cannot be constructed (no call to new) but this would require a big refactor of the codebase and the way it TS internal works
So a way to make that error obvious is buy using static analysis but again, pretty hard and I would rather turn every types into interfaces
And this would create other issues maybe because fields would be public
Thanks for helping me understand that Tom