nanovms / ops

ops - build and run nanos unikernels
https://ops.city
MIT License
1.27k stars 132 forks source link

The cwd variable does not take effect #1632

Closed leeyiding closed 2 months ago

leeyiding commented 3 months ago

Sometimes the main file of a python program does not have to be placed in the root directory, but organizes all the code files into one directory, so the path to the working directory needs to be modified, but I found that the cwd variable does not take effect.

I made a minimal replica code here. tree

.
├── config.json
└── program
    └── main.py

2 directories, 2 files

config.json

{
    "Dirs": [
        "program"
    ],
    "Args":[
        "/program/main.py"
    ],
    "ManifestPassthrough": {
        "cwd": "/program"
    }
}

main.py

import os

current_directory = os.getcwd()
print(current_directory)

run ops pkg load eyberg/python:3.10.6 -c config.json

warning: overwriting existing file /program/main.py hostpath old: program/main.py new: /root/nanos/test-cwd//program/main.py
running local instance
booting /root/.ops/images/python3.10 ...
en1: assigned 10.0.2.15
/

You can see that the program output '/' instead of '/program' as I expected. I don't know if the cwd variable is not effective or if my configuration or understanding is wrong.

francescolavra commented 2 months ago

@leeyiding thanks for your report. This issue in the Nanos kernel is fixed by https://github.com/nanovms/nanos/pull/2036. You can use the fixed kernel by adding --nanos-version ee1681d to your Ops command line.

leeyiding commented 2 months ago

Thank you very much. After testing, it worked.