I can make a working example, but hopefully this gets the idea across, as I was ironing out
- build base image for mkdocs
- if requirements file is found install from that
- if not install from string array then persist a new requirements file.
How am I supposed to get the output from the ctr.Stdout(ctx) and persist. I've tried freeze with inline shell redirect and even capturing the string of the output but neither seem to persist out the requirements file.... pointer on what I'm doing wrong?
// Container is the mkdocs container with thea dditional python packages to install
func InstallPipPackages(ctx context.Context, ctr *dagger.Container, packages []string, dir *Directory) *dagger.Container {
// support using requirements.txt to install, as can use for caching optimization.
// however, if you delete it or it doesn't exist, it will install the required packages and then provide a newly generated requirements file for you.
if _, err := os.Stat(qualifiedInternalRequirementsFile); os.IsNotExist(err) {
fmt.Println("requirements not found, so installing packages from code first exists")
for _, p := range packages {
ctr = ctr.WithExec([]string{"python", "-m", "pip", "install", p}, dagger.ContainerWithExecOpts{
SkipEntrypoint: true,
})
}
ctr = ctr.WithExec([]string{"python", "-m", "pip", "freeze", ">", qualifiedInternalRequirementsFile}, dagger.ContainerWithExecOpts{
SkipEntrypoint: true,
})
} else {
fmt.Println("requirements file exists")
ctr = ctr.WithExec([]string{"python", "-m", "pip", "install", "-r", qualifiedInternalRequirementsFile}, dagger.ContainerWithExecOpts{
SkipEntrypoint: true,
})
}
// for _, overlay := range overlays {
// ctr = ctr.WithDirectory("/", overlay.Rootfs())
// }
return ctr
}