I am playing a bit with Dagger to understand how it works. The following three functions respectively create, modify and delete a file called message.txt:
func (m *DaggerDraft) Create(ctx context.Context, projectDir *Directory) *Container {
return dag.Container().
From("alpine:3.19").
WithDirectory("/project", projectDir).
WithWorkdir("/project").
WithExec([]string{"/bin/sh", "-c", "echo hello > message.txt"})
}
func (m *DaggerDraft) Modify(ctx context.Context, projectDir *Directory) *Container {
return dag.Container().
From("alpine:3.19").
WithDirectory("/project", projectDir).
WithWorkdir("/project").
WithExec([]string{"/bin/sh", "-c", "echo HELLO > message.txt"})
}
func (m *DaggerDraft) Delete(ctx context.Context, projectDir *Directory) *Container {
return dag.Container().
From("alpine:3.19").
WithDirectory("/project", projectDir).
WithWorkdir("/project").
WithExec([]string{"/bin/sh", "-c", "rm message.txt"})
}
If I call Dagger like below, it will create message.txt on the host, modify it on the host but not delete it on the host. Why is that?
# dagger version: dagger v0.10.2 (registry.dagger.io/engine) darwin/amd64
dagger call create --project-dir . directory --path . export --path .
dagger call modify --project-dir . directory --path . export --path .
dagger call delete --project-dir . directory --path . export --path .
Ultimately, I want to be able to run a container that removes and regenerates a directory on the host filesystem.