Skip to content

Commit e7f7d19

Browse files
authored
[common-utils] fix bug when user home is custom by base docker (#703)
* [common-utils] fix bug when user home is custom by base docker * bumped minor version * reduced conditions to improve readability
1 parent 9852ca8 commit e7f7d19

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.1.3",
3+
"version": "2.2.0",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",

src/common-utils/main.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ fi
407407

408408
if [ "${USERNAME}" = "root" ]; then
409409
user_home="/root"
410+
# Check if user already has a home directory other than /home/${USERNAME}
411+
elif [ "/home/${USERNAME}" != $( getent passwd $USERNAME | cut -d: -f6 ) ]; then
412+
user_home=$( getent passwd $USERNAME | cut -d: -f6 )
410413
else
411414
user_home="/home/${USERNAME}"
412415
if [ ! -d "${user_home}" ]; then
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "user is customUser" grep customUser <(whoami)
10+
check "home is /customHome" grep "/customHome" <(getent passwd customUser | cut -d: -f6)
11+
12+
# Report result
13+
reportResults
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM ubuntu:focal
2+
3+
RUN groupadd customUser -g 30000 && \
4+
useradd customUser -u 30000 -g 30000 --create-home --home-dir /customHome
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "user is customUser" grep customUser <(whoami)
10+
check "home is /home/customUser" grep "/home/customUser" <(getent passwd customUser | cut -d: -f6)
11+
12+
# Report result
13+
reportResults

test/common-utils/scenarios.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,21 @@
183183
"configureZshAsDefaultShell": true
184184
}
185185
}
186+
},
187+
"devcontainer-custom-home": {
188+
"build": {
189+
"dockerfile": "Dockerfile"
190+
},
191+
"remoteUser": "customUser",
192+
"features": {
193+
"common-utils": {}
194+
}
195+
},
196+
"devcontainer-custom-user-default-home": {
197+
"image": "mcr.microsoft.com/devcontainers/base:alpine",
198+
"remoteUser": "customUser",
199+
"features": {
200+
"common-utils": {}
201+
}
186202
}
187203
}

0 commit comments

Comments
 (0)