Repository navigation
Closed
Labels
Description
What is the issue?
I've tried converting the NodeJS docker with postgres example into Elixir, but the .with_service_binding doesn't seem to work properly - an error is always thrown. If I remove the service binding the workflow completes ok (although the tests fail, because they need the database). My workflow is:
defmodule Mix.Tasks.ElixirWithDagger.Test do
use Mix.Task
@impl Mix.Task
def run(_args) do
Application.ensure_all_started(:dagger)
client = Dagger.connect!()
app =
client
|> Dagger.Client.host()
|> Dagger.Host.directory(".", exclude: ["deps", "_build"])
database =
client
|> Dagger.Client.container()
|> Dagger.Container.from("postgres:16")
|> Dagger.Container.with_env_variable("POSTGRES_PASSWORD", "test")
|> Dagger.Container.with_exec(~w"postgres")
|> Dagger.Container.with_exposed_port(5432)
|> Dagger.Container.as_service()
{:ok, _} =
client
|> Dagger.Client.container()
|> Dagger.Container.from("hexpm/elixir:1.15.7-erlang-26.1.2-debian-bullseye-20231009-slim")
|> Dagger.Container.with_exec(~w"apt-get update")
|> Dagger.Container.with_exec(~w"apt-get install -y build-essential git")
|> Dagger.Container.with_exec(~w"apt-get clean")
|> Dagger.Container.with_exec(~w"rm -f /var/lib/apt/lists/*_*")
|> Dagger.Container.with_mounted_directory("/app", app)
|> Dagger.Container.with_workdir("/app")
|> Dagger.Container.with_exec(~w"mix local.hex --force")
|> Dagger.Container.with_exec(~w"mix local.rebar --force")
|> Dagger.Container.with_exec(~w"mix deps.get")
|> Dagger.Container.with_service_binding("db", database)
|> Dagger.Container.with_env_variable("DB_HOST", "db")
|> Dagger.Container.with_env_variable("DB_USER", "postgres")
|> Dagger.Container.with_env_variable("DB_PASSWORD", "test")
|> Dagger.Container.with_env_variable("DB_NAME", "postgres")
|> Dagger.Container.with_exec(~w"mix test")
|> Dagger.Sync.sync()
Dagger.close(client)
IO.puts("Tests succeeded!")
end
endLog output
The output from the Dagger CLI is:
┃ ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:query_timeout, :infinity} of type Tuple. This protocol is implemented for the following type(s): Atom, B
┃ itString, Date, DateTime, Decimal, Float, Integer, List, NaiveDateTime, Phoenix.LiveComponent.CID, Postgrex.Copy, Postgrex.Query, Time, URI, Version, Version.Requirement
┃ (elixir 1.15.7) lib/string/chars.ex:3: String.Chars.impl_for!/1
┃ (elixir 1.15.7) lib/string/chars.ex:22: String.Chars.to_string/1
┃ (dagger 0.9.3) lib/dagger/query_builder.ex:82: Dagger.QueryBuilder.Selection.encode_value/1
┃ (elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
┃ (dagger 0.9.3) lib/dagger/query_builder.ex:65: Dagger.QueryBuilder.Selection.encode_value/1
┃ (dagger 0.9.3) lib/dagger/query_builder.ex:76: anonymous fn/1 in Dagger.QueryBuilder.Selection.encode_value/1
┃ (elixir 1.15.7) lib/enum.ex:1701: anonymous fn/3 in Enum.map/2
┃ (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
Steps to reproduce
Run the above workflow with dagger run mix elixir_with_dagger.test
SDK version
dagger v0.9.3 (registry.dagger.io/engine) darwin/arm64
OS version
macOS
Reacted by Thanabodee Charoenpiriyakij
Reacted by Allan Calix
Activity
allancalix commentedon Nov 10, 2023
So either the type definitions are wrong or the implementation is wrong I'm not sure which. What's happening is that when this gets encoded into some graphql query it's attempting to serialize the entire
Dagger.Servicetype. What should probably be happening iswith_service_bindingshould map the service to its ID and encode that into the query.You can do this yourself to work around this issue, not ideal but it worked for me:
bs1180 commentedon Nov 10, 2023
Oh wonderful, that worked - thank you for the quick reply. The workaround is fine but I'll leave the issue open?
wingyplus commentedon Nov 11, 2023
Thank you for the report. I can surely say that it is a bug.
Let me investigate and come up with a fix tomorrow. 🙇♂️
fix Elixir service binding not working (#6099)
fix Elixir service binding not working (dagger#6099)
fix Elixir service binding not working (dagger#6099)
fix Elixir service binding not working (dagger#6099)
fix Elixir service binding not working (dagger#6099)
fix Elixir service binding not working (dagger#6099)
fix Elixir service binding not working (dagger#6099)