If I do this:
import * as dagger from '@dagger.io/dagger';
dagger.connect(
async (client) => {
const assets = client.host().directory('.', {
include: ['foo.txt'],
});
await client
.container()
.from('node:16-slim')
.withWorkdir('/root/foo')
.withEntrypoint(['/bin/sh', '-c'])
.withMountedDirectory('.', assets)
.withExec('mkdir -p ./foo/bar')
.withExec('touch ./foo/bar/file.txt')
.export('./foo.tar.gz');
},
{
LogOutput: process.stdout,
Workdir: '.',
}
);
And load the docker image, the file.txt asset generated within the Dagger pipeline does not exist.
But if I do this:
import * as dagger from '@dagger.io/dagger';
dagger.connect(
async (client) => {
const assets = client.host().directory('.', {
include: ['foo.txt'],
});
await client
.container()
.from('node:16-slim')
.withWorkdir('/root/foo')
.withEntrypoint(['/bin/sh', '-c'])
.withDirectory('.', assets)
.withExec('mkdir -p ./foo/bar')
.withExec('touch ./foo/bar/file.txt')
.export('./foo.tar.gz');
},
{
LogOutput: process.stdout,
Workdir: '.',
}
);
The file.txt exists.
I understand the differences between withDirectory and withMountedDirectory, but it makes no sense to me that what I choose to add after the mount, which in this case happens to be in the same root directory, would also wipe the assets that I made within the pipeline. The behaviour should be that it only removes the assets that were originally mounted.
[In terms of why I think this is bad: this cost me a couple of hours of my time to figure out why my final image was missing assets in a complex pipeline.]