`apko build` ignores `--workdir` flag
sfc-gh-ptabor opened this issue · comments
I spotted that 'apko build' is working outside of directory given using --workdir
flag.
I suspect this piece of code: https://github.com/chainguard-dev/apko/blame/1e5f9dbfd40406c0219c30ffa9ee34007814a438/internal/cli/build.go#L146
func BuildCmd(ctx context.Context, imageRef, outputTarGZ string, archs []types.Architecture, tags []string, wantSBOM bool, sbomPath string, logger log.Logger, opts ...build.Option) error {
wd, err := os.MkdirTemp("", "apko-*")
cmd.PersistentFlags().StringVarP(&workDir, "workdir", "C", cwd, "working dir (default is current dir where executed)")
@sfc-gh-ptabor can you define "working outside of directory"? What use case did you do that triggered a problem?
I would guess that this is a bug that's been around forever...
We try to Getwd
here:
Lines 28 to 32 in c68c72f
And then change to that dir here:
Lines 39 to 43 in c68c72f
But that just totally ignores the --workdir
flag.
At least for my usage, I tend to invoke apko
in a directory with a bunch of apko configs rather than in a directory where I want to populate a filesystem... I don't think we can "fix" this to use the current directory as the workdir because it would break so many existing things, but we could have the default value be a temporary directory (as it currently is now) and have the --workdir
flag let you set a specific directory.
Is that the behavior you'd expect?
Or do you want to os.Chdir
to the --workdir
before invoking apko
, but still build to a temporary directory?
I usually do as well, but sometimes you need to reference other dirs, especially in debug mode. Either way, it should work if it is there. Fixed in #830.