8000 chore: convert withFile to dagop by alexcb · Pull Request #10569 · dagger/dagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: convert withFile to dagop #10569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ func main() { //nolint:gocyclo
logLevel = config.LevelDebug
}
}
fmt.Printf("ACB setting trace log\n")
logLevel = config.LevelExtraDebug

if logLevel != "" {
slogLevel, err := logLevel.ToSlogLevel()
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions core/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func (container *Container) WithDirectory(ctx context.Context, subdir string, sr
})
}

func (container *Container) WithFile(ctx context.Context, destPath string, src *File, permissions *int, owner string) (*Container, error) {
func (container *Container) WithFile(ctx context.Context, srv *dagql.Server, destPath string, src *File, permissions *int, owner string) (*Container, error) {
container = container.Clone()

dir, file := filepath.Split(filepath.Clean(destPath))
Expand All @@ -669,17 +669,18 @@ func (container *Container) WithFile(ctx context.Context, destPath string, src *
return nil, err
}

return dir.WithFile(ctx, file, src, permissions, ownership)
return dir.WithFile(ctx, srv, file, src, permissions, ownership)
})
}

func (container *Container) WithoutPaths(ctx context.Context, destPaths ...string) (*Container, error) {
func (container *Container) WithoutPaths(ctx context.Context, srv *dagql.Server, destPaths ...string) (*Container, error) {
container = container.Clone()
fmt.Printf("ACB WithoutPaths %v\n", destPaths)

for _, destPath := range destPaths {
var err error
container, err = container.writeToPath(ctx, path.Dir(destPath), func(dir *Directory) (*Directory, error) {
return dir.Without(ctx, path.Base(destPath))
return dir.Without(ctx, srv, path.Base(destPath))
})
if err != nil {
return nil, err
Expand All @@ -688,7 +689,7 @@ func (container *Container) WithoutPaths(ctx context.Context, destPaths ...strin
return container, nil
}

func (container *Container) WithFiles(ctx context.Context, destDir string, src []*File, permissions *int, owner string) (*Container, error) {
func (container *Container) WithFiles(ctx context.Context, srv *dagql.Server, destDir string, src []*File, permissions *int, owner string) (*Container, error) {
container = container.Clone()

dir, file := filepath.Split(filepath.Clean(destDir))
Expand All @@ -698,7 +699,7 @@ func (container *Container) WithFiles(ctx context.Context, destDir string, src [
return nil, err
}

return dir.WithFiles(ctx, file, src, permissions, ownership)
return dir.WithFiles(ctx, srv, file, src, permissions, ownership)
})
}

Expand Down Expand Up @@ -1215,6 +1216,12 @@ func (container *Container) writeToPath(ctx context.Context, subdir string, fn f
return nil, err
}

if mount == nil {
dir.Result = container.FSResult
} else {
dir.Result = mount.Result
}

dir, err = fn(dir)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1695,6 +1702,7 @@ func (container *Container) WithoutExposedPort(port int, protocol NetworkProtoco

func (container *Container) WithServiceBinding(ctx context.Context, svc dagql.Instance[*Service], alias string) (*Container, error) {
container = container.Clone()
fmt.Printf("ACB WithServiceBinding\n")

host, err := svc.Self.Hostname(ctx, svc.ID())
if err != nil {
Expand All @@ -1714,6 +1722,7 @@ func (container *Container) WithServiceBinding(ctx context.Context, svc dagql.In
},
})

fmt.Printf("ACB WithServiceBinding returning\n")
return container, nil
}

Expand Down
9 changes: 6 additions & 3 deletions core/dagop.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func NewContainerDagOp(
id *call.ID,
ctr *Container,
extraInputs []llb.State,
skipMeta bool,
) (*Container, error) {
mounts, inputs, outputCount, err := getAllContainerMounts(ctr)
if err != nil {
Expand Down Expand Up @@ -338,7 +339,7 @@ func NewContainerDagOp(
}

ctr = ctr.Clone()
err = dagop.setAllContainerMounts(ctx, ctr, sts)
err = dagop.setAllContainerMounts(ctx, ctr, sts, skipMeta)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -598,7 +599,7 @@ func getAllContainerMounts(container *Container) (mounts []*pb.Mount, states []l

// setAllContainerMounts is the reverse of getAllContainerMounts, and rewrites
// the container mounts to the given states.
func (op *ContainerDagOp) setAllContainerMounts(ctx context.Context, container *Container, outputs []llb.State) error {
func (op *ContainerDagOp) setAllContainerMounts(ctx context.Context, container *Container, outputs []llb.State, skipMeta bool) error {
for mountIdx, mount := range op.Mounts {
if mount.Output == pb.SkipOutput {
continue
Expand All @@ -613,7 +614,9 @@ func (op *ContainerDagOp) setAllContainerMounts(ctx context.Context, container *
case 0:
container.FS = def.ToPB()
case 1:
container.Meta = def.ToPB()
if !skipMeta {
container.Meta = def.ToPB()
}
default:
container.Mounts[mountIdx-2].Source = def.ToPB()
}
Expand Down
Loading
Loading
0