#Can we retrieve logs from a Dockerfile build ?

1 messages · Page 1 of 1 (latest)

minor skiff
#

I tried implementing log retrieval the same way that with an exec, is there anyway to get stdout/stderr/exitcode of a docker build ?

Kind regards

    build, err := dag.Container().
        Build(source, dagger.ContainerBuildOpts{
            Dockerfile: "Dockerfile",
        }).Sync(ctx)
    ...
    stdout, err := build.Stdout(ctx)
    if err != nil {
        return "", "", 0, fmt.Errorf("failed to fetch stdout: %w", err)
    }
   stdout: input: container.build.stdout resolve: no command has been set: stdout requires an exec
quiet flare
short dagger
#

@quiet flare Did this ever get picked up? Hitting this error now

quiet flare
jovial nebula
#

there's no way i know of getting the logs of a docker build

#

getting build.Stdout will just get the result of the last exec in the build

#

actually, no it won't

#

it's expected, it gets the last withExec - there isn't a withExec

#

we need to do huge refactoring of how we support docker builds, supporting them as a native feature doesn't seem sustainable long term (since it's really tricky to implement features like this)

short dagger
#

What about logs of a withExec after a dockerBuild?

#

That's what I'm trying to do, and it still errors with stdout requires an exec, even though there is an exec

jovial nebula
#

can you share a code snippet?

quiet flare
short dagger
#

I was hoping to return a container and append stdout on the command, but I'll try that

quiet flare
jovial nebula
#

if you want it fully defined in the docker file, you could set the entry point?

#

then you can just WithExec with useEntrypoint=true

short dagger
#

Hmmm, that didn't work for me. Wrapping something else up then I'll retry

#

Function ends with:

    ctr.WithExec([]string{binary, "validate", fmt.Sprintf("--config=%s", configfile)})

    return ctr, nil
#

Command results in:

✘ .stdout: String! 0.0s
! no command has been set: stdout requires an exec
#

dagger -c 'validate ../otel-collector-sidecar --vars CLOUDWATCH_LOG_GROUP=testloggroup,CLOUDWATCH_LOG_STREAM=testlogstream | stdout' results in no command has been set: stdout requires an exec

quiet flare
#

so basically:

    ctr = ctr.WithExec([]string{binary, "validate", fmt.Sprintf("--config=%s", configfile)})

    return ctr, nil
short dagger
#

Ahhh 🤦‍♂️

#

Rookie errors huh