Skip to content
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

Have option to specify output directory path #2036

Open
razvand opened this issue Dec 31, 2024 · 2 comments
Open

Have option to specify output directory path #2036

razvand opened this issue Dec 31, 2024 · 2 comments
Labels
kind/enhancement New feature or request

Comments

@razvand
Copy link
Contributor

razvand commented Dec 31, 2024

Feature request summary

Currently, when running kraft build, you can configure the path to the Kraftfile by using the -K option to kraft. You can configure the path to the root filesystem by using the --rootfs option to kraft.

For the output directory path (the one storing the output directory .unikraft/), we use the last argument to kraft (if that is not present, the current directory is used). The issue is that that last argument is also used as the base directory for paths inside a Dockerfile passed as an argument, e.g. the use of COPY path/to/local/file path/in/container inside a Dockerfile. So currently we don't have an option of using a directory for Dockerfile input files and a separate one for the output directory .unikraft.

It would be useful to have an option such as --output / -o to specify the output directory.

Describe alternatives

No response

Related architectures

None

Related platforms

None

Additional context

We can use a command such as this to specify paths for the root filesystem / Dockerfile and for the Kraftfile:

kraft build --plat qemu --arch x86_64 --rootfs ../Dockerfile -K ./Kraftfile ..

But we don't have an option for the output directory.

@razvand razvand added the kind/enhancement New feature or request label Dec 31, 2024
@bishnushah0909
Copy link

To fix this, you'll need to add an additional option, --output (or -o), that allows users to explicitly define the output directory. This would make it easier to keep the build artifacts (.unikraft) separate from the Dockerfile's file references.

Step-by-Step Plan:
Introduce --output / -o Option:

1)Add a new --output or -o flag to the kraft build command. This option will specify the directory where the .unikraft output files should go.
2)Modify Input Path Handling:

If the --output option is provided, it should be used solely for the .unikraft output directory.
The last positional argument will still be used to define the base directory for Dockerfile paths, unless --output is provided.
Ensure Compatibility with Dockerfile Paths:

When parsing the Dockerfile, treat the directory where the Dockerfile resides as the base directory for any relative paths (e.g., COPY).

3)Ensure that paths inside the Dockerfile are relative to the directory specified by the --rootfs argument, but output is placed in the directory defined by --output.
Update the Build Process:

4)Ensure that both the output path for .unikraft and the Dockerfile's input paths are correctly handled without any conflicts.
Example Usage
With the new --output option, the kraft build command would look like this:

kraft build --rootfs ./Dockerfile -K ./Kraftfile -o /path/to/output .

In this example:

--rootfs ./Dockerfile: Path to the Dockerfile or root filesystem.
-K ./Kraftfile: Path to the Kraftfile.
-o /path/to/output: Directory where .unikraft output files will be stored.
The last . argument still defines the base directory for Dockerfile input files.
Implementation:
Here’s how you could modify the kraft build command to handle the new --output option:

1)Add --output Option to Command Line Parsing:
Modify the command-line argument parser to accept the --output option:

var outputDir string
flag.StringVar(&outputDir, "output", ".", "Directory where the output .unikraft files should be placed")

2)Update File Path Handling Logic:
Ensure that the outputDir is handled separately from the Dockerfile paths. For example, when handling the Dockerfile, ensure relative paths are resolved based on the --rootfs argument.

if outputDir != "" {
// Use the specified output directory for .unikraft
// Ensure paths for Dockerfile are not mixed with the output directory
} else {
// Default behavior: current directory used
outputDir = "./.unikraft"
}

3)Modify Dockerfile Path Handling:
Ensure the Dockerfile paths are based on the directory where the Dockerfile resides (or --rootfs), while the output paths are handled separately.

// Handling Dockerfile paths
dockerfileDir := filepath.Dir(dockerfilePath) // Directory where Dockerfile is located

4)Final Build Logic: Ensure that the build logic respects both the Dockerfile’s input paths and the output directory:
// Proceed with build
buildOptions := BuildOptions{
RootfsPath: rootfsPath,
KraftfilePath: kraftfilePath,
OutputDir: outputDir,
}

// Now, the build function should use the OutputDir separately
build(buildOptions)

output;
With this approach:

You can now specify a separate output directory for the .unikraft files without affecting the base paths inside the Dockerfile.
The Dockerfile can still reference files from its base directory or any other directory without interfering with the output location for build artifacts.

@razvand
Copy link
Contributor Author

razvand commented Jan 4, 2025

Thanks, @bishnushah0909 , for the input. I'll let @craciunoiuc and @nderjung comment here, as they have a better view of the source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants