[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:
Pablo Ulloa 2023-09-27 15:45:29 -03:00 committed by GitHub
parent 9852ca8888
commit e7f7d194d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 1 deletions

View file

@ -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.",

View file

@ -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

View 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

View file

@ -0,0 +1,4 @@
FROM ubuntu:focal
RUN groupadd customUser -g 30000 && \
useradd customUser -u 30000 -g 30000 --create-home --home-dir /customHome

View 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

View file

@ -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": {}
}
} }
} }