status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
⌀ | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
timestamp[us, tz=UTC] | language
stringclasses 5
values | commit_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | Container struct {
From struct {
ImageRef string
}
}
}{}
err := testutil.Query(
`{
container {
from(address:"hello-world") {
exec(args:["/hello"]) {
imageRef
}
}
}
}`, &res, nil)
require.Error(t, err)
require.Contains(t, err.Error(), "Image reference can only be retrieved immediately after the 'Container.From' call. Error in fetching imageRef as the container image is changed")
})
t.Run("should throw error after the container image modification with exec", func(t *testing.T) {
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | Container struct {
From struct {
ImageRef string
}
}
}{}
err := testutil.Query(
`{
container {
from(address:"hello-world") {
withExec(args:["/hello"]) {
imageRef
}
}
}
}`, &res, nil)
require.Error(t, err)
require.Contains(t, err.Error(), "Image reference can only be retrieved immediately after the 'Container.From' call. Error in fetching imageRef as the container image is changed")
})
t.Run("should throw error after the container image modification with directory", func(t *testing.T) {
c, ctx := connect(t)
defer c.Close()
dir := c.Directory(). |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | WithNewFile("some-file", "some-content").
WithNewFile("some-dir/sub-file", "sub-content").
Directory("some-dir")
ctr := c.Container().
From("alpine:3.16.2").
WithWorkdir("/workdir").
WithDirectory("with-dir", dir)
_, err := ctr.ImageRef(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "Image reference can only be retrieved immediately after the 'Container.From' call. Error in fetching imageRef as the container image is changed")
})
}
func TestContainerBuildNilContextError(t *testing.T) {
t.Parallel()
ctx := context.Background()
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
require.NoError(t, err)
defer c.Close()
err = testutil.Query(
`{
container {
build(context: "") {
id
}
}
}`, &map[any]any{}, nil)
require.ErrorContains(t, err, "invalid nil input definition to definition op")
}
func TestContainerInsecureRootCapabilites(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | c, ctx := connect(t)
defer c.Close()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
out, err := c.Container().From("alpine:3.16.2").
WithExec([]string{"cat", "/proc/self/status"}).
Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, "CapInh:\t0000000000000000")
require.Contains(t, out, "CapPrm:\t00000000a80425fb")
require.Contains(t, out, "CapEff:\t00000000a80425fb")
require.Contains(t, out, "CapBnd:\t00000000a80425fb")
require.Contains(t, out, "CapAmb:\t0000000000000000")
out, err = c.Container().From("alpine:3.16.2").
WithExec([]string{"cat", "/proc/self/status"}, dagger.ContainerWithExecOpts{
InsecureRootCapabilities: true,
}).
Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, "CapInh:\t0000003fffffffff")
require.Contains(t, out, "CapPrm:\t0000003fffffffff")
require.Contains(t, out, "CapEff:\t0000003fffffffff")
require.Contains(t, out, "CapBnd:\t0000003fffffffff")
require.Contains(t, out, "CapAmb:\t0000003fffffffff")
}
func TestContainerInsecureRootCapabilitesWithService(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | c, ctx := connect(t)
defer c.Close()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
dockerd := c.Container().From("docker:23.0.1-dind").
WithMountedCache("/var/lib/docker", c.CacheVolume("docker-lib"), dagger.ContainerWithMountedCacheOpts{
Sharing: dagger.Private,
}).
WithMountedCache("/tmp", c.CacheVolume("share-tmp")).
WithExposedPort(2375).
WithExec([]string{"dockerd",
"--host=tcp://0.0.0.0:2375",
"--tls=false",
}, dagger.ContainerWithExecOpts{
InsecureRootCapabilities: true,
})
dockerHost, err := dockerd.Endpoint(ctx, dagger.ContainerEndpointOpts{
Scheme: "tcp",
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | core/integration/container_test.go | require.NoError(t, err)
randID := identity.NewID()
out, err := c.Container().From("docker:23.0.1-cli").
WithMountedCache("/tmp", c.CacheVolume("share-tmp")).
WithServiceBinding("docker", dockerd).
WithEnvVariable("DOCKER_HOST", dockerHost).
WithExec([]string{"sh", "-e", "-c", strings.Join([]string{
fmt.Sprintf("echo %s-from-outside > /tmp/from-outside", randID),
"docker run --rm -v /tmp:/tmp alpine cat /tmp/from-outside",
fmt.Sprintf("docker run --rm -v /tmp:/tmp alpine sh -c 'echo %s-from-inside > /tmp/from-inside'", randID),
"cat /tmp/from-inside",
}, "\n")}).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s-from-outside\n%s-from-inside\n", randID, randID), out)
}
func TestContainerNoExecError(t *testing.T) {
c, ctx := connect(t)
defer c.Close()
_, err := c.Container().From("alpine:3.16.2").ExitCode(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), core.ErrContainerNoExec.Error())
_, err = c.Container().From("alpine:3.16.2").Stdout(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), core.ErrContainerNoExec.Error())
_, err = c.Container().From("alpine:3.16.2").Stderr(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), core.ErrContainerNoExec.Error())
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | package mage
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"text/template"
"time"
"dagger.io/dagger"
"github.com/dagger/dagger/internal/mage/sdk"
"github.com/dagger/dagger/internal/mage/util"
"github.com/magefile/mage/mg"
"golang.org/x/mod/semver"
)
const (
engineBinName = "dagger-engine"
shimBinName = "dagger-shim"
alpineVersion = "3.17"
runcVersion = "v1.1.4"
buildkitRepo = "github.com/moby/buildkit"
buildkitRef = "34a576c411eaab55c40f3e06478a628ef73bdfc7"
qemuBinImage = "tonistiigi/binfmt:buildkit-v7.1.0-30@sha256:45dd57b4ba2f24e2354f71f1e4e51f073cb7a28fd848ce6f5f2a7701142a6bf0" |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | engineTomlPath = "/etc/dagger/engine.toml"
engineDefaultStateDir = "/var/lib/dagger"
engineEntrypointPath = "/usr/local/bin/dagger-entrypoint.sh"
cacheConfigEnvName = "_EXPERIMENTAL_DAGGER_CACHE_CONFIG"
servicesDNSEnvName = "_EXPERIMENTAL_DAGGER_SERVICES_DNS"
)
var engineEntrypoint string
const engineEntrypointTmpl = `#!/bin/sh
set -e
# cgroup v2: enable nesting
# see https://github.com/moby/moby/blob/38805f20f9bcc5e87869d6c79d432b166e1c88b4/hack/dind#L28
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
# move the processes from the root group to the /init group,
# otherwise writing subtree_control fails with EBUSY.
# An error during moving non-existent process (i.e., "cat") is ignored.
mkdir -p /sys/fs/cgroup/init
xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
# enable controllers
sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \
> /sys/fs/cgroup/cgroup.subtree_control
fi
exec {{.EngineBin}} --config {{.EngineConfig}} "$@"
`
const engineConfig = `
debug = true
insecure-entitlements = ["security.insecure"]
`
func init() {
type entrypointTmplParams struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | Bridge string
EngineBin string
EngineConfig string
}
tmpl := template.Must(template.New("entrypoint").Parse(engineEntrypointTmpl))
buf := new(bytes.Buffer)
err := tmpl.Execute(buf, entrypointTmplParams{
EngineBin: "/usr/local/bin/" + engineBinName,
EngineConfig: engineTomlPath,
})
if err != nil {
panic(err)
}
engineEntrypoint = buf.String()
}
var publishedEngineArches = []string{"amd64", "arm64"}
func parseRef(tag string) error { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | if tag == "main" {
return nil
}
if ok := semver.IsValid(tag); !ok {
return fmt.Errorf("invalid semver tag: %s", tag)
}
return nil
}
type Engine mg.Namespace
func (t Engine) Build(ctx context.Context) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("build") |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | build := util.GoBase(c).
WithEnvVariable("GOOS", runtime.GOOS).
WithEnvVariable("GOARCH", runtime.GOARCH).
WithExec([]string{"go", "build", "-o", "./bin/dagger", "-ldflags", "-s -w", "/app/cmd/dagger"})
_, err = build.Directory("./bin").Export(ctx, "./bin")
return err
}
func (t Engine) Lint(ctx context.Context) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("lint")
repo := util.RepositoryGoCodeOnly(c)
goMod, err := repo.File("go.mod").Contents(ctx)
if err != nil {
return err
}
for _, l := range strings.Split(goMod, "\n") {
l = strings.TrimSpace(l)
parts := strings.SplitN(l, " ", 2)
if len(parts) != 2 {
continue
}
repo, version := parts[0], parts[1]
if repo != buildkitRepo {
continue
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | buildkitRef := buildkitRef
if strings.Contains(version, "-") {
version = version[strings.LastIndex(version, "-")+1:]
buildkitRef = buildkitRef[:12]
}
if version != buildkitRef {
return fmt.Errorf("buildkit version mismatch: %s (buildkitd) != %s (buildkit in go.mod)", buildkitRef, version)
}
}
_, err = c.Container().
From("golangci/golangci-lint:v1.51").
WithMountedDirectory("/app", repo).
WithWorkdir("/app").
WithExec([]string{"golangci-lint", "run", "-v", "--timeout", "5m"}).
ExitCode(ctx)
return err
}
func (t Engine) Publish(ctx context.Context, version string) error {
if err := parseRef(version); err != nil {
return err
}
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("publish")
engineImage, err := util.WithSetHostVar(ctx, c.Host(), "DAGGER_ENGINE_IMAGE").Value(ctx)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | return err
}
ref := fmt.Sprintf("%s:%s", engineImage, version)
digest, err := c.Container().Publish(ctx, ref, dagger.ContainerPublishOpts{
PlatformVariants: devEngineContainer(c, publishedEngineArches),
})
if err != nil {
return err
}
if semver.IsValid(version) {
sdks := sdk.All{}
if err := sdks.Bump(ctx, version); err != nil {
return err
}
} else {
fmt.Printf("'%s' is not a semver version, skipping image bump in SDKs", version)
}
time.Sleep(3 * time.Second)
fmt.Println("PUBLISHED IMAGE REF:", digest)
return nil
}
func (t Engine) TestPublish(ctx context.Context) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("test-publish")
_, err = c.Container().Export(ctx, "./engine.tar.gz", dagger.ContainerExportOpts{
PlatformVariants: devEngineContainer(c, publishedEngineArches), |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | })
return err
}
func (t Engine) test(ctx context.Context, race bool) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("test")
cgoEnabledEnv := "0"
args := []string{"go", "test", "-p", "16", "-v", "-count=1"}
if race {
args = append(args, "-race", "-timeout=1h")
cgoEnabledEnv = "1"
}
args = append(args, "./...")
output, err := util.GoBase(c).
WithMountedDirectory("/app", util.Repository(c)).
WithWorkdir("/app").
WithEnvVariable("CGO_ENABLED", cgoEnabledEnv).
WithMountedDirectory("/root/.docker", util.HostDockerDir(c)).
WithExec(args).
Stdout(ctx)
if err != nil {
return err
}
fmt.Println(output)
return nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | func (t Engine) Test(ctx context.Context) error {
return t.test(ctx, false)
}
func (t Engine) TestRace(ctx context.Context) error {
return t.test(ctx, true)
}
func (t Engine) Dev(ctx context.Context) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer c.Close()
c = c.Pipeline("engine").Pipeline("dev")
tmpfile, err := os.CreateTemp("", "dagger-engine-export")
if err != nil {
return err
}
defer os.Remove(tmpfile.Name())
arches := []string{runtime.GOARCH}
_, err = c.Container().Export(ctx, tmpfile.Name(), dagger.ContainerExportOpts{
PlatformVariants: devEngineContainer(c, arches),
})
if err != nil {
return err
}
volumeName := util.EngineContainerName
imageName := fmt.Sprintf("localhost/%s:latest", util.EngineContainerName)
loadCmd := exec.CommandContext(ctx, "docker", "load", "-i", tmpfile.Name())
output, err := loadCmd.CombinedOutput() |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | if err != nil {
return fmt.Errorf("docker load failed: %w: %s", err, output)
}
_, imageID, ok := strings.Cut(string(output), "sha256:")
if !ok {
return fmt.Errorf("unexpected output from docker load: %s", output)
}
imageID = strings.TrimSpace(imageID)
if output, err := exec.CommandContext(ctx, "docker",
"tag",
imageID,
imageName,
).CombinedOutput(); err != nil {
return fmt.Errorf("docker tag: %w: %s", err, output)
}
if output, err := exec.CommandContext(ctx, "docker",
"rm",
"-fv",
util.EngineContainerName,
).CombinedOutput(); err != nil {
return fmt.Errorf("docker rm: %w: %s", err, output)
}
runArgs := []string{
"run",
"-d",
"-e", cacheConfigEnvName,
"-e", servicesDNSEnvName,
"-v", volumeName + ":" + engineDefaultStateDir,
"--name", util.EngineContainerName, |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | "--privileged",
}
runArgs = append(runArgs, imageName, "--debug")
if output, err := exec.CommandContext(ctx, "docker", runArgs...).CombinedOutput(); err != nil {
return fmt.Errorf("docker run: %w: %s", err, output)
}
binDest := filepath.Join(os.Getenv("DAGGER_SRC_ROOT"), "bin", "dagger")
_, err = util.HostDaggerBinary(c).Export(ctx, binDest)
if err != nil {
return err
}
fmt.Println("export _EXPERIMENTAL_DAGGER_CLI_BIN=" + binDest)
fmt.Println("export _EXPERIMENTAL_DAGGER_RUNNER_HOST=docker-container://" + util.EngineContainerName)
return nil
}
const cniVersion = "v1.2.0"
func dnsnameBinary(c *dagger.Client, arch string) *dagger.File {
return util.GoBase(c).
WithEnvVariable("GOOS", "linux").
WithEnvVariable("GOARCH", arch).
WithExec([]string{
"go", "build",
"-o", "./bin/dnsname",
"-ldflags", "-s -w",
"/app/cmd/dnsname",
}).
File("./bin/dnsname")
}
func devEngineContainer(c *dagger.Client, arches []string) []*dagger.Container { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | platformVariants := make([]*dagger.Container, 0, len(arches))
for _, arch := range arches {
platformVariants = append(platformVariants, c.
Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/" + arch)}).
From("alpine:"+alpineVersion).
WithExec([]string{
"apk", "add",
"git", "openssh", "pigz", "xz",
"iptables", "ip6tables", "dnsmasq",
}).
WithFile("/usr/local/bin/runc", runcBin(c, arch), dagger.ContainerWithFileOpts{
Permissions: 0700,
}).
WithFile("/usr/local/bin/buildctl", buildctlBin(c, arch)).
WithFile("/usr/local/bin/"+shimBinName, shimBin(c, arch)).
WithFile("/usr/local/bin/"+engineBinName, engineBin(c, arch)).
WithDirectory("/usr/local/bin", qemuBins(c, arch)).
WithDirectory("/opt/cni/bin", cniPlugins(c, arch)).
WithDirectory(engineDefaultStateDir, c.Directory()).
WithNewFile(engineTomlPath, dagger.ContainerWithNewFileOpts{
Contents: engineConfig,
Permissions: 0600, |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | }).
WithNewFile(engineEntrypointPath, dagger.ContainerWithNewFileOpts{
Contents: engineEntrypoint,
Permissions: 755,
}).
WithEntrypoint([]string{"dagger-entrypoint.sh"}),
)
}
return platformVariants
}
func cniPlugins(c *dagger.Client, arch string) *dagger.Directory {
cniURL := fmt.Sprintf(
"https://github.com/containernetworking/plugins/releases/download/%s/cni-plugins-%s-%s-%s.tgz",
cniVersion, "linux", arch, cniVersion,
)
return c.Container().
From("alpine:"+alpineVersion).
WithMountedFile("/tmp/cni-plugins.tgz", c.HTTP(cniURL)).
WithDirectory("/opt/cni/bin", c.Directory()).
WithExec([]string{
"tar", "-xzf", "/tmp/cni-plugins.tgz",
"-C", "/opt/cni/bin",
"./bridge", "./firewall",
"./loopback", "./host-local",
}).
WithFile("/opt/cni/bin/dnsname", dnsnameBinary(c, arch)).
Directory("/opt/cni/bin")
}
func engineBin(c *dagger.Client, arch string) *dagger.File { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | return util.GoBase(c).
WithEnvVariable("GOOS", "linux").
WithEnvVariable("GOARCH", arch).
WithExec([]string{
"go", "build",
"-o", "./bin/" + engineBinName,
"-ldflags", "-s -w",
"/app/cmd/engine",
}).
File("./bin/" + engineBinName)
}
func shimBin(c *dagger.Client, arch string) *dagger.File {
return util.GoBase(c).
WithEnvVariable("GOOS", "linux").
WithEnvVariable("GOARCH", arch).
WithExec([]string{
"go", "build",
"-o", "./bin/" + shimBinName,
"-ldflags", "-s -w",
"/app/cmd/shim",
}).
File("./bin/" + shimBinName)
}
func buildctlBin(c *dagger.Client, arch string) *dagger.File { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,620 | Engine fails, hangs or becomes really slow when several operations are chained | Some users (cc @cpuguy83 ) have observed that when chaining several `WithMountedDirectory` calls, sometimes the engine becomes extremely slow or completely unresponsive.
Discord thread: https://discord.com/channels/707636530424053791/1075544944388882522
@cpuguy83 managed to come up with a simple repro here.
Repro snippet: https://gist.github.com/cpuguy83/b61f22d05fd05a6407008d944f5858f4
cc @sipsma | https://github.com/dagger/dagger/issues/4620 | https://github.com/dagger/dagger/pull/4817 | aaba659eccbc858a0f330c5178cb7ea20f997c94 | 7215711bac3ff9442d0bb59b8d2cc6b2bee70867 | 2023-02-17T23:17:51Z | go | 2023-03-22T23:13:15Z | internal/mage/engine.go | return util.GoBase(c).
WithEnvVariable("GOOS", "linux").
WithEnvVariable("GOARCH", arch).
WithMountedDirectory("/app", c.Git(buildkitRepo).Branch(buildkitRef).Tree()).
WithExec([]string{
"go", "build",
"-o", "./bin/buildctl",
"-ldflags", "-s -w",
"/app/cmd/buildctl",
}).
File("./bin/buildctl")
}
func runcBin(c *dagger.Client, arch string) *dagger.File {
return c.HTTP(fmt.Sprintf(
"https://github.com/opencontainers/runc/releases/download/%s/runc.%s",
runcVersion,
arch,
))
}
func qemuBins(c *dagger.Client, arch string) *dagger.Directory {
return c.
Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/" + arch)}).
From(qemuBinImage).
Rootfs()
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,586 | Go SDK leaks goroutines | ### What is the issue?
It looks like we leak 2 goroutines per API call.
### Log output
```
[...]
2023/02/10 16:59:56 run: 9407 ip: 10.87.50.246/16 elapsed: 43m11.060688359s goroutines: 18818
2023/02/10 16:59:56 run: 9408 ip: 10.87.50.247/16 elapsed: 43m11.30768587s goroutines: 18820
2023/02/10 16:59:56 run: 9409 ip: 10.87.50.248/16 elapsed: 43m11.580243301s goroutines: 18822
2023/02/10 16:59:57 run: 9410 ip: 10.87.50.249/16 elapsed: 43m11.906234657s goroutines: 18824
```
Here are the goroutines + stacks that leak:
```
goroutine 109 [select, 27 minutes]:
net/http.(*persistConn).writeLoop(0xc00024e360)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2410 +0xf2
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x173d
[originating from goroutine 107]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1767 +0x173d
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
goroutine 61 [IO wait, 27 minutes]:
internal/poll.runtime_pollWait(0x7ff68544ab38, 0x72)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/runtime/netpoll.go:306 +0x89
internal/poll.(*pollDesc).wait(0xc00031e200?, 0xc00034c000?, 0x0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc00031e200, {0xc00034c000, 0x1000, 0x1000})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_unix.go:167 +0x299
net.(*netFD).Read(0xc00031e200, {0xc00034c000?, 0x43b4a7?, 0xc000210c30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/fd_posix.go:55 +0x29
net.(*conn).Read(0xc0003180d8, {0xc00034c000?, 0x0?, 0xc0000081a0?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/net.go:183 +0x45
net/http.(*persistConn).Read(0xc0003166c0, {0xc00034c000?, 0xc0002b0180?, 0xc000210d30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1943 +0x4e
bufio.(*Reader).fill(0xc00032c480)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:106 +0xff
bufio.(*Reader).Peek(0xc00032c480, 0x1)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:144 +0x5d
net/http.(*persistConn).readLoop(0xc0003166c0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2107 +0x1ac
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1765 +0x16ea
[originating from goroutine 60]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x16ea
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
```
### Steps to reproduce
Run this program:
```go
package main
import (
"context"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
"strings"
"time"
"dagger.io/dagger"
"github.com/moby/buildkit/identity"
"github.com/rs/cors"
)
func main() {
ctx := context.Background()
c, err := dagger.Connect(ctx)
if err != nil {
panic(err)
}
cor := cors.New(cors.Options{})
go func() {
log.Println(http.ListenAndServe("localhost:6060", cor.Handler(http.DefaultServeMux)))
}()
start := time.Now()
for i := 0; i < 1000000; i++ {
stdout, err := c.Container().
From("alpine:3.16.2").
WithEnvVariable("CACHEBUST", identity.NewID()).
WithExec([]string{"sh", "-c", "ip -f inet addr show eth1 | grep -o '10\\..*/16'"}).
Stdout(ctx)
if err != nil {
panic(err)
}
ip := strings.TrimSpace(stdout)
log.Printf("run: %d\tip: %s\telapsed: %s\tgoroutines: %d", i+1, ip, time.Since(start), runtime.NumGoroutine())
}
}
```
### SDK version
Go SDK `main`
### OS version
Linux | https://github.com/dagger/dagger/issues/4586 | https://github.com/dagger/dagger/pull/4960 | f33ab503f6314324c282eff13b21f54542ace893 | b8bc25cc80f705b182188101b948e6918220ba1d | 2023-02-10T22:02:24Z | go | 2023-04-14T15:52:32Z | sdk/go/internal/engineconn/engineconn.go | package engineconn
import (
"context"
"fmt"
"io"
"net"
"net/http"
"github.com/Khan/genqlient/graphql"
)
type EngineConn interface {
graphql.Doer
Host() string
Close() error
}
type Config struct {
Workdir string
ConfigPath string
NoExtensions bool
LogOutput io.Writer
}
type ConnectParams struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,586 | Go SDK leaks goroutines | ### What is the issue?
It looks like we leak 2 goroutines per API call.
### Log output
```
[...]
2023/02/10 16:59:56 run: 9407 ip: 10.87.50.246/16 elapsed: 43m11.060688359s goroutines: 18818
2023/02/10 16:59:56 run: 9408 ip: 10.87.50.247/16 elapsed: 43m11.30768587s goroutines: 18820
2023/02/10 16:59:56 run: 9409 ip: 10.87.50.248/16 elapsed: 43m11.580243301s goroutines: 18822
2023/02/10 16:59:57 run: 9410 ip: 10.87.50.249/16 elapsed: 43m11.906234657s goroutines: 18824
```
Here are the goroutines + stacks that leak:
```
goroutine 109 [select, 27 minutes]:
net/http.(*persistConn).writeLoop(0xc00024e360)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2410 +0xf2
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x173d
[originating from goroutine 107]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1767 +0x173d
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
goroutine 61 [IO wait, 27 minutes]:
internal/poll.runtime_pollWait(0x7ff68544ab38, 0x72)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/runtime/netpoll.go:306 +0x89
internal/poll.(*pollDesc).wait(0xc00031e200?, 0xc00034c000?, 0x0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc00031e200, {0xc00034c000, 0x1000, 0x1000})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_unix.go:167 +0x299
net.(*netFD).Read(0xc00031e200, {0xc00034c000?, 0x43b4a7?, 0xc000210c30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/fd_posix.go:55 +0x29
net.(*conn).Read(0xc0003180d8, {0xc00034c000?, 0x0?, 0xc0000081a0?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/net.go:183 +0x45
net/http.(*persistConn).Read(0xc0003166c0, {0xc00034c000?, 0xc0002b0180?, 0xc000210d30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1943 +0x4e
bufio.(*Reader).fill(0xc00032c480)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:106 +0xff
bufio.(*Reader).Peek(0xc00032c480, 0x1)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:144 +0x5d
net/http.(*persistConn).readLoop(0xc0003166c0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2107 +0x1ac
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1765 +0x16ea
[originating from goroutine 60]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x16ea
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
```
### Steps to reproduce
Run this program:
```go
package main
import (
"context"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
"strings"
"time"
"dagger.io/dagger"
"github.com/moby/buildkit/identity"
"github.com/rs/cors"
)
func main() {
ctx := context.Background()
c, err := dagger.Connect(ctx)
if err != nil {
panic(err)
}
cor := cors.New(cors.Options{})
go func() {
log.Println(http.ListenAndServe("localhost:6060", cor.Handler(http.DefaultServeMux)))
}()
start := time.Now()
for i := 0; i < 1000000; i++ {
stdout, err := c.Container().
From("alpine:3.16.2").
WithEnvVariable("CACHEBUST", identity.NewID()).
WithExec([]string{"sh", "-c", "ip -f inet addr show eth1 | grep -o '10\\..*/16'"}).
Stdout(ctx)
if err != nil {
panic(err)
}
ip := strings.TrimSpace(stdout)
log.Printf("run: %d\tip: %s\telapsed: %s\tgoroutines: %d", i+1, ip, time.Since(start), runtime.NumGoroutine())
}
}
```
### SDK version
Go SDK `main`
### OS version
Linux | https://github.com/dagger/dagger/issues/4586 | https://github.com/dagger/dagger/pull/4960 | f33ab503f6314324c282eff13b21f54542ace893 | b8bc25cc80f705b182188101b948e6918220ba1d | 2023-02-10T22:02:24Z | go | 2023-04-14T15:52:32Z | sdk/go/internal/engineconn/engineconn.go | Port int `json:"port"`
SessionToken string `json:"session_token"`
}
func Get(ctx context.Context, cfg *Config) (EngineConn, error) {
conn, ok, err := FromSessionEnv()
if err != nil {
return nil, err
}
if ok {
return conn, nil
}
conn, ok, err = FromLocalCLI(ctx, cfg)
if err != nil {
return nil, err
}
if ok {
return conn, nil
}
conn, err = FromDownloadedCLI(ctx, cfg)
if err != nil {
return nil, err
}
return conn, nil
}
func defaultHTTPClient(p *ConnectParams) *http.Client { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,586 | Go SDK leaks goroutines | ### What is the issue?
It looks like we leak 2 goroutines per API call.
### Log output
```
[...]
2023/02/10 16:59:56 run: 9407 ip: 10.87.50.246/16 elapsed: 43m11.060688359s goroutines: 18818
2023/02/10 16:59:56 run: 9408 ip: 10.87.50.247/16 elapsed: 43m11.30768587s goroutines: 18820
2023/02/10 16:59:56 run: 9409 ip: 10.87.50.248/16 elapsed: 43m11.580243301s goroutines: 18822
2023/02/10 16:59:57 run: 9410 ip: 10.87.50.249/16 elapsed: 43m11.906234657s goroutines: 18824
```
Here are the goroutines + stacks that leak:
```
goroutine 109 [select, 27 minutes]:
net/http.(*persistConn).writeLoop(0xc00024e360)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2410 +0xf2
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x173d
[originating from goroutine 107]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1767 +0x173d
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
goroutine 61 [IO wait, 27 minutes]:
internal/poll.runtime_pollWait(0x7ff68544ab38, 0x72)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/runtime/netpoll.go:306 +0x89
internal/poll.(*pollDesc).wait(0xc00031e200?, 0xc00034c000?, 0x0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc00031e200, {0xc00034c000, 0x1000, 0x1000})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/internal/poll/fd_unix.go:167 +0x299
net.(*netFD).Read(0xc00031e200, {0xc00034c000?, 0x43b4a7?, 0xc000210c30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/fd_posix.go:55 +0x29
net.(*conn).Read(0xc0003180d8, {0xc00034c000?, 0x0?, 0xc0000081a0?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/net.go:183 +0x45
net/http.(*persistConn).Read(0xc0003166c0, {0xc00034c000?, 0xc0002b0180?, 0xc000210d30?})
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1943 +0x4e
bufio.(*Reader).fill(0xc00032c480)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:106 +0xff
bufio.(*Reader).Peek(0xc00032c480, 0x1)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/bufio/bufio.go:144 +0x5d
net/http.(*persistConn).readLoop(0xc0003166c0)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:2107 +0x1ac
created by net/http.(*Transport).dialConn
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1765 +0x16ea
[originating from goroutine 60]:
net/http.(*Transport).dialConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1766 +0x16ea
net/http.(*Transport).dialConnFor(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1456 +0xb0
created by net/http.(*Transport).queueForDial
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1425 +0x3ea
[originating from goroutine 1]:
net/http.(*Transport).queueForDial(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1426 +0x3ea
net/http.(*Transport).getConn(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:1383 +0x4dd
net/http.(*Transport).roundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/transport.go:590 +0x79e
dagger.io/dagger/internal/engineconn.defaultHTTPClient.func1(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:62 +0xb8
net/http.(*Transport).RoundTrip(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/roundtrip.go:17 +0xab
dagger.io/dagger/internal/engineconn.RoundTripperFunc.RoundTrip(...)
/home/vito/src/dagger/sdk/go/internal/engineconn/engineconn.go:74 +0x1f
net/http.send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:252 +0x5f7
net/http.(*Client).send(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(...)
/nix/store/dnvng8cdwc2i6g48qxijqmch3w8l3s85-go-1.20/share/go/src/net/http/client.go:716 +0x8fb
dagger.io/dagger/internal/engineconn.(*cliSessionConn).Do(...)
<autogenerated>:1 +0x25
github.com/Khan/genqlient/graphql.(*client).MakeRequest(...)
/home/vito/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/graphql/client.go:144 +0x24b
dagger.io/dagger.errorWrappedClient.MakeRequest(...)
/home/vito/src/dagger/sdk/go/client.go:154 +0x42
dagger.io/dagger/internal/querybuilder.(*Selection).Execute(...)
/home/vito/src/dagger/sdk/go/internal/querybuilder/querybuilder.go:140 +0x102
dagger.io/dagger.(*Container).Stdout(...)
/home/vito/src/dagger/sdk/go/api.gen.go:474 +0x134
main.main(...)
/home/vito/src/dagger/junk/main.go:37 +0x4db
```
### Steps to reproduce
Run this program:
```go
package main
import (
"context"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
"strings"
"time"
"dagger.io/dagger"
"github.com/moby/buildkit/identity"
"github.com/rs/cors"
)
func main() {
ctx := context.Background()
c, err := dagger.Connect(ctx)
if err != nil {
panic(err)
}
cor := cors.New(cors.Options{})
go func() {
log.Println(http.ListenAndServe("localhost:6060", cor.Handler(http.DefaultServeMux)))
}()
start := time.Now()
for i := 0; i < 1000000; i++ {
stdout, err := c.Container().
From("alpine:3.16.2").
WithEnvVariable("CACHEBUST", identity.NewID()).
WithExec([]string{"sh", "-c", "ip -f inet addr show eth1 | grep -o '10\\..*/16'"}).
Stdout(ctx)
if err != nil {
panic(err)
}
ip := strings.TrimSpace(stdout)
log.Printf("run: %d\tip: %s\telapsed: %s\tgoroutines: %d", i+1, ip, time.Since(start), runtime.NumGoroutine())
}
}
```
### SDK version
Go SDK `main`
### OS version
Linux | https://github.com/dagger/dagger/issues/4586 | https://github.com/dagger/dagger/pull/4960 | f33ab503f6314324c282eff13b21f54542ace893 | b8bc25cc80f705b182188101b948e6918220ba1d | 2023-02-10T22:02:24Z | go | 2023-04-14T15:52:32Z | sdk/go/internal/engineconn/engineconn.go | return &http.Client{
Transport: RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
r.SetBasicAuth(p.SessionToken, "")
return (&http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", p.Port))
},
}).RoundTrip(r)
}),
}
}
type RoundTripperFunc func(*http.Request) (*http.Response, error)
func (f RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
return f(r)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | package core
import (
"context"
"encoding/base32"
"encoding/binary"
"encoding/hex" |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | "encoding/json"
"fmt"
"io"
"io/fs"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/pkg/transfer/archive"
"github.com/containerd/containerd/platforms"
"github.com/dagger/dagger/core/pipeline"
"github.com/dagger/dagger/router"
"github.com/docker/distribution/reference"
bkclient "github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/frontend/dockerui"
bkgw "github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/solver/pb"
"github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/vito/progrock"
"github.com/zeebo/xxh3"
)
type Container struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | FS *pb.Definition `json:"fs"`
Config specs.ImageConfig `json:"cfg"`
Pipeline pipeline.Path `json:"pipeline"`
Mounts ContainerMounts `json:"mounts,omitempty"`
Meta *pb.Definition `json:"meta,omitempty"`
Platform specs.Platform `json:"platform,omitempty"`
Secrets []ContainerSecret `json:"secret_env,omitempty"`
Sockets []ContainerSocket `json:"sockets,omitempty"`
ImageRef string `json:"image_ref,omitempty"`
Hostname string `json:"hostname,omitempty"`
Ports []ContainerPort `json:"ports,omitempty"`
Services ServiceBindings `json:"services,omitempty"`
HostAliases []HostAlias `json:"host_aliases,omitempty"`
}
func NewContainer(id ContainerID, pipeline pipeline.Path, platform specs.Platform) (*Container, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | container, err := id.ToContainer()
if err != nil {
return nil, err
}
container.Pipeline = pipeline.Copy()
container.Platform = platform
return container, nil
}
func (container *Container) Clone() *Container {
cp := *container
cp.Mounts = clone(cp.Mounts)
cp.Secrets = clone(cp.Secrets)
cp.Sockets = clone(cp.Sockets)
cp.Ports = clone(cp.Ports)
cp.Services = cloneMap(cp.Services)
cp.HostAliases = clone(cp.HostAliases)
cp.Pipeline = clone(cp.Pipeline)
return &cp
}
type ContainerID string
func (id ContainerID) String() string {
return string(id)
}
var _ router.Digestible = ContainerID("") |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | func (id ContainerID) Digest() (digest.Digest, error) {
return digest.FromString(id.String()), nil
}
func (id ContainerID) ToContainer() (*Container, error) {
var container Container
if id == "" {
return &container, nil
}
if err := decodeID(&container, id); err != nil {
return nil, err
}
return &container, nil
}
func (container *Container) ID() (ContainerID, error) {
return encodeID[ContainerID](container)
}
var _ router.Pipelineable = (*Container)(nil)
func (container *Container) PipelinePath() pipeline.Path {
return container.Pipeline
}
var _ router.Digestible = (*Container)(nil)
func (container *Container) Digest() (digest.Digest, error) {
id, err := container.ID()
if err != nil {
return "", err
}
return id.Digest()
}
type HostAlias struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | Alias string `json:"alias"`
Target string `json:"target"`
}
type Ownership struct {
UID int `json:"uid"`
GID int `json:"gid"`
}
func (owner Ownership) Opt() llb.ChownOption {
return llb.WithUIDGID(owner.UID, owner.GID)
}
type ContainerSecret struct {
Secret SecretID `json:"secret"`
EnvName string `json:"env,omitempty"`
MountPath string `json:"path,omitempty"`
Owner *Ownership `json:"owner,omitempty"`
}
type ContainerSocket struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | Socket SocketID `json:"socket"`
UnixPath string `json:"unix_path,omitempty"`
Owner *Ownership `json:"owner,omitempty"`
}
type ContainerPort struct {
Port int `json:"port"`
Protocol NetworkProtocol `json:"protocol"`
Description *string `json:"description,omitempty"`
}
func (container *Container) FSState() (llb.State, error) {
if container.FS == nil {
return llb.Scratch(), nil
}
return defToState(container.FS)
}
const metaMountDestPath = "/.dagger_meta_mount"
const metaSourcePath = "meta"
func (container *Container) MetaState() (*llb.State, error) {
if container.Meta == nil {
return nil, nil
}
metaSt, err := defToState(container.Meta)
if err != nil {
return nil, err
}
return &metaSt, nil
}
type ContainerMount struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | Source *pb.Definition `json:"source,omitempty"`
SourcePath string `json:"source_path,omitempty"`
Target string `json:"target"`
CacheID string `json:"cache_id,omitempty"`
CacheSharingMode string `json:"cache_sharing,omitempty"`
Tmpfs bool `json:"tmpfs,omitempty"`
}
func (mnt ContainerMount) SourceState() (llb.State, error) {
if mnt.Source == nil {
return llb.Scratch(), nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return defToState(mnt.Source)
}
type ContainerMounts []ContainerMount
func (mnts ContainerMounts) With(newMnt ContainerMount) ContainerMounts {
mntsCp := make(ContainerMounts, 0, len(mnts))
parent := newMnt.Target + "/"
for _, mnt := range mnts {
if mnt.Target == newMnt.Target || strings.HasPrefix(mnt.Target, parent) {
continue
}
mntsCp = append(mntsCp, mnt)
}
mntsCp = append(mntsCp, newMnt)
return mntsCp
}
type PipelineMetaResolver struct {
Resolver llb.ImageMetaResolver
Pipeline pipeline.Path
}
func (r PipelineMetaResolver) ResolveImageConfig(ctx context.Context, ref string, opt llb.ResolveImageConfigOpt) (digest.Digest, []byte, error) {
opt.LogName = pipeline.CustomName{
Name: fmt.Sprintf("resolve image config for %s", ref),
Pipeline: r.Pipeline,
}.String()
return r.Resolver.ResolveImageConfig(ctx, ref, opt)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | func (container *Container) From(ctx context.Context, gw bkgw.Client, addr string) (*Container, error) {
container = container.Clone()
platform := container.Platform
pipelineName := fmt.Sprintf("from %s", addr)
p := container.Pipeline.Add(pipeline.Pipeline{
Name: pipelineName,
})
ctx, subRecorder := progrock.WithGroup(ctx, pipelineName)
refName, err := reference.ParseNormalizedNamed(addr)
if err != nil {
return nil, err
}
ref := reference.TagNameOnly(refName).String()
resolver := PipelineMetaResolver{
Resolver: gw,
Pipeline: p,
}
digest, cfgBytes, err := resolver.ResolveImageConfig(ctx, ref, llb.ResolveImageConfigOpt{
Platform: &platform,
ResolveMode: llb.ResolveModeDefault.String(),
})
if err != nil {
return nil, err
}
digested, err := reference.WithDigest(refName, digest)
if err != nil {
return nil, err
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | var imgSpec specs.Image
if err := json.Unmarshal(cfgBytes, &imgSpec); err != nil {
return nil, err
}
fsSt := llb.Image(
digested.String(),
llb.WithCustomNamef("pull %s", ref),
p.LLBOpt(),
)
def, err := fsSt.Marshal(ctx, llb.Platform(container.Platform))
if err != nil {
return nil, err
}
container.FS = def.ToPB()
recordVertexes(subRecorder, container.FS)
imgSpec.Config.Env = append(container.Config.Env, imgSpec.Config.Env...)
container.Config = imgSpec.Config
container.ImageRef = digested.String()
return container, nil
}
const defaultDockerfileName = "Dockerfile"
var buildCache = newCacheMap[uint64, *Container]()
func cacheKey(keys ...any) uint64 {
hash := xxh3.New()
enc := json.NewEncoder(hash)
for _, key := range keys {
enc.Encode(key)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return hash.Sum64()
}
func (container *Container) Build(
ctx context.Context,
gw bkgw.Client,
context *Directory,
dockerfile string,
buildArgs []BuildArg,
target string,
secrets []SecretID,
) (*Container, error) {
return buildCache.GetOrInitialize(
cacheKey(container, context, dockerfile, buildArgs, target, secrets),
func() (*Container, error) {
return container.buildUncached(ctx, gw, context, dockerfile, buildArgs, target, secrets)
},
)
}
func (container *Container) buildUncached(
ctx context.Context,
gw bkgw.Client,
context *Directory,
dockerfile string,
buildArgs []BuildArg,
target string,
secrets []SecretID,
) (*Container, error) {
container = container.Clone()
container.Services.Merge(context.Services)
for _, secretID := range secrets { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | secret, err := secretID.ToSecret()
if err != nil {
return nil, err
}
container.Secrets = append(container.Secrets, ContainerSecret{
Secret: secretID,
MountPath: fmt.Sprintf("/run/secrets/%s", secret.Name),
})
}
container.ImageRef = ""
pipelineName := "docker build"
subPipeline := container.Pipeline.Add(pipeline.Pipeline{
Name: pipelineName,
})
ctx, subRecorder := progrock.WithGroup(ctx, pipelineName)
return WithServices(ctx, gw, container.Services, func() (*Container, error) {
platform := container.Platform
opts := map[string]string{
"platform": platforms.Format(platform),
"contextsubdir": context.Dir,
}
if dockerfile != "" {
opts["filename"] = path.Join(context.Dir, dockerfile)
} else {
opts["filename"] = path.Join(context.Dir, defaultDockerfileName)
}
if target != "" {
opts["target"] = target
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | for _, buildArg := range buildArgs {
opts["build-arg:"+buildArg.Name] = buildArg.Value
}
inputs := map[string]*pb.Definition{
dockerui.DefaultLocalNameContext: context.LLB,
dockerui.DefaultLocalNameDockerfile: context.LLB,
}
res, err := gw.Solve(ctx, bkgw.SolveRequest{
Frontend: "dockerfile.v0",
FrontendOpt: opts,
FrontendInputs: inputs,
})
if err != nil {
return nil, err
}
bkref, err := res.SingleRef()
if err != nil {
return nil, err
}
var st llb.State
if bkref == nil {
st = llb.Scratch()
} else {
st, err = bkref.ToState()
if err != nil {
return nil, err
}
}
def, err := st.Marshal(ctx, llb.Platform(platform))
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return nil, err
}
recordVertexes(subRecorder, def.ToPB())
overrideProgress(def, subPipeline)
container.FS = def.ToPB()
container.FS.Source = nil
cfgBytes, found := res.Metadata[exptypes.ExporterImageConfigKey]
if found {
var imgSpec specs.Image
if err := json.Unmarshal(cfgBytes, &imgSpec); err != nil {
return nil, err
}
container.Config = imgSpec.Config
}
return container, nil
})
}
func (container *Container) RootFS(ctx context.Context) (*Directory, error) {
return &Directory{
LLB: container.FS,
Dir: "/",
Platform: container.Platform,
Pipeline: container.Pipeline,
Services: container.Services,
}, nil
}
func (container *Container) WithRootFS(ctx context.Context, dir *Directory) (*Container, error) {
container = container.Clone()
dirSt, err := dir.StateWithSourcePath() |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if err != nil {
return nil, err
}
def, err := dirSt.Marshal(ctx, llb.Platform(dir.Platform))
if err != nil {
return nil, err
}
container.FS = def.ToPB()
container.Services.Merge(dir.Services)
container.ImageRef = ""
return container, nil
}
func (container *Container) WithDirectory(ctx context.Context, gw bkgw.Client, subdir string, src *Directory, filter CopyFilter, owner string) (*Container, error) {
container = container.Clone()
return container.writeToPath(ctx, gw, subdir, func(dir *Directory) (*Directory, error) {
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, err
}
return dir.WithDirectory(ctx, ".", src, filter, ownership)
})
}
func (container *Container) WithFile(ctx context.Context, gw bkgw.Client, subdir string, src *File, permissions fs.FileMode, owner string) (*Container, error) {
container = container.Clone()
return container.writeToPath(ctx, gw, subdir, func(dir *Directory) (*Directory, error) {
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, err
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return dir.WithFile(ctx, ".", src, permissions, ownership)
})
}
func (container *Container) WithNewFile(ctx context.Context, gw bkgw.Client, dest string, content []byte, permissions fs.FileMode, owner string) (*Container, error) {
container = container.Clone()
dir, file := filepath.Split(dest)
return container.writeToPath(ctx, gw, dir, func(dir *Directory) (*Directory, error) {
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, err
}
return dir.WithNewFile(ctx, file, content, permissions, ownership)
})
}
func (container *Container) WithMountedDirectory(ctx context.Context, gw bkgw.Client, target string, dir *Directory, owner string) (*Container, error) {
container = container.Clone()
return container.withMounted(ctx, gw, target, dir.LLB, dir.Dir, dir.Services, owner)
}
func (container *Container) WithMountedFile(ctx context.Context, gw bkgw.Client, target string, file *File, owner string) (*Container, error) {
container = container.Clone()
return container.withMounted(ctx, gw, target, file.LLB, file.File, file.Services, owner)
}
func (container *Container) WithMountedCache(ctx context.Context, gw bkgw.Client, target string, cache *CacheVolume, source *Directory, concurrency CacheSharingMode, owner string) (*Container, error) {
container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
cacheSharingMode := ""
switch concurrency {
case CacheSharingModePrivate:
cacheSharingMode = "private"
case CacheSharingModeLocked: |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | cacheSharingMode = "locked"
default:
cacheSharingMode = "shared"
}
mount := ContainerMount{
Target: target,
CacheID: cache.Sum(),
CacheSharingMode: cacheSharingMode,
}
if source != nil {
mount.Source = source.LLB
mount.SourcePath = source.Dir
}
if owner != "" {
var err error
mount.Source, mount.SourcePath, err = container.chown(
ctx,
gw,
mount.Source,
mount.SourcePath,
owner,
llb.Platform(container.Platform),
)
if err != nil {
return nil, err
}
}
container.Mounts = container.Mounts.With(mount)
container.ImageRef = "" |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return container, nil
}
func (container *Container) WithMountedTemp(ctx context.Context, target string) (*Container, error) {
container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
container.Mounts = container.Mounts.With(ContainerMount{
Target: target,
Tmpfs: true,
})
container.ImageRef = ""
return container, nil
}
func (container *Container) WithMountedSecret(ctx context.Context, gw bkgw.Client, target string, source *Secret, owner string) (*Container, error) {
container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, err
}
secretID, err := source.ID()
if err != nil {
return nil, err
}
container.Secrets = append(container.Secrets, ContainerSecret{
Secret: secretID,
MountPath: target,
Owner: ownership,
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | container.ImageRef = ""
return container, nil
}
func (container *Container) WithoutMount(ctx context.Context, target string) (*Container, error) {
container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
var found bool
var foundIdx int
for i := len(container.Mounts) - 1; i >= 0; i-- {
if container.Mounts[i].Target == target {
found = true
foundIdx = i
break
}
}
if found {
container.Mounts = append(container.Mounts[:foundIdx], container.Mounts[foundIdx+1:]...)
}
container.ImageRef = ""
return container, nil
}
func (container *Container) MountTargets(ctx context.Context) ([]string, error) {
mounts := []string{}
for _, mnt := range container.Mounts {
mounts = append(mounts, mnt.Target)
}
return mounts, nil
}
func (container *Container) WithUnixSocket(ctx context.Context, gw bkgw.Client, target string, source *Socket, owner string) (*Container, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, err
}
socketID, err := source.ID()
if err != nil {
return nil, err
}
newSocket := ContainerSocket{
Socket: socketID,
UnixPath: target,
Owner: ownership,
}
var replaced bool
for i, sock := range container.Sockets {
if sock.UnixPath == target {
container.Sockets[i] = newSocket
replaced = true
break
}
}
if !replaced {
container.Sockets = append(container.Sockets, newSocket)
}
container.ImageRef = ""
return container, nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | func (container *Container) WithoutUnixSocket(ctx context.Context, target string) (*Container, error) {
container = container.Clone()
target = absPath(container.Config.WorkingDir, target)
for i, sock := range container.Sockets {
if sock.UnixPath == target {
container.Sockets = append(container.Sockets[:i], container.Sockets[i+1:]...)
break
}
}
container.ImageRef = ""
return container, nil
}
func (container *Container) WithSecretVariable(ctx context.Context, name string, secret *Secret) (*Container, error) {
container = container.Clone()
secretID, err := secret.ID()
if err != nil {
return nil, err
}
container.Secrets = append(container.Secrets, ContainerSecret{
Secret: secretID,
EnvName: name,
})
container.ImageRef = ""
return container, nil
}
func (container *Container) Directory(ctx context.Context, gw bkgw.Client, dirPath string) (*Directory, error) {
dir, _, err := locatePath(ctx, container, dirPath, NewDirectory)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return nil, err
}
info, err := dir.Stat(ctx, gw, ".")
if err != nil {
return nil, err
}
if !info.IsDir() {
return nil, fmt.Errorf("path %s is a file, not a directory", dirPath)
}
return dir, nil
}
func (container *Container) File(ctx context.Context, gw bkgw.Client, filePath string) (*File, error) {
file, _, err := locatePath(ctx, container, filePath, NewFile)
if err != nil {
return nil, err
}
info, err := file.Stat(ctx, gw)
if err != nil {
return nil, err
}
if info.IsDir() {
return nil, fmt.Errorf("path %s is a directory, not a file", filePath)
}
return file, nil
}
func locatePath[T *File | *Directory]( |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | ctx context.Context,
container *Container,
containerPath string,
init func(context.Context, *pb.Definition, string, pipeline.Path, specs.Platform, ServiceBindings) T,
) (T, *ContainerMount, error) {
containerPath = absPath(container.Config.WorkingDir, containerPath)
for i := len(container.Mounts) - 1; i >= 0; i-- {
mnt := container.Mounts[i]
if containerPath == mnt.Target || strings.HasPrefix(containerPath, mnt.Target+"/") {
if mnt.Tmpfs {
return nil, nil, fmt.Errorf("%s: cannot retrieve path from tmpfs", containerPath)
}
if mnt.CacheID != "" {
return nil, nil, fmt.Errorf("%s: cannot retrieve path from cache", containerPath)
}
sub := mnt.SourcePath
if containerPath != mnt.Target {
dirSub := strings.TrimPrefix(containerPath, mnt.Target+"/")
if dirSub != "" {
sub = path.Join(sub, dirSub)
}
}
return init(
ctx,
mnt.Source, |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | sub,
container.Pipeline,
container.Platform,
container.Services,
), &mnt, nil
}
}
return init(
ctx,
container.FS,
containerPath,
container.Pipeline,
container.Platform,
container.Services,
), nil, nil
}
func (container *Container) withMounted(
ctx context.Context,
gw bkgw.Client,
target string,
srcDef *pb.Definition,
srcPath string,
svcs ServiceBindings,
owner string,
) (*Container, error) {
target = absPath(container.Config.WorkingDir, target)
var err error
if owner != "" {
srcDef, srcPath, err = container.chown(ctx, gw, srcDef, srcPath, owner, llb.Platform(container.Platform)) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if err != nil {
return nil, err
}
}
container.Mounts = container.Mounts.With(ContainerMount{
Source: srcDef,
SourcePath: srcPath,
Target: target,
})
container.Services.Merge(svcs)
container.ImageRef = ""
return container, nil
}
func (container *Container) chown(
ctx context.Context,
gw bkgw.Client,
srcDef *pb.Definition,
srcPath string,
owner string,
opts ...llb.ConstraintsOpt,
) (*pb.Definition, string, error) {
ownership, err := container.ownership(ctx, gw, owner)
if err != nil {
return nil, "", err
}
if ownership == nil {
return srcDef, srcPath, nil
}
var srcSt llb.State |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if srcDef == nil {
srcSt = llb.Scratch().File(
llb.Mkdir("/chown", 0o755, ownership.Opt()),
)
srcPath = "/chown"
} else {
srcSt, err = defToState(srcDef)
if err != nil {
return nil, "", err
}
def, err := srcSt.Marshal(ctx, opts...)
if err != nil {
return nil, "", err
}
ref, err := gwRef(ctx, gw, def.ToPB())
if err != nil {
return nil, "", err
}
stat, err := ref.StatFile(ctx, bkgw.StatRequest{
Path: srcPath,
})
if err != nil {
return nil, "", err
}
if stat.IsDir() {
chowned := "/chown" |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | srcSt = llb.Scratch().File(
llb.Mkdir(chowned, os.FileMode(stat.Mode), ownership.Opt()).
Copy(srcSt, srcPath, chowned, &llb.CopyInfo{
CopyDirContentsOnly: true,
}, ownership.Opt()),
)
srcPath = chowned
} else {
srcSt = llb.Scratch().File(
llb.Copy(srcSt, srcPath, ".", ownership.Opt()),
)
srcPath = filepath.Base(srcPath)
}
}
def, err := srcSt.Marshal(ctx, opts...)
if err != nil {
return nil, "", err
}
return def.ToPB(), srcPath, nil
}
func (container *Container) writeToPath(ctx context.Context, gw bkgw.Client, subdir string, fn func(dir *Directory) (*Directory, error)) (*Container, error) {
dir, mount, err := locatePath(ctx, container, subdir, NewDirectory)
if err != nil {
return nil, err
}
dir.Pipeline = container.Pipeline
dir, err = fn(dir)
if err != nil {
return nil, err
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if mount == nil {
root, err := dir.Root()
if err != nil {
return nil, err
}
return container.WithRootFS(ctx, root)
}
return container.withMounted(ctx, gw, mount.Target, dir.LLB, mount.SourcePath, nil, "")
}
func (container *Container) ImageConfig(ctx context.Context) (specs.ImageConfig, error) {
return container.Config, nil
}
func (container *Container) UpdateImageConfig(ctx context.Context, updateFn func(specs.ImageConfig) specs.ImageConfig) (*Container, error) {
container = container.Clone()
container.Config = updateFn(container.Config)
return container, nil
}
func (container *Container) WithPipeline(ctx context.Context, name, description string, labels []pipeline.Label) (*Container, error) {
container = container.Clone()
container.Pipeline = container.Pipeline.Add(pipeline.Pipeline{
Name: name,
Description: description,
Labels: labels,
})
return container, nil
}
func (container *Container) WithExec(ctx context.Context, gw bkgw.Client, progSock *Socket, defaultPlatform specs.Platform, opts ContainerExecOpts) (*Container, error) {
container = container.Clone()
cfg := container.Config |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | mounts := container.Mounts
platform := container.Platform
if platform.OS == "" {
platform = defaultPlatform
}
args := opts.Args
if len(args) == 0 {
args = cfg.Cmd
}
if len(cfg.Entrypoint) > 0 && !opts.SkipEntrypoint {
args = append(cfg.Entrypoint, args...)
}
if len(args) == 0 {
return nil, errors.New("no command has been set")
}
runOpts := []llb.RunOption{
llb.Args(args),
container.Pipeline.LLBOpt(),
llb.WithCustomNamef("exec %s", strings.Join(args, " ")),
}
if opts.ExperimentalPrivilegedNesting {
sid, err := progSock.ID()
if err != nil {
return nil, err
}
runOpts = append(runOpts,
llb.AddEnv("_DAGGER_ENABLE_NESTING", ""),
llb.AddSSHSocket( |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | llb.SSHID(sid.LLBID()),
llb.SSHSocketTarget("/.progrock.sock"),
),
)
}
meta := llb.Mkdir(metaSourcePath, 0o777)
if opts.Stdin != "" {
meta = meta.Mkfile(path.Join(metaSourcePath, "stdin"), 0o600, []byte(opts.Stdin))
}
runOpts = append(runOpts,
llb.AddMount(metaMountDestPath,
llb.Scratch().File(meta, pipeline.CustomName{Name: "creating dagger metadata", Internal: true}.LLBOpt(), container.Pipeline.LLBOpt()),
llb.SourcePath(metaSourcePath)))
if opts.RedirectStdout != "" {
runOpts = append(runOpts, llb.AddEnv("_DAGGER_REDIRECT_STDOUT", opts.RedirectStdout))
}
if opts.RedirectStderr != "" {
runOpts = append(runOpts, llb.AddEnv("_DAGGER_REDIRECT_STDERR", opts.RedirectStderr))
}
for _, alias := range container.HostAliases {
runOpts = append(runOpts, llb.AddEnv("_DAGGER_HOSTNAME_ALIAS_"+alias.Alias, alias.Target))
}
if cfg.User != "" {
runOpts = append(runOpts, llb.User(cfg.User))
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if cfg.WorkingDir != "" {
runOpts = append(runOpts, llb.Dir(cfg.WorkingDir))
}
for _, env := range cfg.Env {
name, val, ok := strings.Cut(env, "=")
if !ok {
_ = ok
}
if name == "_DAGGER_ENABLE_NESTING" && !opts.ExperimentalPrivilegedNesting {
continue
}
if name == DebugFailedExecEnv {
continue
}
runOpts = append(runOpts, llb.AddEnv(name, val))
}
secretsToScrub := SecretToScrubInfo{}
for i, secret := range container.Secrets {
secretOpts := []llb.SecretOption{llb.SecretID(secret.Secret.String())}
var secretDest string
switch {
case secret.EnvName != "":
secretDest = secret.EnvName
secretOpts = append(secretOpts, llb.SecretAsEnv(true))
secretsToScrub.Envs = append(secretsToScrub.Envs, secret.EnvName) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | case secret.MountPath != "":
secretDest = secret.MountPath
secretsToScrub.Files = append(secretsToScrub.Files, secret.MountPath)
if secret.Owner != nil {
secretOpts = append(secretOpts, llb.SecretFileOpt(
secret.Owner.UID,
secret.Owner.GID,
0o400,
))
}
default:
return nil, fmt.Errorf("malformed secret config at index %d", i)
}
runOpts = append(runOpts, llb.AddSecret(secretDest, secretOpts...))
}
if len(secretsToScrub.Envs) != 0 || len(secretsToScrub.Files) != 0 {
sort.Strings(secretsToScrub.Envs)
sort.Strings(secretsToScrub.Files)
secretsToScrubJSON, err := json.Marshal(secretsToScrub)
if err != nil {
return nil, fmt.Errorf("scrub secrets json: %w", err)
}
runOpts = append(runOpts, llb.AddEnv("_DAGGER_SCRUB_SECRETS", string(secretsToScrubJSON)))
}
for _, socket := range container.Sockets {
if socket.UnixPath == "" {
return nil, fmt.Errorf("unsupported socket: only unix paths are implemented")
}
socketOpts := []llb.SSHOption{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | llb.SSHID(socket.Socket.LLBID()),
llb.SSHSocketTarget(socket.UnixPath),
}
if socket.Owner != nil {
socketOpts = append(socketOpts,
llb.SSHSocketOpt(
socket.UnixPath,
socket.Owner.UID,
socket.Owner.GID,
0o600,
))
}
runOpts = append(runOpts, llb.AddSSHSocket(socketOpts...))
}
for _, mnt := range mounts {
srcSt, err := mnt.SourceState()
if err != nil {
return nil, fmt.Errorf("mount %s: %w", mnt.Target, err)
}
mountOpts := []llb.MountOption{}
if mnt.SourcePath != "" {
mountOpts = append(mountOpts, llb.SourcePath(mnt.SourcePath))
}
if mnt.CacheID != "" {
var sharingMode llb.CacheMountSharingMode
switch mnt.CacheSharingMode {
case "shared":
sharingMode = llb.CacheMountShared
case "private":
sharingMode = llb.CacheMountPrivate |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | case "locked":
sharingMode = llb.CacheMountLocked
default:
return nil, errors.Errorf("invalid cache mount sharing mode %q", mnt.CacheSharingMode)
}
mountOpts = append(mountOpts, llb.AsPersistentCacheDir(mnt.CacheID, sharingMode))
}
if mnt.Tmpfs {
mountOpts = append(mountOpts, llb.Tmpfs())
}
runOpts = append(runOpts, llb.AddMount(mnt.Target, srcSt, mountOpts...))
}
if opts.InsecureRootCapabilities {
runOpts = append(runOpts, llb.Security(llb.SecurityModeInsecure))
}
fsSt, err := container.FSState()
if err != nil {
return nil, fmt.Errorf("fs state: %w", err)
}
execStNoHostname := fsSt.Run(runOpts...)
constraints := llb.NewConstraints(llb.Platform(platform))
rootVtx := execStNoHostname.Root().Output().Vertex(ctx, constraints)
digest, _, _, _, err := rootVtx.Marshal(ctx, constraints)
if err != nil {
return nil, fmt.Errorf("marshal: %w", err)
}
hostname := hostHash(digest)
container.Hostname = hostname |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | runOpts = append(runOpts, llb.Hostname(hostname))
execSt := fsSt.Run(runOpts...)
execDef, err := execSt.Root().Marshal(ctx, llb.Platform(platform))
if err != nil {
return nil, fmt.Errorf("marshal root: %w", err)
}
container.FS = execDef.ToPB()
metaDef, err := execSt.GetMount(metaMountDestPath).Marshal(ctx, llb.Platform(platform))
if err != nil {
return nil, fmt.Errorf("get meta mount: %w", err)
}
container.Meta = metaDef.ToPB()
for i, mnt := range mounts {
if mnt.Tmpfs || mnt.CacheID != "" {
continue
}
mountSt := execSt.GetMount(mnt.Target)
execMountDef, err := mountSt.Marshal(ctx, llb.Platform(platform))
if err != nil {
return nil, fmt.Errorf("propagate %s: %w", mnt.Target, err)
}
mounts[i].Source = execMountDef.ToPB()
}
container.Mounts = mounts
container.ImageRef = ""
return container, nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | func (container *Container) Evaluate(ctx context.Context, gw bkgw.Client, pipelineOverride *pipeline.Path) error {
if container.FS == nil {
return nil
}
_, err := WithServices(ctx, gw, container.Services, func() (*bkgw.Result, error) {
st, err := container.FSState()
if err != nil {
return nil, err
}
def, err := st.Marshal(ctx, llb.Platform(container.Platform))
if err != nil {
return nil, err
}
if pipelineOverride != nil {
recordVertexes(progrock.RecorderFromContext(ctx), def.ToPB())
overrideProgress(def, *pipelineOverride)
}
return gw.Solve(ctx, bkgw.SolveRequest{
Evaluate: true,
Definition: def.ToPB(),
})
})
return err
}
func (container *Container) ExitCode(ctx context.Context, gw bkgw.Client, progSock *Socket) (int, error) {
content, err := container.MetaFileContents(ctx, gw, progSock, "exitCode")
if err != nil {
return 0, err
}
return strconv.Atoi(content) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | }
func (container *Container) Start(ctx context.Context, gw bkgw.Client) (*Service, error) {
if container.Hostname == "" {
return nil, ErrContainerNoExec
}
health := newHealth(gw, container.Hostname, container.Ports)
pipelineName := fmt.Sprintf("service %s", container.Hostname)
pipeline := container.Pipeline.Add(pipeline.Pipeline{
Name: pipelineName,
Labels: []pipeline.Label{
{
Name: pipeline.ServiceHostnameLabel,
Value: container.Hostname,
},
},
})
rec := progrock.RecorderFromContext(ctx).WithGroup(pipelineName)
svcCtx, stop := context.WithCancel(context.Background())
svcCtx = progrock.RecorderToContext(svcCtx, rec)
checked := make(chan error, 1)
go func() {
checked <- health.Check(ctx)
}()
exited := make(chan error, 1)
go func() {
exited <- container.Evaluate(svcCtx, gw, &pipeline)
}()
select { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | case err := <-checked:
if err != nil {
stop()
return nil, fmt.Errorf("health check errored: %w", err)
}
_ = stop
return &Service{
Container: container,
Detach: stop,
}, nil
case err := <-exited:
stop()
if err != nil {
return nil, fmt.Errorf("exited: %w", err)
}
return nil, fmt.Errorf("service exited before healthcheck")
}
}
func (container *Container) MetaFileContents(ctx context.Context, gw bkgw.Client, progSock *Socket, filePath string) (string, error) {
if container.Meta == nil {
ctr, err := container.WithExec(ctx, gw, progSock, container.Platform, ContainerExecOpts{})
if err != nil {
return "", err
}
return ctr.MetaFileContents(ctx, gw, progSock, filePath)
}
file := NewFile(
ctx,
container.Meta,
path.Join(metaSourcePath, filePath), |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | container.Pipeline,
container.Platform,
container.Services,
)
content, err := file.Contents(ctx, gw)
if err != nil {
return "", err
}
return string(content), nil
}
func (container *Container) Publish(
ctx context.Context,
ref string,
platformVariants []ContainerID,
forcedCompression ImageLayerCompression,
bkClient *bkclient.Client,
solveOpts bkclient.SolveOpt,
solveCh chan<- *bkclient.SolveStatus,
) (string, error) {
solveOpts.Exports = []bkclient.ExportEntry{
{
Type: bkclient.ExporterImage,
Attrs: map[string]string{
"name": ref,
"push": strconv.FormatBool(true),
},
},
}
if forcedCompression != "" { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | compressionStr := strings.ToLower(string(forcedCompression))
solveOpts.Exports[0].Attrs["compression"] = compressionStr
solveOpts.Exports[0].Attrs["force-compression"] = strconv.FormatBool(true)
if forcedCompression == CompressionEStarGZ {
solveOpts.Exports[0].Attrs["oci-mediatypes"] = strconv.FormatBool(true)
}
}
ch, wg := mirrorCh(solveCh)
defer wg.Wait()
res, err := bkClient.Build(ctx, solveOpts, "", func(ctx context.Context, gw bkgw.Client) (*bkgw.Result, error) {
return container.export(ctx, gw, platformVariants)
}, ch)
if err != nil {
return "", err
}
refName, err := reference.ParseNormalizedNamed(ref)
if err != nil {
return "", err
}
imageDigest, found := res.ExporterResponse[exptypes.ExporterImageDigestKey]
if found {
dig, err := digest.Parse(imageDigest)
if err != nil {
return "", fmt.Errorf("parse digest: %w", err)
}
withDig, err := reference.WithDigest(refName, dig)
if err != nil {
return "", fmt.Errorf("with digest: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return withDig.String(), nil
}
return ref, nil
}
func (container *Container) Export(
ctx context.Context,
host *Host,
dest string,
platformVariants []ContainerID,
forcedCompression ImageLayerCompression,
bkClient *bkclient.Client,
solveOpts bkclient.SolveOpt,
solveCh chan<- *bkclient.SolveStatus,
) error {
dest, err := host.NormalizeDest(dest)
if err != nil {
return err
}
out, err := os.Create(dest)
if err != nil {
return err
}
defer out.Close()
exportOpts := bkclient.ExportEntry{
Type: bkclient.ExporterOCI,
Output: func(map[string]string) (io.WriteCloser, error) {
return out, nil
},
}
if forcedCompression != "" { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | compressionStr := strings.ToLower(string(forcedCompression))
exportOpts.Attrs = map[string]string{
"compression": compressionStr,
"force-compression": strconv.FormatBool(true),
}
if forcedCompression == CompressionEStarGZ {
exportOpts.Attrs["oci-mediatypes"] = strconv.FormatBool(true)
}
}
return host.Export(ctx, exportOpts, bkClient, solveOpts, solveCh, func(ctx context.Context, gw bkgw.Client) (*bkgw.Result, error) {
return container.export(ctx, gw, platformVariants)
})
}
const OCIStoreName = "dagger-oci"
var importCache = newCacheMap[uint64, *Container]()
func (container *Container) Import(
ctx context.Context,
gw bkgw.Client,
host *Host,
source FileID,
tag string,
store content.Store,
) (*Container, error) {
return importCache.GetOrInitialize(
cacheKey(container, source, tag),
func() (*Container, error) {
return container.importUncached(ctx, gw, host, source, tag, store)
},
) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | }
func (container *Container) importUncached(
ctx context.Context,
gw bkgw.Client,
host *Host,
source FileID,
tag string,
store content.Store,
) (*Container, error) {
file, err := source.ToFile()
if err != nil {
return nil, err
}
src, err := file.Open(ctx, host, gw)
if err != nil {
return nil, err
}
defer src.Close()
container = container.Clone()
stream := archive.NewImageImportStream(src, "")
desc, err := stream.Import(ctx, store)
if err != nil {
return nil, fmt.Errorf("image archive import: %w", err)
}
manifestDesc, err := resolveIndex(ctx, store, desc, container.Platform, tag)
if err != nil {
return nil, fmt.Errorf("image archive resolve index: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | dummyRepo := "dagger/import"
st := llb.OCILayout(
fmt.Sprintf("%s@%s", dummyRepo, manifestDesc.Digest),
llb.OCIStore("", OCIStoreName),
llb.Platform(container.Platform),
)
execDef, err := st.Marshal(ctx, llb.Platform(container.Platform))
if err != nil {
return nil, fmt.Errorf("marshal root: %w", err)
}
container.FS = execDef.ToPB()
manifestBlob, err := content.ReadBlob(ctx, store, *manifestDesc)
if err != nil {
return nil, fmt.Errorf("image archive read manifest blob: %w", err)
}
var man specs.Manifest
err = json.Unmarshal(manifestBlob, &man)
if err != nil {
return nil, fmt.Errorf("image archive unmarshal manifest: %w", err)
}
configBlob, err := content.ReadBlob(ctx, store, man.Config)
if err != nil {
return nil, fmt.Errorf("image archive read image config blob %s: %w", man.Config.Digest, err)
}
var imgSpec specs.Image
err = json.Unmarshal(configBlob, &imgSpec)
if err != nil {
return nil, fmt.Errorf("load image config: %w", err)
}
container.Config = imgSpec.Config |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return container, nil
}
func (container *Container) HostnameOrErr() (string, error) {
if container.Hostname == "" {
return "", ErrContainerNoExec
}
return container.Hostname, nil
}
func (container *Container) Endpoint(port int, scheme string) (string, error) {
if port == 0 {
if len(container.Ports) == 0 {
return "", fmt.Errorf("no ports exposed")
}
port = container.Ports[0].Port
}
host, err := container.HostnameOrErr()
if err != nil {
return "", err
}
endpoint := fmt.Sprintf("%s:%d", host, port)
if scheme != "" {
endpoint = scheme + ":" + endpoint
}
return endpoint, nil
}
func (container *Container) WithExposedPort(port ContainerPort) (*Container, error) {
container = container.Clone()
container.Ports = append(container.Ports, port)
if container.Config.ExposedPorts == nil {
container.Config.ExposedPorts = map[string]struct{}{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | }
ociPort := fmt.Sprintf("%d/%s", port.Port, port.Protocol.Network())
container.Config.ExposedPorts[ociPort] = struct{}{}
return container, nil
}
func (container *Container) WithoutExposedPort(port int, protocol NetworkProtocol) (*Container, error) {
container = container.Clone()
filtered := []ContainerPort{}
filteredOCI := map[string]struct{}{}
for _, p := range container.Ports {
if p.Port != port || p.Protocol != protocol {
filtered = append(filtered, p)
ociPort := fmt.Sprintf("%d/%s", p.Port, p.Protocol.Network())
filteredOCI[ociPort] = struct{}{}
}
}
container.Ports = filtered
container.Config.ExposedPorts = filteredOCI
return container, nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | func (container *Container) WithServiceBinding(svc *Container, alias string) (*Container, error) {
container = container.Clone()
svcID, err := svc.ID()
if err != nil {
return nil, err
}
container.Services.Merge(ServiceBindings{
svcID: AliasSet{alias},
})
if alias != "" {
hn, err := svc.HostnameOrErr()
if err != nil {
return nil, fmt.Errorf("get hostname: %w", err)
}
container.HostAliases = append(container.HostAliases, HostAlias{
Alias: alias,
Target: hn,
})
}
return container, nil
}
func (container *Container) export(
ctx context.Context,
gw bkgw.Client,
platformVariants []ContainerID,
) (*bkgw.Result, error) {
containers := []*Container{}
services := ServiceBindings{}
if container.FS != nil {
containers = append(containers, container) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | services.Merge(container.Services)
}
for _, id := range platformVariants {
variant, err := id.ToContainer()
if err != nil {
return nil, err
}
if variant.FS != nil {
containers = append(containers, variant)
services.Merge(variant.Services)
}
}
if len(containers) == 0 {
return nil, errors.New("no containers to export")
}
return WithServices(ctx, gw, services, func() (*bkgw.Result, error) {
if len(containers) == 1 {
exportContainer := containers[0]
st, err := exportContainer.FSState()
if err != nil {
return nil, err
}
stDef, err := st.Marshal(ctx, llb.Platform(exportContainer.Platform))
if err != nil {
return nil, err
}
res, err := gw.Solve(ctx, bkgw.SolveRequest{
Evaluate: true,
Definition: stDef.ToPB(), |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | })
if err != nil {
return nil, err
}
cfgBytes, err := json.Marshal(specs.Image{
Platform: specs.Platform{
Architecture: exportContainer.Platform.Architecture,
OS: exportContainer.Platform.OS,
OSVersion: exportContainer.Platform.OSVersion,
OSFeatures: exportContainer.Platform.OSFeatures,
},
Config: exportContainer.Config,
})
if err != nil {
return nil, err
}
res.AddMeta(exptypes.ExporterImageConfigKey, cfgBytes)
return res, nil
}
res := bkgw.NewResult()
expPlatforms := &exptypes.Platforms{
Platforms: make([]exptypes.Platform, len(containers)),
}
for i, exportContainer := range containers {
st, err := exportContainer.FSState()
if err != nil {
return nil, err
}
stDef, err := st.Marshal(ctx, llb.Platform(exportContainer.Platform))
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | return nil, err
}
r, err := gw.Solve(ctx, bkgw.SolveRequest{
Evaluate: true,
Definition: stDef.ToPB(),
})
if err != nil {
return nil, err
}
ref, err := r.SingleRef()
if err != nil {
return nil, err
}
platformKey := platforms.Format(exportContainer.Platform)
res.AddRef(platformKey, ref)
expPlatforms.Platforms[i] = exptypes.Platform{
ID: platformKey,
Platform: exportContainer.Platform,
}
cfgBytes, err := json.Marshal(specs.Image{
Platform: specs.Platform{
Architecture: exportContainer.Platform.Architecture,
OS: exportContainer.Platform.OS,
OSVersion: exportContainer.Platform.OSVersion,
OSFeatures: exportContainer.Platform.OSFeatures,
},
Config: exportContainer.Config,
})
if err != nil {
return nil, err |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | }
res.AddMeta(fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, platformKey), cfgBytes)
}
platformBytes, err := json.Marshal(expPlatforms)
if err != nil {
return nil, err
}
res.AddMeta(exptypes.ExporterPlatformsKey, platformBytes)
return res, nil
})
}
func (container *Container) ImageRefOrErr(ctx context.Context, gw bkgw.Client) (string, error) {
imgRef := container.ImageRef
if imgRef != "" {
return imgRef, nil
}
return "", errors.Errorf("Image reference can only be retrieved immediately after the 'Container.From' call. Error in fetching imageRef as the container image is changed")
}
func (container *Container) ownership(ctx context.Context, gw bkgw.Client, owner string) (*Ownership, error) {
if owner == "" {
return nil, nil
}
fsSt, err := container.FSState()
if err != nil {
return nil, err
}
return resolveUIDGID(ctx, fsSt, gw, container.Platform, owner)
}
type ContainerExecOpts struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | Args []string
SkipEntrypoint bool
Stdin string
RedirectStdout string
RedirectStderr string
ExperimentalPrivilegedNesting bool
InsecureRootCapabilities bool
}
type BuildArg struct {
Name string `json:"name"`
Value string `json:"value"`
}
func hostHash(val digest.Digest) string {
b, err := hex.DecodeString(val.Encoded())
if err != nil {
panic(err)
}
return b32(xxh3.Hash(b))
}
func b32(n uint64) string { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | var sum [8]byte
binary.BigEndian.PutUint64(sum[:], n)
return base32.HexEncoding.
WithPadding(base32.NoPadding).
EncodeToString(sum[:])
}
const ociTagAnnotation = "org.opencontainers.image.ref.name"
func resolveIndex(ctx context.Context, store content.Store, desc specs.Descriptor, platform specs.Platform, tag string) (*specs.Descriptor, error) {
if desc.MediaType != specs.MediaTypeImageIndex {
return nil, fmt.Errorf("expected index, got %s", desc.MediaType)
}
indexBlob, err := content.ReadBlob(ctx, store, desc)
if err != nil {
return nil, fmt.Errorf("read index blob: %w", err)
}
var idx specs.Index
err = json.Unmarshal(indexBlob, &idx)
if err != nil {
return nil, fmt.Errorf("unmarshal index: %w", err)
}
matcher := platforms.Only(platform)
for _, m := range idx.Manifests {
if m.Platform != nil {
if !matcher.Match(*m.Platform) {
continue
}
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/container.go | if tag != "" {
if m.Annotations == nil {
continue
}
manifestTag, found := m.Annotations[ociTagAnnotation]
if !found || manifestTag != tag {
continue
}
}
switch m.MediaType {
case specs.MediaTypeImageManifest,
images.MediaTypeDockerSchema2Manifest:
return &m, nil
case specs.MediaTypeImageIndex,
images.MediaTypeDockerSchema2ManifestList:
return resolveIndex(ctx, store, m, platform, tag)
default:
return nil, fmt.Errorf("expected manifest or index, got %s", m.MediaType)
}
}
return nil, fmt.Errorf("no manifest for platform %s and tag %s", platforms.Format(platform), tag)
}
type ImageLayerCompression string
const (
CompressionGzip ImageLayerCompression = "Gzip"
CompressionZstd ImageLayerCompression = "Zstd"
CompressionEStarGZ ImageLayerCompression = "EStarGZ"
CompressionUncompressed ImageLayerCompression = "Uncompressed"
) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | package core
import (
"bytes"
"context"
_ "embed"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"dagger.io/dagger"
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/core/schema"
"github.com/dagger/dagger/internal/testutil"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/moby/buildkit/identity"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/require"
)
func TestContainerScratch(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
ID string
Fs struct {
Entries []string
}
}
}{}
err := testutil.Query(
`{
container {
id
fs {
entries
}
}
}`, &res, nil)
require.NoError(t, err)
require.Empty(t, res.Container.Fs.Entries)
}
func TestContainerFrom(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
From struct {
Fs struct {
File struct {
Contents string
}
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
fs {
file(path: "/etc/alpine-release") {
contents
}
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.Fs.File.Contents, "3.16.2\n")
}
func TestContainerWith(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | t.Parallel()
ctx := context.Background()
c, err := dagger.Connect(ctx)
require.NoError(t, err)
defer c.Close()
foo := "bar"
alpine := c.Container().From("alpine:3.16.2").With(func(c *dagger.Container) *dagger.Container {
return c.WithEnvVariable("FOO", foo)
})
out, err := alpine.WithExec([]string{"printenv", "FOO"}).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "bar\n", out)
withFood := func(c *dagger.Container) *dagger.Container {
return c.WithEnvVariable("FOOD", "bar")
}
out, err = c.Container().From("alpine:3.16.2").
With(withFood).
WithExec([]string{"printenv", "FOOD"}).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "bar\n", out)
withEnv := func(env, val string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
return c.WithEnvVariable(env, val)
}
}
env := "HELLO" |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | val := "WORLD"
out, err = c.Container().From("alpine:3.16.2").
With(withEnv(env, val)).
WithExec([]string{"printenv", env}).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, val+"\n", out)
}
func TestContainerBuild(t *testing.T) {
ctx := context.Background()
c, err := dagger.Connect(ctx)
require.NoError(t, err)
defer c.Close()
contextDir := c.Directory().
WithNewFile("main.go",
`package main
import "fmt"
import "os"
func main() {
for _, env := range os.Environ() {
fmt.Println(env)
}
}`)
t.Run("default Dockerfile location", func(t *testing.T) {
src := contextDir.
WithNewFile("Dockerfile",
`FROM golang:1.18.2-alpine
WORKDIR /src
COPY main.go .
RUN go mod init hello |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | RUN go build -o /usr/bin/goenv main.go
ENV FOO=bar
CMD goenv
`)
env, err := c.Container().Build(src).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=bar\n")
})
t.Run("custom Dockerfile location", func(t *testing.T) {
src := contextDir.
WithNewFile("subdir/Dockerfile.whee",
`FROM golang:1.18.2-alpine
WORKDIR /src
COPY main.go .
RUN go mod init hello
RUN go build -o /usr/bin/goenv main.go
ENV FOO=bar
CMD goenv
`)
env, err := c.Container().Build(src, dagger.ContainerBuildOpts{
Dockerfile: "subdir/Dockerfile.whee",
}).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=bar\n")
})
t.Run("subdirectory with default Dockerfile location", func(t *testing.T) {
src := contextDir.
WithNewFile("Dockerfile",
`FROM golang:1.18.2-alpine
WORKDIR /src |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | COPY main.go .
RUN go mod init hello
RUN go build -o /usr/bin/goenv main.go
ENV FOO=bar
CMD goenv
`)
sub := c.Directory().WithDirectory("subcontext", src).Directory("subcontext")
env, err := c.Container().Build(sub).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=bar\n")
})
t.Run("subdirectory with custom Dockerfile location", func(t *testing.T) {
src := contextDir.
WithNewFile("subdir/Dockerfile.whee",
`FROM golang:1.18.2-alpine
WORKDIR /src
COPY main.go .
RUN go mod init hello
RUN go build -o /usr/bin/goenv main.go
ENV FOO=bar
CMD goenv
`)
sub := c.Directory().WithDirectory("subcontext", src).Directory("subcontext")
env, err := c.Container().Build(sub, dagger.ContainerBuildOpts{
Dockerfile: "subdir/Dockerfile.whee",
}).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=bar\n")
})
t.Run("with build args", func(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | src := contextDir.
WithNewFile("Dockerfile",
`FROM golang:1.18.2-alpine
ARG FOOARG=bar
WORKDIR /src
COPY main.go .
RUN go mod init hello
RUN go build -o /usr/bin/goenv main.go
ENV FOO=$FOOARG
CMD goenv
`)
env, err := c.Container().Build(src).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=bar\n")
env, err = c.Container().Build(src, dagger.ContainerBuildOpts{BuildArgs: []dagger.BuildArg{{Name: "FOOARG", Value: "barbar"}}}).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, env, "FOO=barbar\n")
})
t.Run("with target", func(t *testing.T) {
src := contextDir.
WithNewFile("Dockerfile",
`FROM golang:1.18.2-alpine AS base
CMD echo "base"
FROM base AS stage1
CMD echo "stage1"
FROM base AS stage2
CMD echo "stage2"
`)
output, err := c.Container().Build(src).Stdout(ctx)
require.NoError(t, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | require.Contains(t, output, "stage2\n")
output, err = c.Container().Build(src, dagger.ContainerBuildOpts{Target: "stage1"}).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, output, "stage1\n")
require.NotContains(t, output, "stage2\n")
})
t.Run("with build secrets", func(t *testing.T) {
sec := c.SetSecret("my-secret", "barbar")
require.NoError(t, err)
src := contextDir.
WithNewFile("Dockerfile",
`FROM golang:1.18.2-alpine
WORKDIR /src
RUN --mount=type=secret,id=my-secret test "$(cat /run/secrets/my-secret)" = "barbar"
RUN --mount=type=secret,id=my-secret cp /run/secrets/my-secret /secret
CMD cat /secret
`)
stdout, err := c.Container().Build(src, dagger.ContainerBuildOpts{
Secrets: []*dagger.Secret{sec},
}).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, stdout, "***")
})
t.Run("just build, don't execute", func(t *testing.T) {
src := contextDir.
WithNewFile("Dockerfile", "FROM alpine:3.16.2\nCMD false")
_, err = c.Container().Build(src).Sync(ctx)
require.NoError(t, err)
_, err = c.Container().Build(src).WithExec(nil).Sync(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | require.NotEmpty(t, err)
})
t.Run("just build, short-circuit", func(t *testing.T) {
src := contextDir.
WithNewFile("Dockerfile", "FROM alpine:3.16.2\nRUN false")
_, err = c.Container().Build(src).Sync(ctx)
require.NotEmpty(t, err)
})
}
func TestContainerWithRootFS(t *testing.T) {
t.Parallel()
ctx := context.Background()
c, err := dagger.Connect(ctx)
require.NoError(t, err)
defer c.Close()
alpine316 := c.Container().From("alpine:3.16.2")
alpine316ReleaseStr, err := alpine316.File("/etc/alpine-release").Contents(ctx)
require.NoError(t, err)
alpine316ReleaseStr = strings.TrimSpace(alpine316ReleaseStr)
dir := alpine316.Rootfs()
exitCode, err := c.Container().WithEnvVariable("ALPINE_RELEASE", alpine316ReleaseStr).WithRootfs(dir).WithExec([]string{
"/bin/sh",
"-c",
"test -f /etc/alpine-release && test \"$(head -n 1 /etc/alpine-release)\" = \"$ALPINE_RELEASE\"",
}).ExitCode(ctx)
require.NoError(t, err)
require.Equal(t, exitCode, 0)
alpine315 := c.Container().From("alpine:3.15.6")
varVal := "testing123"
alpine315WithVar := alpine315.WithEnvVariable("DAGGER_TEST", varVal) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | varValResp, err := alpine315WithVar.EnvVariable(ctx, "DAGGER_TEST")
require.NoError(t, err)
require.Equal(t, varVal, varValResp)
alpine315ReplacedFS := alpine315WithVar.WithRootfs(dir)
varValResp, err = alpine315ReplacedFS.EnvVariable(ctx, "DAGGER_TEST")
require.NoError(t, err)
require.Equal(t, varVal, varValResp)
releaseStr, err := alpine315ReplacedFS.File("/etc/alpine-release").Contents(ctx)
require.NoError(t, err)
require.Equal(t, "3.16.2\n", releaseStr)
}
var helloSrc string
func TestContainerWithRootFSSubdir(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
hello := c.Directory().WithNewFile("main.go", helloSrc).File("main.go")
ctr := c.Container().
From("golang:1.20.0-alpine").
WithMountedFile("/src/main.go", hello).
WithEnvVariable("CGO_ENABLED", "0").
WithExec([]string{"go", "build", "-o", "/out/hello", "/src/main.go"})
out, err := c.Container().
WithRootfs(ctr.Directory("/out")).
WithExec([]string{"/hello"}).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "Hello, world!\n", out)
}
func TestContainerExecSync(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | t.Parallel()
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(args: ["false"]) {
sync
}
}
}
}`, nil, nil)
require.Contains(t, err.Error(), `process "false" did not complete successfully`)
}
func TestContainerExecExitCode(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
From struct {
WithExec struct {
ExitCode *int
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(args: ["true"]) {
exitCode
}
}
}
}`, &res, nil) |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | require.NoError(t, err)
require.NotNil(t, res.Container.From.WithExec.ExitCode)
require.Equal(t, 0, *res.Container.From.WithExec.ExitCode)
/*
It's not currently possible to get a nonzero exit code back because
Buildkit raises an error.
We could perhaps have the shim mask the exit status and always exit 0, but
we would have to be careful not to let that happen in a big chained LLB
since it would prevent short-circuiting.
We could only do it when the user requests the exitCode, but then we would
actually need to run the command _again_ since we'd need some way to tell
the shim what to do.
Hmm...
err = testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(args: ["false"]) {
exitCode
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.WithExec.ExitCode, 1)
*/
}
func TestContainerExecStdoutStderr(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
From struct {
WithExec struct {
Stdout string
Stderr string
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(args: ["sh", "-c", "echo hello; echo goodbye >/dev/stderr"]) {
stdout
stderr
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.WithExec.Stdout, "hello\n")
require.Equal(t, res.Container.From.WithExec.Stderr, "goodbye\n")
}
func TestContainerExecStdin(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
From struct {
WithExec struct {
Stdout string
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(args: ["cat"], stdin: "hello") {
stdout
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.WithExec.Stdout, "hello")
}
func TestContainerExecRedirectStdoutStderr(t *testing.T) {
t.Parallel()
res := struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | Container struct {
From struct {
WithExec struct {
Out, Err struct {
Contents string
}
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withExec(
args: ["sh", "-c", "echo hello; echo goodbye >/dev/stderr"],
redirectStdout: "out",
redirectStderr: "err"
) {
out: file(path: "out") {
contents
}
err: file(path: "err") {
contents
}
}
}
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | }`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.WithExec.Out.Contents, "hello\n")
require.Equal(t, res.Container.From.WithExec.Err.Contents, "goodbye\n")
c, ctx := connect(t)
defer c.Close()
execWithMount := c.Container().From("alpine:3.16.2").
WithMountedDirectory("/mnt", c.Directory()).
WithExec([]string{"sh", "-c", "echo hello; echo goodbye >/dev/stderr"}, dagger.ContainerWithExecOpts{
RedirectStdout: "/mnt/out",
RedirectStderr: "/mnt/err",
})
stdout, err := execWithMount.File("/mnt/out").Contents(ctx)
require.NoError(t, err)
require.Equal(t, "hello\n", stdout)
stderr, err := execWithMount.File("/mnt/err").Contents(ctx)
require.NoError(t, err)
require.Equal(t, "goodbye\n", stderr)
_, err = execWithMount.Stdout(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "stdout: no such file or directory")
_, err = execWithMount.Stderr(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "stderr: no such file or directory")
}
func TestContainerExecWithWorkdir(t *testing.T) {
t.Parallel()
res := struct {
Container struct {
From struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | WithWorkdir struct {
WithExec struct {
Stdout string
}
}
}
}
}{}
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
withWorkdir(path: "/usr") {
withExec(args: ["pwd"]) {
stdout
}
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, res.Container.From.WithWorkdir.WithExec.Stdout, "/usr\n")
}
func TestContainerExecWithUser(t *testing.T) {
t.Parallel()
res := struct {
Container struct {
From struct {
User string
WithUser struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | User string
WithExec struct {
Stdout string
}
}
}
}
}{}
t.Run("user name", func(t *testing.T) {
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
user
withUser(name: "daemon") {
user
withExec(args: ["whoami"]) {
stdout
}
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, "", res.Container.From.User)
require.Equal(t, "daemon", res.Container.From.WithUser.User)
require.Equal(t, "daemon\n", res.Container.From.WithUser.WithExec.Stdout)
})
t.Run("user and group name", func(t *testing.T) {
err := testutil.Query( |
closed | dagger/dagger | https://github.com/dagger/dagger | 4,588 | DX: Container.From() and Container.Build() creates fresh container | Discord context: https://discord.com/channels/707636530424053791/1074736111131304057/1074747695765405696
Summary:
Container.From() and Container.Build() create a new container. Chaining this with `.client.Container()` instead of directly `client.From()`/`container.Build()`, or `client.ContainerFrom()`/`client.ContainerBuild()` introduces opportunity for potential footguns.
For example:
```js
const foo = await client
.container()
.withEnvVariable('BUST_CACHE', Math.random().toString())
.build(node)
.withExec(['node', '--version'])
.stdout();
```
The cache busting env variable will never actually make it to the engine since the environment is replaced (correct me if this is wrong) | https://github.com/dagger/dagger/issues/4588 | https://github.com/dagger/dagger/pull/5052 | f5f76fcbda4b772a54aecc43812bd03e51c0d62c | 7d8738d64889572fd5ac7d9930c2f16b4c3629d2 | 2023-02-13T18:00:22Z | go | 2023-05-19T18:05:02Z | core/integration/container_test.go | `{
container {
from(address: "alpine:3.16.2") {
user
withUser(name: "daemon:floppy") {
user
withExec(args: ["sh", "-c", "whoami; groups"]) {
stdout
}
}
}
}
}`, &res, nil)
require.NoError(t, err)
require.Equal(t, "", res.Container.From.User)
require.Equal(t, "daemon:floppy", res.Container.From.WithUser.User)
require.Equal(t, "daemon\nfloppy\n", res.Container.From.WithUser.WithExec.Stdout)
})
t.Run("user ID", func(t *testing.T) {
err := testutil.Query(
`{
container {
from(address: "alpine:3.16.2") {
user
withUser(name: "2") {
user
withExec(args: ["whoami"]) {
stdout
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.