#I am getting a bit of a cryptic error

1 messages · Page 1 of 1 (latest)

zenith tinsel
#

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?

desert frost
#

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

lucid scarab
#

@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.

desert frost
#

Just cast the platform, not the clientContainerOpts

#

This is because it's a scalar

lucid scarab
#

Yeah I did that

#

Does not seem to make a difference - same error

desert frost
#

{ platform: Platform as Platform }

lucid scarab
desert frost
#

Inside the }

lucid scarab
#

oops hold on I think it was a syhntax error on my end

#

Yeah

desert frost
#

Not outside

lucid scarab
#

In either case,

.container({platform: platform as Platform} )

results in the same error

desert frost
#

Put it inside ()

lucid scarab
#

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?

zenith tinsel
#
@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?

desert frost
#

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

lucid scarab
desert frost
#

Ty

desert frost
#

@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

lucid scarab
#

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.

desert frost
#

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

lucid scarab
#

Thanks for helping me understand that Tom

zenith tinsel
#

Ah. Good spotting that.
I would not have thought to use new Directory, but wonder if other folks might as well...
I'm surprised we don't have withNewDirectory() on container...

#

I guess we're trying to not change the tree structure of the rootfs but can add files to it?