[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
This commit is contained in:
parent
9852ca8888
commit
e7f7d194d6
6 changed files with 50 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"id": "common-utils",
|
"id": "common-utils",
|
||||||
"version": "2.1.3",
|
"version": "2.2.0",
|
||||||
"name": "Common Utilities",
|
"name": "Common Utilities",
|
||||||
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
|
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
|
||||||
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
|
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
|
||||||
|
|
|
@ -407,6 +407,9 @@ fi
|
||||||
|
|
||||||
if [ "${USERNAME}" = "root" ]; then
|
if [ "${USERNAME}" = "root" ]; then
|
||||||
user_home="/root"
|
user_home="/root"
|
||||||
|
# Check if user already has a home directory other than /home/${USERNAME}
|
||||||
|
elif [ "/home/${USERNAME}" != $( getent passwd $USERNAME | cut -d: -f6 ) ]; then
|
||||||
|
user_home=$( getent passwd $USERNAME | cut -d: -f6 )
|
||||||
else
|
else
|
||||||
user_home="/home/${USERNAME}"
|
user_home="/home/${USERNAME}"
|
||||||
if [ ! -d "${user_home}" ]; then
|
if [ ! -d "${user_home}" ]; then
|
||||||
|
|
13
test/common-utils/devcontainer-custom-home.sh
Normal file
13
test/common-utils/devcontainer-custom-home.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Optional: Import test library
|
||||||
|
source dev-container-features-test-lib
|
||||||
|
|
||||||
|
# Definition specific tests
|
||||||
|
check "user is customUser" grep customUser <(whoami)
|
||||||
|
check "home is /customHome" grep "/customHome" <(getent passwd customUser | cut -d: -f6)
|
||||||
|
|
||||||
|
# Report result
|
||||||
|
reportResults
|
4
test/common-utils/devcontainer-custom-home/Dockerfile
Normal file
4
test/common-utils/devcontainer-custom-home/Dockerfile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
FROM ubuntu:focal
|
||||||
|
|
||||||
|
RUN groupadd customUser -g 30000 && \
|
||||||
|
useradd customUser -u 30000 -g 30000 --create-home --home-dir /customHome
|
13
test/common-utils/devcontainer-custom-user-default-home.sh
Normal file
13
test/common-utils/devcontainer-custom-user-default-home.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Optional: Import test library
|
||||||
|
source dev-container-features-test-lib
|
||||||
|
|
||||||
|
# Definition specific tests
|
||||||
|
check "user is customUser" grep customUser <(whoami)
|
||||||
|
check "home is /home/customUser" grep "/home/customUser" <(getent passwd customUser | cut -d: -f6)
|
||||||
|
|
||||||
|
# Report result
|
||||||
|
reportResults
|
|
@ -183,5 +183,21 @@
|
||||||
"configureZshAsDefaultShell": true
|
"configureZshAsDefaultShell": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"devcontainer-custom-home": {
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "Dockerfile"
|
||||||
|
},
|
||||||
|
"remoteUser": "customUser",
|
||||||
|
"features": {
|
||||||
|
"common-utils": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"devcontainer-custom-user-default-home": {
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/base:alpine",
|
||||||
|
"remoteUser": "customUser",
|
||||||
|
"features": {
|
||||||
|
"common-utils": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue