#Is it possible to pass a *Container as an arg to dagger call?
1 messages ยท Page 1 of 1 (latest)
hm, so you want the cli to be the one that chains these together?
unfortunately, i don't think there's a way to do that today
you can specify a container image arg in a registry with just something like image:tag
and we could definitely add an arg to do an import
but there's no chaining functionality in the cli where it's all kept internal
No worries, thank you @serene depot. I'll do the chaining in the Go code instead.
that said, i'm curious about the use case - personally, i've wondered about whether we could do chaining like this in the cli
Basically I'd like to have another dagger func after this one: https://github.com/felipecruz91/go-dagger-pipeline/blob/main/.github/workflows/ci.yml#L41 which accepts a *Container and runs the dagger call <fn> <container> publish --address <registry/image:tag>
It doesn't seem straightfoward to publish a multi-arch image from the CLI. Also, I just came across this issue which is exactly what I'm facing ๐ https://github.com/dagger/dagger/issues/6675
Using platformVariants is extremely unwieldy to use: dagger/docs/docs-graphql/schema.graphqls Lines 196 to 201 in fca9e78 """ Identifiers for other platform specific containers. Used...
I have a working example of publishing multi-arch docker images from a dagger module, https://github.com/purpleclay/daggerverse/blob/main/docker/main.go
Thank you @wheat osprey. I did something similar: https://github.com/felipecruz91/daggerverse/blob/main/go/docker.go#L69-L71
I've got a dagger func that builds a container image and returns the core *Container type.
If the original function returns a *Container, you can call publish from there. For example dagger call -m "$DAGGER_GO_MODULE" docker-build --bin bin --platform "linux/amd64" publish --address foo. It might need to be changed around to push your multiarch image though
Thank you @static herald. That's an elegant solution when building single-arch images!
Ideally we could have an equally elegant solution for multi-arch... I'll think about it more and see if I come up with anything
Just searching around on the same kind of issue, where I create a base img for my GO build, and I thought I could pass this base img around and execute different cmd(s) on it. But its looks like this isn't really how its designed to work? When reviewing this dagger module walkthrough..
https://docs.dagger.io/guides/457482/create-app-ci-module#conclusion
I see the base image being built here but I don't connect how its actually being used/consumed? Is it actually referenced ever again? Does the context keep the last built container img?
๐ it's being referenced in other function calls. for example:
@object_type
class MyModule:
@function
async def test(self, source: dagger.Directory) -> str:
"""Run unit tests"""
return await (
dag.node(ctr=self.build_base_image(source))
.commands()
.run(["test:unit", "run"])
.stdout()
)
def build_base_image(self, source: dagger.Directory) -> dagger.Container:
"""Build base image"""
return (
dag.node(version="21").with_npm().with_source(source).install().container()
)
you can see that build_base_image is being referenced in test in the dag.node function call
in this case since functions are part of the same Dagger module, you can just use self.base() from other functions to retrieve your base image
Yeah, I've found those examples. I guess what I'm confused about is it a running active container after it executes? When you return it to next function should it be able to then que in another .WithExec for example or do I need to init it again to spin it back up?
not sure I got the question. could you rephrase it please ๐ ?
Sure, I guess what I'm having a bit of trouble understanding is, when you are passing a dagger.container object to another dagger function, is that container in a running state when it hits said function? LMK if that makes more sense?
ok, I see now. No, the container is not in a running state what you're passing it to a function
You're basically building a DAG when you do dag.container().from().with_exec().with_exec()..... etc
and once you call a method on that object that forces that DAG resolution (this methods in python are the ones that return a Coroutine), that will trigger the DAG resolution
so when you do await container.sync() or any other function that returns a Coroutine like mentioned above, that's when everything gets resolved/executing
Ok so you have to persist stuff through the caches, mnt folders, etc.. I thought you could just init a container, and run it down a pipeline if you preferred but I see the design intent now. Thanks!
not sure what you mean about persisting through caches
Just anything you are working on, Artifacts etc
between functions you mean? no, that's not required
let me give you a quick example
you use python, right @lean saddle ?
cc @granite lake we should bring back the lazy evaluation docs from 0.9 when possible ๐
@fresh field Learning Go along with Dagger (hence why I'm probably such a bother) I use Python on the daily so I should be able to follow along.
here's a basic example:
@object_type
class Test:
@function
async def run(self, message: str) -> str:
return await self.base().with_exec(["figlet", message]).stdout()
@function
def base(self) -> dagger.Container:
return dag.container().from_("alpine").with_exec(["apk", "add", "figlet"])
in this case for example, the base function builds a Container object that it'll be resolved/executed when run is called as it's calling the sync function that needs to be awaited
In the case of Go, since there's no Promise or Coroutine equivalent, those functions receive a context.Context
Ah, I see
so when self.base is called nothing gets executed at that time in reality. a Container object gets built but in order for that to execute, you need to call a function that actually uses something from that container. Or else, you can optionally use the sync() call to force it to resolve if you don't need anything and you just want to run it
OK, yeah this tracks roughly with what I'm trying to do at least in my head, let me switch over to it here in a few and review the GO code. In the GO's context obj, that's where my base container should waiting for me to reference after its created? I was getting confused if it was actually in there or not. There are a few Container methods at various levels and its hard to know exactly which version I'm looking for. I do appreciate the time @fresh field its very helpful! Understanding the raw flow of how it wants to work seems to be half the battle for me so far. 
that's great! happy to help. We're constantly improving our docs so the next user doesn't trip into these cases cc @granite lake . Thx for brining this feedback to us and don't hesitate to ask if you have more questions ๐