#How to export Directory from a service?

1 messages · Page 1 of 1 (latest)

void frost
#

I have a database (elasticsearch) container which gets populated with data from several different import containers. Once all the importers are done, I'd like to export the elastic search directory from the elasticsearch container.

My thought was to start elasticsearch AsService() then pass that to my various importer containers. This allows the importers to succeed.

But then... how do I get the directory back out from my service container?

func (p *Pelias) PeliasImportSchema(ctx context.Context,
    // +defaultPath="./services/pelias"
    serviceDir *dagger.Directory) *dagger.Directory{

    elasticsearch := dag.Container().
            From("pelias/elasticsearch:8.12.2-beta").
            WithExposedPort(9200)

    service := elasticsearch.AsService()

    _, err := p.PeliasContainerFrom(ctx, "pelias/schema:master").
        WithServiceBinding("pelias-elasticsearch", service).
        WithFile("/tools/wait.sh", serviceDir.File("wait.sh")).
        WithExec([]string{"bash", "-c", "/tools/wait.sh && ./bin/create_index "}).
        Sync(ctx)

    if err != nil {
        panic(fmt.Errorf("failed to import schema: %w", err))
    }   

    return elasticsearch.Directory("/usr/share/elasticsearch/data")
}

The directory that gets exported is empty - but I'm expecting it to have been populated.

This is somewhat similar to https://discord.com/channels/707636530424053791/1260558982246825994, except I don't think I want to use a volume - I don't want to cache state across invocations.

Relatedly - is there a way to "connect" to a dagger Service? e.g. something like Terminal?