I based my modifications on the code you've provided. It also fails with the same error. Here is the code I used this time:
type M struct{}
func (m *M) Database(ctx context.Context) (*dagger.Container, error) {
pgCache := dag.CacheVolume("postgres-data")
postgres := dag.Container().From("postgres")
migrations := dag.
Directory().
WithNewFile("/migrations/00_test.sql", "CREATE TABLE test IF NOT EXISTS (test text)").
Directory("/migrations")
_, err := m.Sqlx().WithServiceBinding("postgres",
postgres.WithEnvVariable("POSTGRES_PASSWORD", "postgres").
WithMountedCache("/var/lib/postgresql/data", pgCache).
WithExposedPort(5432).AsService()).
WithEnvVariable("DATABASE_URL", "postgres://postgres:postgres@postgres").
WithDirectory("migrations", migrations).
WithExec([]string{"cargo", "sqlx", "migrate", "run"}).
Sync(ctx)
if err != nil {
return nil, err
}
return postgres.WithMountedCache("/data", pgCache).
WithExec([]string{"cp", "-r", "/data", "/var/lib/postgresql/"}, ContainerWithExecOpts{SkipEntrypoint: true}).
WithExec(nil), nil
}
func (m *M) Sqlx() *dagger.Container {
return dag.Container().From("rust").WithExec([]string{"cargo", "install", "sqlx-cli"})
}