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: add script to build Docker container on Windows #966

Merged
merged 2 commits into from
Apr 9, 2023

Conversation

cdcseacave
Copy link
Owner

@cdcseacave cdcseacave commented Apr 2, 2023

Repair latest changes to Docker build (#954) and restore functionality for Windows.

@cdcseacave
Copy link
Owner Author

cdcseacave commented Apr 2, 2023

@satyajitghana
@yanxke
This change enables executing the docker script on Windows too, but it still fails at the end, can you suggest a fix pls?

#7 636.6 -- Installing: /usr/local/bin/OpenMVS/InterfaceCOLMAP                                                                                                                                                     #7 636.6 -- Installing: /usr/local/bin/OpenMVS/InterfaceMetashape                                                                                                                                                  #7 636.6 -- Installing: /usr/local/bin/OpenMVS/InterfaceMVSNet                                                                                                                                                     #7 636.6 -- Installing: /usr/local/bin/OpenMVS/DensifyPointCloud                                                                                                                                                   #7 636.6 -- Installing: /usr/local/bin/OpenMVS/ReconstructMesh                                                                                                                                                     #7 636.6 -- Installing: /usr/local/bin/OpenMVS/RefineMesh                                                                                                                                                          #7 636.6 -- Installing: /usr/local/bin/OpenMVS/TextureMesh                                                                                                                                                         #7 636.6 -- Installing: /usr/local/bin/OpenMVS/TransformScene                                                                                                                                                      #7 636.6 -- Installing: /usr/local/bin/OpenMVS/Viewer                                                                                                                                                              #7 636.6 -- Installing: /usr/local/bin/OpenMVS/Tests                                                                                                                                                               #7 636.8 Setting permissions for user ared:ared                                                                                                                                                                    #7 636.8 adduser [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]                                                                                                                                        #7 636.8 [--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID]                                                                                                                               #7 636.8 [--disabled-password] [--disabled-login] [--add_extra_groups]                                                                                                                                             #7 636.8 [--encrypt-home] USER                                                                                                                                                                                     #7 636.8    Add a normal user                                                                                                                                                                                      #7 636.8                                                                                                                                                                                                           #7 636.8 adduser --system [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]                                                                                                                               #7 636.8 [--gecos GECOS] [--group | --ingroup GROUP | --gid ID] [--disabled-password]                                                                                                                              #7 636.8 [--disabled-login] [--add_extra_groups] USER                                                                                                                                                              #7 636.8    Add a system user                                                                                                                                                                                      #7 636.8                                                                                                                                                                                                           #7 636.8 adduser --group [--gid ID] GROUP                                                                                                                                                                          #7 636.8 addgroup [--gid ID] GROUP                                                                                                                                                                                 #7 636.8    Add a user group                                                                                                                                                                                       #7 636.8                                                                                                                                                                                                           #7 636.8 addgroup --system [--gid ID] GROUP                                                                                                                                                                        #7 636.8    Add a system group                                                                                                                                                                                     #7 636.8                                                                                                                                                                                                           #7 636.8 adduser USER GROUP                                                                                                                                                                                        #7 636.8    Add an existing user to an existing group                                                                                                                                                              #7 636.8                                                                                                                                                                                                           #7 636.8 general options:                                                                                                                                                                                          #7 636.8   --quiet | -q      don't give process information to stdout                                                                                                                                              #7 636.8   --force-badname   allow usernames which do not match the                                                                                                                                                #7 636.8                     NAME_REGEX[_SYSTEM] configuration variable                                                                                                                                            #7 636.8   --extrausers      uses extra users as the database                                                                                                                                                      #7 636.8   --help | -h       usage message                                                                                                                                                                         #7 636.8   --version | -v    version number and copyright                                                                                                                                                          #7 636.8   --conf | -c FILE  use FILE as configuration file                                                                                                                                                        #7 636.8                                                                                                                                                                                                           #7 636.8 Value "ared" invalid for option gid (number expected)                                                                                                                                                     ------                                                                                                                                                                                                             executor failed running [/bin/sh -c /tmp/buildInDocker.sh --cuda $CUDA --user_id $USER_ID --group_id $GROUP_ID --master $MASTER && rm /tmp/buildInDocker.sh]: exit code: 1                                                                                            

image

@satyajitghana
Copy link
Contributor

satyajitghana commented Apr 2, 2023

Seems like GROUP_ID and USER_ID are set to username in windows. It should have been numbers

How about this?

@echo off

set WORKSPACE=%CD%

set CUDA_BUILD_ARGS=
set CUDA_RUNTIME_ARGS=
set CUDA_CONTAINER_SUFFIX=
set MASTER_ARGS=
set DISPLAY_ARGS=

:parse_args
if "%~1" == "" goto build_image
if "%~1" == "--cuda" (
  set "CUDA_BUILD_ARGS=--build-arg CUDA=1 --build-arg BASE_IMAGE=nvidia/cuda:11.8.0-devel-ubuntu22.04"
  set "CUDA_RUNTIME_ARGS=--gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics"
  set "CUDA_CONTAINER_SUFFIX=-cuda"
  shift
  goto parse_args
)
if "%~1" == "--master" (
  set "MASTER_ARGS=--build-arg MASTER=1"
  shift
  goto parse_args
)
if "%~1" == "--workspace" (
  set "WORKSPACE=%~2"
  shift
  shift
  goto parse_args
)
echo Unknown argument: %~1
exit /b 1

:build_image
echo Running with workspace: %WORKSPACE%

for /f "tokens=1 delims=" %%a in ('id -u') do (
  set "USER_ID=%%a"
)
for /f "tokens=1 delims=" %%a in ('id -g') do (
  set "GROUP_ID=%%a"
)

docker build -t="openmvs-ubuntu%CUDA_CONTAINER_SUFFIX%" --build-arg "USER_ID=%USER_ID%" --build-arg "GROUP_ID=%GROUP_ID%" %CUDA_BUILD_ARGS% %MASTER_ARGS% .
if errorlevel 1 exit /b 1

set "XSOCK=\\.\pipe\X11-unix"
set "XAUTH=%TEMP%\docker.xauth"
docker run %CUDA_RUNTIME_ARGS% --entrypoint bash --ipc=host --shm-size=4gb -w /work -v "%WORKSPACE%:/work" -e "DISPLAY=%COMPUTERNAME%:0.0" -v "%XAUTH%:%XAUTH%:rw" -e "XAUTHORITY=%XAUTH%" -it openmvs-ubuntu%CUDA_CONTAINER_SUFFIX%

exit /b 0

this part takes care of the USER_ID and GROUP_ID

for /f "tokens=1 delims=" %%a in ('id -u') do (
  set "USER_ID=%%a"
)
for /f "tokens=1 delims=" %%a in ('id -g') do (
  set "GROUP_ID=%%a"
)

@cdcseacave
Copy link
Owner Author

it is building, but I do not think this will work, the user remains empty
as far as I know we do not have to set permision for windows docker, is there a way to disable setting them if the USER_ID is empty?
image

@cdcseacave
Copy link
Owner Author

cdcseacave commented Apr 2, 2023

indeed, removing setting user completed the build, but fails next creating the container, any suggestions?
image

image

@cdcseacave
Copy link
Owner Author

I found a solution how to run it, adding --user 1001 at the command line

@cdcseacave
Copy link
Owner Author

@satyajitghana pls review the fix I added for the user
pls also reconsider the GUI mode code, as something is not right there: one variable is set but not used, and the other is used 2 times in the same arg

@satyajitghana
Copy link
Contributor

the userid fix looks good. I don't think setting 1001 uid matter in windows host. i read somewhere that docker uses a samba share to mount folders into container.

as for the display, difficult for me to verify, haven't worked with windows docker GUI stuff. I doubt if the display would work without WSL2 (WSLg) on windows. Ref: https://github.com/microsoft/wslg/blob/main/samples/container/Containers.md

I think if you can get VcXsrv installed, and then just do export DISPLAY=localhost:0 it might work. assuming --net=host is set in docker run. Else you'll need the docker host IP address (must be a vnet listed in ipconfig). Ref: https://stackoverflow.com/questions/43508481/running-x-windows-desktop-apps-in-docker-containers-on-windows-10

@cdcseacave
Copy link
Owner Author

thank you, I'll merge it as is for now, and we fix the GUI with the next occasion

@cdcseacave cdcseacave merged commit 6d0e772 into develop Apr 9, 2023
@cdcseacave cdcseacave deleted the build_windows_docker branch April 9, 2023 23:35
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

Successfully merging this pull request may close these issues.

2 participants