dagger / dagger

An engine to run your pipelines in containers
https://dagger.io
Apache License 2.0
11.36k stars 606 forks source link

🐞 Calling Dagger.Client.host/1 fails #8052

Closed gmile closed 2 months ago

gmile commented 2 months ago

What is the issue?

Dagger.Client.host/1 function is advertised in docs, however calling it fails with an following error, and so is fails Dagger.Host.directory/2 (so I must be doing something wrong here):

# removed for brevity
Compiling 3 files (.ex)
    warning: Dagger.Host.directory/2 is undefined (module Dagger.Host is not available or is yet to be defined)
    │
 14 │       |> Dagger.Host.directory("/tmp")
    │                      ~
    │
    └─ lib/dagger_module_sample.ex:14:22: DaggerModuleSample.problem/2

    warning: Dagger.Client.host/1 is undefined or private
    │
 13 │       |> Dagger.Client.host()
    │                        ~
    │
    └─ lib/dagger_module_sample.ex:13:24: DaggerModuleSample.problem/2

Generated dagger_module_sample app
** (UndefinedFunctionError) function Dagger.Client.host/1 is undefined or private
    (dagger 0.0.0) Dagger.Client.host(%Dagger.Client{selection: %Dagger.Core.QueryBuilder.Selection{name: nil, args: nil, prev: nil, alias: ""}, client: %Dagger.Core.Client{url: "http://127.0.0.1:36899/query", conn: %Dagger.Core.EngineConn{port: "36899", token: "2gxmnfgfe5whff2fzshxei0nj", session_pid: nil}, connect_opts: [query_timeout: :infinity, connect_timeout: 10000, log_output: :stderr]}})
    (dagger_module_sample 0.1.0) lib/dagger_module_sample.ex:13: DaggerModuleSample.problem/2
    (dagger 0.0.0) lib/dagger/mod.ex:150: Dagger.Mod.invoke/5
    (dagger 0.0.0) lib/dagger/mod.ex:117: Dagger.Mod.invoke/1
    (mix 1.16.3) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (elixir 1.16.3) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
    (mix 1.16.3) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.16.3) lib/mix/cli.ex:96: Mix.CLI.run_task/2
Stderr:
** (exit) 1
    (mix 1.16.3) lib/mix/tasks/cmd.ex:74: Mix.Tasks.Cmd.run/1
    (mix 1.16.3) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.16.3) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /usr/local/bin/mix:2: (file)

Dagger version

v0.12.3

Steps to reproduce

Create and cd into a sample directory:

mkdir dagger-module-sample && cd dagger-module-sample

Initialize new Elixir module:

dagger init --sdk=github.com/dagger/dagger/sdk/elixir/runtime .

Find the main module file and replace it with this contents:

defmodule DaggerModuleSample do
  use Dagger.Mod, name: "DaggerModuleSample"

  defstruct [:dag]

  @function [
    args: [],
    return: Dagger.Container
  ]
  def problem(self, args) do
    host_tmp =
      self.dag
      |> Dagger.Client.host()
      |> Dagger.Host.directory("/tmp")

    self.dag
    |> Dagger.Client.container()
    |> Dagger.Container.with_directory("/tmp", host_tmp)
  end
end

Log output

No response

gmile commented 2 months ago

cc @wingyplus 🙇

helderco commented 2 months ago

Same explanation from here:

gmile commented 2 months ago

Thank you @helderco! I'll close this one.