#It has to be passed as an argument. For
1 messages · Page 1 of 1 (latest)
Do you by chance have a working example?
Here I am trying to forward a postgres service from the host:
func (m *Pg) ContainerEcho(
ctx context.Context,
svc *Service,
) *Container {
return dag.Container().From("postgres:12").
WithServiceBinding("sdm", svc).
WithExec([]string{"/bin/sh", "-c", "psql postgres://postgres@sdm:15543/postgres -c \\dt"})
}```
and I call it like this:
`dagger --debug call container-echo --svc tcp://localhost:15443`
The same command works locally e.g. `psql postgres://postgres@localhost:15543/postgres -c \\dt`
But I get this when running in dagger:
┃ port is up at 10.87.0.124:15443
● tunnel /upstream.15443.sock:15443/tcp 1.1s
┃ 2024/03/04 16:57:03 listening on 15443/tcp
┃ 2024/03/04 16:57:03 10.87.0.17:58238 > handling
┃ 2024/03/04 16:57:03 10.87.0.17:58238 > dialed /tmp/.buildkit-ssh-sock1400989177/ssh_auth_sock
┃ 2024/03/04 16:57:03 10.87.0.17:58238 > copy upstream->downstream error readfrom tcp 10.87.0.124:15443->10.87.0.17:58238: use of closed network
┃ connection
┃ 2024/03/04 16:57:03 10.87.0.17:58238 > done ✘ exec docker-entrypoint.sh psql -U postgres -p 15543 -d postgres 0.4s
┃ psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.15543" failed: No such file or directory ┃ Is the server running locally and accepting connections on that socket? ```
I noticed the ports are different in your connection string, is that intentional?
what do you mean different? Did I fat finger something?
15443 vs 15543
oo
Ok, fixed that - same error though: dagger --debug call container-echo --svc tcp://localhost:15543
┃ polling for port drj5416iiuv6a.f91bl3qd0kebk.dagger.local:15543
┃ port not ready: dial tcp 10.87.0.128:15543: connect: connection refused; elapsed: 676.959µs
┃ port is up at 10.87.0.128:15543
● tunnel /upstream.15543.sock:15543/tcp 0.3s
┃ 2024/03/04 17:02:22 listening on 15543/tcp
┃ 2024/03/04 17:02:22 10.87.0.17:46136 > handling
┃ 2024/03/04 17:02:22 10.87.0.17:46136 > dialed /tmp/.buildkit-ssh-sock3186588592/ssh_auth_sock
┃ 2024/03/04 17:02:22 10.87.0.17:46136 > copy upstream->downstream error readfrom tcp 10.87.0.128:15543->10.87.0.17:46136: use of closed network
┃ connection
┃ 2024/03/04 17:02:22 10.87.0.17:46136 > done
✘ exec docker-entrypoint.sh psql -U postgres -p 15543 -d postgres 0.1s
┃ psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.15543" failed: No such file or directory
┃ Is the server running locally and accepting connections on that socket? ```
this is the working command that works locally: psql postgres://postgres@localhost:15543/postgres -c \\dt
Here's my working example (requires running a bunch of other stuff) https://github.com/kpenfound/example-voting-app/blob/daggerize/ci/seed/main.go#L6
dagger -m seed call run --dir seed-data/ --vote tcp://localhost:5000
I'm confused about this part from the output exec docker-entrypoint.sh psql -U postgres -p 15543 -d postgres since it doesn't have sdm
Good call out. I got it working after you rlast comment. I think there was a caching issue of sorts because that line of code was commented out and was still being executed. I changed it to use "sdm" as the host and uncommented it and it worked
one final question. Is there a way to bind it to teh function's container instead of dropping into my own container yet? Might be neat to directly expose it to the function instead of having to drop into a container
Could be something like dag.Module().WithServiceBinding(svc) since I see there is already a reference to the module with dag.Module()
Not yet afaik
I think it's nicer to drop to a container in this case anyway, since it requires the postgres binary to be able to actually execute this