Skip to content

Commit 9fb3257

Browse files
committed
Improve ease of configuration for local UID/GIDs
1 parent 43a750d commit 9fb3257

File tree

3 files changed

+60
-27
lines changed

3 files changed

+60
-27
lines changed

docker-compose.override.example.yml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,54 @@
99
# ...and adjust services below as needed. The examples shown below are not
1010
# exhaustive.
1111
#
12+
# Some sections of this file facilitate alignment of users and groups when
13+
# mounting code as container volumes. These values first read from the UID
14+
# and GID environment variables if available and fall back to "501" as the
15+
# sensible default for MacOS contributors (the folks that will most likely
16+
# need to override user/group here). Linux users typically have a UID=1000
17+
# and GID=1000. Since these are image defaults, we do not need to override
18+
# these unless we're using a system where our account doesn't have UID/GID
19+
# of 1000.
20+
#
21+
# To assign the UID and GID environment variables automatically, run:
22+
#
23+
# export UID=$(id -u) GID=$(id -g)
24+
#
25+
# Add the above command to a profile script to avoid the need to run it in
26+
# every session. Some shells set these variables in the scope of the shell
27+
# process (not the environment). We still need to export the values to the
28+
# environment to access those here. For example, Bash sets UID, and we can
29+
# export it directly:
30+
#
31+
# export UID GID=$(id -g)
32+
#
33+
# Alternatively, add the UID and GID variables to your .env file.
34+
#
1235

1336
name: tdei-workspaces
1437

38+
x-node-dev-base:
39+
&node-dev-base
40+
# Build the container so that the runtime user matches the local user.
41+
build:
42+
args:
43+
APP_UID: ${UID:-501}
44+
APP_GID: ${GID:-501}
45+
# Run the container as your local user so that file permissions match.
46+
user: "${UID:-501}:${GID:-501}"
47+
1548
services:
1649
frontend:
17-
# Run the container as your local user so that file permissions match.
18-
#
19-
# The default UID for MacOS is typically 501. For Linux, this is typically
20-
# 1000. Run `id -u` to confirm.
21-
#
22-
user: 501
50+
<<: *node-dev-base
51+
52+
rapid:
53+
<<: *node-dev-base
54+
55+
pathways-editor:
56+
<<: *node-dev-base
2357

2458
tasks-backend:
25-
# Build the container as your local user so that file permissions match.
26-
#
27-
# The default UID for MacOS is typically 501. For Linux, this is typically
28-
# 1000. Run `id -u` to confirm.
29-
#
59+
# Build the container as your local user so that permissions match.
3060
build:
3161
args:
32-
APP_UID: 501
62+
APP_UID: ${UID:-501}

docker-compose.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ x-osm-rails-base:
2424
- osm-rails-tmp:/app/tmp
2525
- osm-rails-storage:/app/storage
2626

27+
x-node-dev-base:
28+
&node-dev-base
29+
build:
30+
context: node-dev
31+
working_dir: /app
32+
tty: true
33+
2734
################################################################################
2835

2936
services:
@@ -40,12 +47,8 @@ services:
4047
- --providers.docker.exposedbydefault=false
4148

4249
frontend:
43-
image: node:latest
44-
entrypoint: npm
50+
<<: *node-dev-base
4551
command: run dev
46-
user: node
47-
working_dir: /app
48-
tty: true
4952
environment:
5053
VITE_TDEI_API_URL: ${WS_TDEI_API_URL}
5154
VITE_TDEI_USER_API_URL: ${WS_TDEI_BACKEND_URL}
@@ -69,12 +72,8 @@ services:
6972
# the tasks-backend service below.
7073

7174
rapid:
72-
image: node:latest
73-
entrypoint: npm
75+
<<: *node-dev-base
7476
command: run start
75-
user: node
76-
working_dir: /app
77-
tty: true
7877
volumes:
7978
- ./rapid:/app
8079
labels:
@@ -88,12 +87,8 @@ services:
8887
- traefik.http.services.rapid.loadbalancer.server.port=8080
8988

9089
pathways-editor:
91-
image: node:latest
92-
entrypoint: npm
90+
<<: *node-dev-base
9391
command: run start
94-
user: node
95-
working_dir: /app
96-
tty: true
9792
volumes:
9893
- ./pathways-editor:/app
9994
labels:

node-dev/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:25.2
2+
3+
ARG APP_UID=1000
4+
ARG APP_GID=1000
5+
6+
RUN groupmod -g "$APP_UID" node && usermod -u "$APP_UID" -g "$APP_GID" node
7+
8+
ENTRYPOINT ["npm"]

0 commit comments

Comments
 (0)