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

build-ubuntu.sh Ignores CPU_CORES Environment Variable #1782

Open
c-ewing opened this issue Nov 21, 2024 · 1 comment
Open

build-ubuntu.sh Ignores CPU_CORES Environment Variable #1782

c-ewing opened this issue Nov 21, 2024 · 1 comment

Comments

@c-ewing
Copy link

c-ewing commented Nov 21, 2024

Description:

I encountered an issue while using the build-ubuntu.sh script to build Docker images. Despite the ${CPU_CORES} environment variable being set (via check-cpu.sh), CMake utilizes all available cores instead of respecting the specified number.

When check-cpu.sh is run independently, it correctly returns a value of 3. However, during the Docker build process, all cores are still used.

Is this the intended behavior?


Reproduction Steps:

  1. Run check-cpu.sh independently and observe that it returns the expected number of cores.
  2. Run build-ubuntu.sh and observe that CMake uses all available CPU cores instead of the value defined in ${CPU_CORES}.

Expected Behavior:

CMake should respect the ${CPU_CORES} value calculated by check-cpu.sh.


Relevant Code:
The issue appears to stem from the following lines:

COPY docker/check-cpu.sh ${AV_DEV}/docker/check-cpu.sh
RUN export CPU_CORES=`${AV_DEV}/docker/check-cpu.sh` && echo "Build multithreading number of cores: ${CPU_CORES}"


Proposed Fix:

To ensure the ${CPU_CORES} environment variable is properly calculated and used, I suggest rewriting the lines as:

RUN CPU_CORES=`${AV_DEV}/docker/check-cpu.sh` && \
    echo "Build multithreading number of cores: ${CPU_CORES}" && \
    echo "export CPU_CORES=${CPU_CORES}" >> /etc/profile.d/alicevision.sh

This change will:

  1. Execute the check-cpu.sh script to calculate the number of cores.
  2. Log the value of CPU_CORES for visibility.
  3. Persist the CPU_CORES variable if needed in later build steps by saving it to /etc/profile.d/cpu_cores.sh.

Next Steps:

If this is indeed an issue, I’m happy to submit a pull request with the proposed fix. If I am misunderstanding the intended behavior, please let me know, and I’ll close this report.

Thank you for your time and support!

Best regards,
cewing

@c-ewing
Copy link
Author

c-ewing commented Nov 22, 2024

Additional Issue: Environment Variables in /etc/profile.d/alicevision.sh Are Not Used in the Build Process

While investigating the original issue, I discovered that none of the environment variables written to /etc/profile.d/alicevision.sh are actually used during the build process.

The root cause is that Docker uses non-login shells for its RUN commands. As a result, the scripts in /etc/profile.d/ are not sourced during the build process. These scripts are only executed if the shell is a login shell, which is not the case for Docker’s default behavior.


Impact:

Environment variables written to /etc/profile.d/alicevision.sh are effectively ignored during Docker’s build steps and not availible in the future unless a login shell is specifically created.


Proposed Fix:
To ensure these environment variables are accessible during the build process, the relevant commands should be moved to use the ENV directive in the Dockerfile. For example:

ENV VAR_NAME=value

This approach guarantees that the environment variables are properly set and persist throughout the Docker build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant