Skip to content

Commit bba7fa3

Browse files
committed
compose: fix permissions on build dir and venv
Fix issue with mixed root/user permissions. Summary of new/working state: - source directory is copied in the Dockerfile with root permissions to allow synchronisation using watch feature of docker compose. - each robot service has its own build dir (/src/build/${ROBOT_ID}) to prevent override to parallel startup. - "uv sync" command is executed with root permission because it creates bindings (__init__.pyi) in the source directory. - "uv run" commands are executed with user permissions because tools are using shared memory files in "/dev/shm" mounted from the host. - to avoid permission denied errors due to recompilation, "uv run" is launched with "--no-sync" option. - "/src/.venv" bound to venv_cache volume so monitor service can reuse the venv created by robot service. Signed-off-by: Eric Courtois <eric.courtois@gmail.com>
1 parent a471b6b commit bba7fa3

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ RUN group_exists=$(getent group ${GID} || true) && echo $group_exists \
6464

6565
ADD .python-version uv.lock pyproject.toml CMakeLists.txt LICENSE /src/
6666
ADD cogip /src/cogip
67-
RUN uv sync
6867

6968
CMD ["sleep", "infinity"]
7069

docker-compose.yml

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ x-volumes-common: &volumes-common
1313
- *vol-dev
1414
- *vol-vscode
1515
- "build_cache:/src/build"
16+
- "venv_cache:/src/.venv"
1617
- "./assets:/src/assets"
1718
- "/tmp/.X11-unix/:/tmp/.X11-unix/"
1819
- "$XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR"
@@ -143,14 +144,13 @@ x-robot: &robot
143144
- -x
144145
- -c
145146
- |
146-
USERNAME=`getent passwd $${UID} | cut -d: -f1` || exit 1
147-
uv sync --reinstall-package cogip-tools -C build-dir=/src/build/$${ROBOT_ID}
148-
su $${USERNAME} -c "uv run cogip-server" &
147+
uv sync -C build-dir=/src/build/$${ROBOT_ID} --link-mode=copy --reinstall-package cogip-tools
148+
gosu $${UID}:$${GID} uv run --no-sync cogip-server &
149149
wait-for-it -t 0 localhost:809$${ROBOT_ID}
150-
su $${USERNAME} -c "uv run cogip-planner" &
151-
su $${USERNAME} -c "uv run cogip-copilot -b 500000 -B 1000000" &
152-
su $${USERNAME} -c "uv run cogip-detector" &
153-
su $${USERNAME} -c "uv run cogip-dashboard" &
150+
gosu $${UID}:$${GID} uv run --no-sync cogip-planner &
151+
gosu $${UID}:$${GID} uv run --no-sync cogip-copilot -b 500000 -B 1000000 &
152+
gosu $${UID}:$${GID} uv run --no-sync cogip-detector &
153+
gosu $${UID}:$${GID} uv run --no-sync cogip-dashboard &
154154
sleep infinity
155155
stop_signal: SIGKILL
156156

@@ -169,8 +169,8 @@ x-monitor: &monitor
169169
- -x
170170
- -c
171171
- |
172-
wait-for-it -t 0 $${COGIP_SOCKETIO_SERVER_HOST}:$${COGIP_SOCKETIO_SERVER_PORT}
173-
gosu $${UID}:$${GID} uv run cogip-monitor http://$${COGIP_SOCKETIO_SERVER_HOST}:$${COGIP_SOCKETIO_SERVER_PORT} &
172+
wait-for-it -t 0 localhost:809$${ROBOT_ID}
173+
gosu $${UID}:$${GID} uv run --no-sync cogip-monitor http://localhost:809$${ROBOT_ID} &
174174
sleep infinity
175175
working_dir: /src
176176
stop_signal: SIGKILL
@@ -350,9 +350,7 @@ services:
350350
hostname: monitor1
351351
environment:
352352
<< : *env-monitor
353-
COGIP_SOCKETIO_SERVER_HOST: robot1
354-
COGIP_SOCKETIO_SERVER_PORT: 8091
355-
COGIP_SOCKETIO_SERVER_URL: http://robot1:8091
353+
ROBOT_ID: 1
356354
depends_on:
357355
- robot1
358356
profiles:
@@ -363,9 +361,7 @@ services:
363361
hostname: monitor2
364362
environment:
365363
<< : *env-monitor
366-
COGIP_SOCKETIO_SERVER_HOST: robot2
367-
COGIP_SOCKETIO_SERVER_PORT: 8092
368-
COGIP_SOCKETIO_SERVER_URL: http://robot2:8092
364+
ROBOT_ID: 2
369365
depends_on:
370366
- robot2
371367
profiles:
@@ -376,9 +372,7 @@ services:
376372
hostname: monitor2
377373
environment:
378374
<< : *env-monitor
379-
COGIP_SOCKETIO_SERVER_HOST: robot3
380-
COGIP_SOCKETIO_SERVER_PORT: 8093
381-
COGIP_SOCKETIO_SERVER_URL: http://robot3:8093
375+
ROBOT_ID: 3
382376
depends_on:
383377
- robot3
384378
profiles:
@@ -389,9 +383,7 @@ services:
389383
hostname: monitor4
390384
environment:
391385
<< : *env-monitor
392-
COGIP_SOCKETIO_SERVER_HOST: robot4
393-
COGIP_SOCKETIO_SERVER_PORT: 8094
394-
COGIP_SOCKETIO_SERVER_URL: http://robot4:8094
386+
ROBOT_ID: 4
395387
depends_on:
396388
- robot4
397389
profiles:
@@ -402,9 +394,7 @@ services:
402394
hostname: monitor5
403395
environment:
404396
<< : *env-monitor
405-
COGIP_SOCKETIO_SERVER_HOST: robot5
406-
COGIP_SOCKETIO_SERVER_PORT: 8095
407-
COGIP_SOCKETIO_SERVER_URL: http://robot5:8095
397+
ROBOT_ID: 5
408398
depends_on:
409399
- robot5
410400
profiles:
@@ -433,11 +423,12 @@ services:
433423
- "./dist:/src/dist"
434424
- "./LICENSE:/src/LICENSE"
435425
- "./.gitignore:/src/.gitignore"
436-
- "build_cache:/src/build/wheel"
426+
- "build_cache:/src/build"
437427
profiles:
438428
- build_wheel
439429

440430
volumes:
441431
vscode:
442432
run:
443433
build_cache:
434+
venv_cache:

0 commit comments

Comments
 (0)