#Hi!๐Ÿ‘‹๐Ÿป I'm trying to build a container

1 messages ยท Page 1 of 1 (latest)

vestal pilot
#

You should be able to tunnel to your host. A function can receive a service as a parameter that can be a URL to a local port. An example for accesing an API running in localhost:

func (m *Tunnel) Echo(ctx context.Context, svc *dagger.Service) (string, error) {
    return dag.Container().
        From("alpine:latest").
        WithExec([]string{"apk", "add", "curl"}).
        WithServiceBinding("testing", svc).
        WithExec([]string{"curl", "-v", "http://testing:8080/hello"}).
        Stdout(ctx)
}

Running an API on localhost:8080 and then a dagger call:

dagger call echo --svc "tcp://localhost:8080"
#

Haven't tested with a registry, but I imagine it should work. I'm not sure if there are other alternatives for when you are building containers using the graphql API more directly. A practice I often do is have a "Build" function that returns a container and then do dagger call build with-registry-auth <params> publish <address>. In this approach I'm not sure if its possible to make it work

sterile tendon
#

    #[DaggerFunction, Doc('Publish PHP Container')]
    public function publish(
        string $registry,
        string $image,
        string $username,
        Secret $password,
    ): string {
        return $this->container
            ->withRegistryAuth($registry, $username, $password)
            ->publish("{$image}/php:0.1");
    }
#

called with:

#

dagger call php publish --registry=$CI_REGISTRY --username=$CI_REGISTRY_USER --password=CI_REGISTRY_PASSWORD --image=$CI_REGISTRY_IMAGE

icy oracle
#

Thanks @vestal pilot , thanks @sterile tendon
I still have to sort this out as I've been able to use the Service to connect to an already running docker container in Go, but not in Python (the main language of the project, but it could be just my mistake in setting it up)
In any case I'm also exploring different strategies to make it work, like creating a custom runner connected to the host network, instead of the bridge