@@ -22,93 +22,82 @@ update-ca-certificates
2222# *runs* as non-root user [scu]
2323#
2424echo " $INFO " " Entrypoint for stage ${SC_BUILD_TARGET} ..."
25- echo User :" $( id " $( whoami) " ) "
26- echo Workdir :" $( pwd) "
27- echo scuUser :" $( id scu) "
28-
29-
30- if [ " ${SC_BUILD_TARGET} " = " development" ]
31- then
32- echo " $INFO " " development mode detected..."
33- # NOTE: expects docker run ... -v $(pwd):/devel/services/dask-sidecar
34- DEVEL_MOUNT=" /devel/services/dask-sidecar"
35-
36- stat $DEVEL_MOUNT > /dev/null 2>&1 || \
37- (echo " $ERROR " " You must mount '$DEVEL_MOUNT ' to deduce user and group ids" && exit 1)
38-
39- echo " setting correct user id/group id..."
40- HOST_USERID=$( stat --format=%u " ${DEVEL_MOUNT} " )
41- HOST_GROUPID=$( stat --format=%g " ${DEVEL_MOUNT} " )
42- CONT_GROUPNAME=$( getent group " ${HOST_GROUPID} " | cut --delimiter=: --fields=1)
43- if [ " $HOST_USERID " -eq 0 ]
44- then
45- echo " Warning: Folder mounted owned by root user... adding $SC_USER_NAME to root..."
46- adduser " $SC_USER_NAME " root
25+ echo User :" $( id " $( whoami) " ) "
26+ echo Workdir :" $( pwd) "
27+ echo scuUser :" $( id scu) "
28+
29+ if [ " ${SC_BUILD_TARGET} " = " development" ]; then
30+ echo " $INFO " " development mode detected..."
31+ # NOTE: expects docker run ... -v $(pwd):/devel/services/dask-sidecar
32+ DEVEL_MOUNT=" /devel/services/dask-sidecar"
33+
34+ stat $DEVEL_MOUNT > /dev/null 2>&1 ||
35+ (echo " $ERROR " " You must mount '$DEVEL_MOUNT ' to deduce user and group ids" && exit 1)
36+
37+ echo " setting correct user id/group id..."
38+ HOST_USERID=$( stat --format=%u " ${DEVEL_MOUNT} " )
39+ HOST_GROUPID=$( stat --format=%g " ${DEVEL_MOUNT} " )
40+ CONT_GROUPNAME=$( getent group " ${HOST_GROUPID} " | cut --delimiter=: --fields=1)
41+ if [ " $HOST_USERID " -eq 0 ]; then
42+ echo " Warning: Folder mounted owned by root user... adding $SC_USER_NAME to root..."
43+ adduser " $SC_USER_NAME " root
44+ else
45+ echo " Folder mounted owned by user $HOST_USERID :$HOST_GROUPID -'$CONT_GROUPNAME '..."
46+ # take host's credentials in $SC_USER_NAME
47+ if [ -z " $CONT_GROUPNAME " ]; then
48+ echo " Creating new group my$SC_USER_NAME "
49+ CONT_GROUPNAME=my$SC_USER_NAME
50+ addgroup --gid " $HOST_GROUPID " " $CONT_GROUPNAME "
4751 else
48- echo " Folder mounted owned by user $HOST_USERID :$HOST_GROUPID -'$CONT_GROUPNAME '..."
49- # take host's credentials in $SC_USER_NAME
50- if [ -z " $CONT_GROUPNAME " ]
51- then
52- echo " Creating new group my$SC_USER_NAME "
53- CONT_GROUPNAME=my$SC_USER_NAME
54- addgroup --gid " $HOST_GROUPID " " $CONT_GROUPNAME "
55- else
56- echo " group already exists"
57- fi
58- echo " adding $SC_USER_NAME to group $CONT_GROUPNAME ..."
59- adduser " $SC_USER_NAME " " $CONT_GROUPNAME "
60-
61- echo " changing $SC_USER_NAME :$SC_USER_NAME ($SC_USER_ID :$SC_USER_ID ) to $SC_USER_NAME :$CONT_GROUPNAME ($HOST_USERID :$HOST_GROUPID )"
62- usermod --uid " $HOST_USERID " --gid " $HOST_GROUPID " " $SC_USER_NAME "
63-
64- echo " Changing group properties of files around from $SC_USER_ID to group $CONT_GROUPNAME "
65- find / -path /proc -prune -o -group " $SC_USER_ID " -exec chgrp --no-dereference " $CONT_GROUPNAME " {} \;
66- # change user property of files already around
67- echo " Changing ownership properties of files around from $SC_USER_ID to group $CONT_GROUPNAME "
68- find / -path /proc -prune -o -user " $SC_USER_ID " -exec chown --no-dereference " $SC_USER_NAME " {} \;
52+ echo " group already exists"
6953 fi
70- fi
54+ echo " adding $SC_USER_NAME to group $CONT_GROUPNAME ..."
55+ adduser " $SC_USER_NAME " " $CONT_GROUPNAME "
7156
57+ echo " changing $SC_USER_NAME :$SC_USER_NAME ($SC_USER_ID :$SC_USER_ID ) to $SC_USER_NAME :$CONT_GROUPNAME ($HOST_USERID :$HOST_GROUPID )"
58+ usermod --uid " $HOST_USERID " --gid " $HOST_GROUPID " " $SC_USER_NAME "
7259
73- if [ " ${SC_BOOT_MODE} " = " debug" ]
74- then
75- # NOTE: production does NOT pre-installs debugpy
76- pip install --no-cache-dir debugpy
60+ echo " Changing group properties of files around from $SC_USER_ID to group $CONT_GROUPNAME "
61+ find / -path /proc -prune -o -group " $SC_USER_ID " -exec chgrp --no-dereference " $CONT_GROUPNAME " {} \;
62+ # change user property of files already around
63+ echo " Changing ownership properties of files around from $SC_USER_ID to group $CONT_GROUPNAME "
64+ find / -path /proc -prune -o -user " $SC_USER_ID " -exec chown --no-dereference " $SC_USER_NAME " {} \;
65+ fi
7766fi
7867
68+ if [ " ${SC_BOOT_MODE} " = " debug" ]; then
69+ # NOTE: production does NOT pre-installs debugpy
70+ uv pip install --no-cache-dir debugpy
71+ fi
7972
8073if [ ${DASK_START_AS_SCHEDULER+x} ]; then
8174
8275 echo " $INFO Starting $* as SCHEDULER ..."
8376 echo " $SC_USER_NAME rights : $( id " $SC_USER_NAME " ) "
8477 echo " local dir : $( ls -al) "
8578
86-
8779else
8880
8981 # Appends docker group if socket is mounted
9082 DOCKER_MOUNT=/var/run/docker.sock
91- if stat $DOCKER_MOUNT > /dev/null 2>&1
92- then
93- echo " $INFO detected docker socket is mounted, adding user to group..."
94- GROUPID=$( stat --format=%g $DOCKER_MOUNT )
95- GROUPNAME=scdocker
96-
97- if ! addgroup --gid " $GROUPID " $GROUPNAME > /dev/null 2>&1
98- then
99- echo " $WARNING docker group with $GROUPID already exists, getting group name..."
100- # if group already exists in container, then reuse name
101- GROUPNAME=$( getent group " ${GROUPID} " | cut --delimiter=: --fields=1)
102- echo " $WARNING docker group with $GROUPID has name $GROUPNAME "
103- fi
104- adduser " $SC_USER_NAME " " $GROUPNAME "
83+ if stat $DOCKER_MOUNT > /dev/null 2>&1 ; then
84+ echo " $INFO detected docker socket is mounted, adding user to group..."
85+ GROUPID=$( stat --format=%g $DOCKER_MOUNT )
86+ GROUPNAME=scdocker
87+
88+ if ! addgroup --gid " $GROUPID " $GROUPNAME > /dev/null 2>&1 ; then
89+ echo " $WARNING docker group with $GROUPID already exists, getting group name..."
90+ # if group already exists in container, then reuse name
91+ GROUPNAME=$( getent group " ${GROUPID} " | cut --delimiter=: --fields=1)
92+ echo " $WARNING docker group with $GROUPID has name $GROUPNAME "
93+ fi
94+ adduser " $SC_USER_NAME " " $GROUPNAME "
10595 fi
10696
10797 echo " $INFO ensuring write rights on computational shared folder ..."
10898 mkdir --parents " ${SIDECAR_COMP_SERVICES_SHARED_FOLDER} "
10999 chown --recursive " $SC_USER_NAME " :" $GROUPNAME " " ${SIDECAR_COMP_SERVICES_SHARED_FOLDER} "
110100
111-
112101 echo " $INFO Starting $* as WORKER ..."
113102 echo " $SC_USER_NAME rights : $( id " $SC_USER_NAME " ) "
114103 echo " local dir : $( ls -al) "
0 commit comments