Skip to content

🐞 Duplicated output when publishing multistage builds #4605

Closed

Description

@kpenfound

What is the issue?

When you do a multistage build with dagger (build in one container and put the files in a secondary container) and publish that secondary container, the output from the build stage is duplicated. This duplication does not happen if there's only one container or if you do any execution other than publishing.

Log output

Single container build:

> _EXPERIMENTAL_DAGGER_JOURNAL="./singlebuild.log" go run main.go
#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.8s

#2
#2 DONE 0.0s

#3 from alpine
#3 resolve docker.io/library/alpine:latest
#3 resolve docker.io/library/alpine:latest 0.3s done
#3 CACHED

#2
#2 0.134 LOOK AT MEEEEEEEEEEEEEE now:1676410956 arch:aarch64 pid:15
#2 DONE 0.1s

Multistage build:

> _EXPERIMENTAL_DAGGER_JOURNAL="./multibuild.log" DO_REPRO=1 go run main.go
#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 1.7s

#2
#2 DONE 0.0s

#3 from alpine
#3 resolve docker.io/library/alpine:latest
#3 resolve docker.io/library/alpine:latest 0.2s done
#3 CACHED

#2
#2 0.119 LOOK AT MEEEEEEEEEEEEEE now:1676411000 arch:aarch64 pid:15
#2 0.119 LOOK AT MEEEEEEEEEEEEEE now:1676411000 arch:aarch64 pid:15
#2 DONE 0.1s

Steps to reproduce

Repro code in this gist: https://gist.github.com/kpenfound/0de9abd133344fb4e69f31255d5e96fa

Run go run main.go for a single container build, and DO_REPRO=1 go run main.go for a multistage build to see the duplicated output.

Here's the graph output:
singlebuild.log
singlebuild
multibuild.log
multibuild

SDK version

Go SDK v0.4.5

OS version

macOS arm64 12.6

Activity

  1. added
    kind/bug
    on Feb 14, 2023
  2. kpenfound commented on Feb 14, 2023

    @kpenfound
    ContributorAuthor
  3. morlay commented on Feb 15, 2023

    @morlay
    Contributor

    I got same issue, then I have define my custom logger base on
    https://github.com/dagger/dagger/blob/main/engine/engine.go#L201-L208

    with changes:

    shouldIgnore := false
    
    for _, v := range ev.Vertexes {
      if v.Started == nil && v.Completed == nil {
    	  shouldIgnore = true
    	  continue
    	  // ...
      }
    }
    
    if shouldIgnore {
       continue
    }
    
    cleanCh <- ev
  4. sipsma commented on Feb 21, 2023

    @sipsma
    Contributor

    I would suspect this is related to the fact that in order to export we have to open a whole new buildkit session right now. There's an upstream issue for fixing this: moby/buildkit#1914. There's also some stuff around sharing buildkit sessions that we could look into too.

    In the meantime, something along the lines of morlay's suggestion seams like a good approach to at least reduce the confusing output.

  5. gerhard commented on May 9, 2023

    @gerhard
    Contributor

    Based on your recent work on TUI, does this bug seem familiar to you @vito?

  6. vito commented on May 9, 2023

    @vito
    Contributor

    @gerhard Bug still exists, it just looks prettier.

    Tweaked the repro to use ubuntu to confirm we're getting repeated logs instead of repeated runs, and to use Export instead of Publish to avoid a registry push:

    func main() {
    	ctx := context.Background()
    	client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
    	if err != nil {
    		panic(err)
    	}
    	defer client.Close()
    
    	container1 := client.Container().
    		From("ubuntu").
    		WithEnvVariable("NOCACHE", time.Now().String()).
    		WithExec([]string{"sh", "-c", "echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof)"})
    	container2 := client.Container()
    	container2 = container2.WithDirectory("/", container1.Directory("/"))
    
    	pushContainer := container1
    	if os.Getenv("DO_REPRO") != "" {
    		pushContainer = container2
    	}
    
    	_, err = pushContainer.Export(ctx, "foo.tar")
    	if err != nil {
    		panic(err)
    	}
    }

    Output:

    ❯ env DO_REPRO=1 dagger run go run ./multistage-output/
    █ [1.14s] go run ./multistage-output/
    ┣─╮ 
    │ ▼ from ubuntu
    │ █ [0.28s] resolve image config for docker.io/library/ubuntu:latest
    │ █ [0.01s] pull docker.io/library/ubuntu:latest
    │ ┣ [0.01s] resolve docker.io/library/ubuntu@sha256:dfd64a3b4296d8c9b62aa3309984f8620b98d87e47492599ee20739e8eb54fbf
    │ ┣─╮ pull docker.io/library/ubuntu:latest
    │ ┻ │ 
    █◀──╯ [0.16s] exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof)
    ┣─╮ exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof)
    ┃ │ LOOK AT MEEEEEEEEEEEEEE now:1683654678164088830 arch:x86_64 pid:17                                                                      
    ┃ │ LOOK AT MEEEEEEEEEEEEEE now:1683654678164088830 arch:x86_64 pid:17                                                                      
    █◀╯ CACHED copy / /
    █ [0.14s] exporting to oci image format
    ┣ [0.00s] exporting layers
    ┣ [0.00s] exporting manifest sha256:daa31bfa409d23a8ec227223bbdc57852f586006add90381c97c9c30d9199b6a
    ┣ [0.00s] exporting config sha256:fe42b71ecf79288c72f387c6e5b34f106e5f1845d8b1932e4287fb2035240f76
    ┣ [0.12s] sending tarball
    ┻ 
    
  7. mircubed commented on Jun 27, 2023

    @mircubed
    Contributor

    @TomChv should we keep you assigned to this issue? Do you need any additional support? cc @gerhard

  8. TomChv commented on Jul 14, 2023

    @TomChv
    Member

    I opened a PR few weeks ago but it seems the issue is mostly on Buildkit side.
    I think you can remove my assignment from this

  9. vito commented on Jul 14, 2023

    @vito
    Contributor

    I bet this will be fixed by #5415

  10. TomChv commented on Jul 17, 2023

    @TomChv
    Member

    That would be amazing!

  11. sipsma commented on Aug 3, 2023

    @sipsma
    Contributor

    I bet this will be fixed by #5415

    Yes in all likelihood this should no longer be an issue in v0.8.0, though I will refrain from closing the issue until we've gotten confirmation it no longer repros

  12. TomChv commented on Aug 8, 2023

    @TomChv
    Member

    I can check with a repro and let you know!

  13. TomChv commented on Aug 9, 2023

    @TomChv
    Member

    I think this fix the issue, here's the output with the latest version, what do you think @sipsma ?

    go run ./test.go
    
    #...
    
    12: exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof)
    12: [0.05s] LOOK AT MEEEEEEEEEEEEEE now:1691542193 arch:aarch64 pid:17
    12: exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof) DONE
    DO_REPRO=1  go run ./test.go
    
    #...
    
    11: exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof)
    11: [0.08s] LOOK AT MEEEEEEEEEEEEEE now:1691542213 arch:aarch64 pid:16
    11: exec sh -c echo LOOK AT MEEEEEEEEEEEEEE now:$(date +%s%N) arch:$(uname -m) pid:$(pidof pidof) DONE
    
  14. TomChv commented on Aug 14, 2023

    @TomChv
    Member

    /cc @kpenfound @nipuna-perera reopen if you see this issue again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugkind/user-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions