func (m *Treasury) TestEnv(
ctx context.Context,
) (*dagger.Container, error) {
devContainer := dag.Container().From("alpine:latest")
var wg sync.WaitGroup
for i := 0; i < 2; i++ {
i := i
wg.Add(1)
go func() {
cache := dag.CacheVolume(fmt.Sprintf("cache-%d", i))
_, err := devContainer.
WithMountedCache("/shared", cache).
WithExec([]string{"sh", "-c", fmt.Sprintf("echo 'SERVER %d' > /shared/index.html", i)}).
Stdout(ctx)
if err != nil {
panic(err)
}
service := dag.Container().
From("python").
WithMountedCache("/shared", cache).
WithWorkdir("/srv").
WithExec([]string{"sh", "-c", "cp /shared/index.html /srv/"}).
WithExec([]string{"python", "-m", "http.server", "8080"}).
WithExposedPort(8080).
AsService()
serviceName := fmt.Sprintf("www-%d", i)
clientContainer := devContainer.
WithEnvVariable("HOST", serviceName).
WithServiceBinding(serviceName, service)
output, err := clientContainer.
WithExec([]string{"wget", "-O-", fmt.Sprintf("http://%s:8080", serviceName)}).
Stdout(ctx)
if err != nil {
panic(err)
}
fmt.Println(output)
wg.Done()
}()
}
wg.Wait()
return devContainer, nil
}
https://dagger.cloud/cordialsys/traces/21bf3cd32bc667bdacf6446f10fb4013
I expect the output to have different lines, like:
SERVER 0
SERVER 1
But instead it's like:
SERVER 0
SERVER 0