#Dagger system shell : how to reuse / inherit container ?

1 messages Β· Page 1 of 1 (latest)

fierce ridge
#

Hi
I try the new feature from 0.17: https://docs.dagger.io/features/shell/
here is my first file:

container |
  from alpine |
  with-exec apk add curl |
  with-exec -- sh -c 'curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=/bin sh'

how can I reuse this base for each other files ?

Iterate faster with familiar Bash-like syntax and autocomplete

#

or how can I setup variables ?

strange viper
#

regular bash syntax, myctr=$(container | ...)

#

also you can use container | with-file /tmp/install.sh $(http https://dl.dagger.io/install.sh) | with-exec /tmp/install.sh

#

(to avoid installing curl, and get better caching on the download)

fierce ridge
#

is it possible to have multiple files ? or each variable (and logic) should be inside the same file ?

#

for example I do this:

docker=$(container |
  from alpine |
  with-exec apk add docker |
  with-unix-socket /var/run/docker.sock /var/run/docker.sock)

dagger=$($docker |
  with-exec apk add curl |
  with-exec -- sh -c 'curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=/bin sh'
)

# $dagger |
#   with-workdir /benchmark-go |
#   with-exec -- dagger init --sdk=go . |
#   with-exec time dagger functions |
#   stderr

$dagger |
  with-workdir /benchmark-php |
  with-exec -- dagger init --sdk=php . |
  with-exec time dagger functions |
  stderr

I would like to be able to test this for each versions of dagger, each sdk, ...

fierce ridge
strange viper
strange viper
#

for simple cases you can also take advantage of the "fan-out" feature of dagger pipelines: if you call a function that returns a list of objects, the next function in the chain will be called against all elements of the array in parallel

fierce ridge
#

I see πŸ™‚
if you have a link to the documentation, I take it

strange viper
fierce ridge
#

the fan-out feature

strange viper
#

I'm not sure the fan-out feature is documented 😬 kind of a niche "advanced" feature. Let me check

#

The main reason is that the core API doesn't return a lot of lists of objects. But when you develop your own module, it becomes much more powerful, because you can write functions that return lists of objects, and so can other modules. That's when fan-out can become a nice cheat code

fierce ridge
#

Thank you Solomon πŸ™‚

strange viper
#

np, keep me posted, I'm interested in seeing what you do with Dagger πŸ™‚

fierce ridge
#

I rewrite it in Go: https://github.com/mykiwi/dagger-sdk-benchmark
but I'm still new with dagger and I don't know how to chain logic, for example in the README I did:

$ BASE_ID=$(dagger call container-base --dockerSocket /var/run/docker.sock)

$ CODE_PHP_ID=$(dagger call container-code --container $BASE_ID --language php)

but it does not works πŸ€”

GitHub

Contribute to mykiwi/dagger-sdk-benchmark development by creating an account on GitHub.

fierce ridge
#

oh I think I get it... I must do this chaining inside an other go function

strange viper
#

it looks like maybe containerCode() should call containerBase()?

#

@fierce ridge to chain from the command line you need to use the dagger shell, not dagger call.

fierce ridge
#

πŸ‘Œ thx