From dcfef0dd333e7f5513c76956640a73cd403f27d6 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Fri, 20 Sep 2024 04:21:30 +0530 Subject: [PATCH] [base-ubuntu] - remove existing ubuntu user (#1170) * [base-ubuntu, dotnet] - del existing ubuntu user * few changes * few more changes miscellaneous * misc. changes * changes to kill process running on 1000 before assigning to vscode user * more change to assign 1000 to vscode * small change * changes as suggested ! * few changes for testing .. * small change * few changes.. * reverting dotnet changes.. * changes as suggested * chg * Update test.sh * changed test - check for ubuntu user after deletion added * changes as discussed in review comment * changes as required * changes suggested --- src/base-ubuntu/.devcontainer/Dockerfile | 9 +++++++++ src/base-ubuntu/.devcontainer/devcontainer.json | 2 ++ src/base-ubuntu/test-project/test.sh | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/base-ubuntu/.devcontainer/Dockerfile b/src/base-ubuntu/.devcontainer/Dockerfile index fe8aacbf4..a44bb2471 100644 --- a/src/base-ubuntu/.devcontainer/Dockerfile +++ b/src/base-ubuntu/.devcontainer/Dockerfile @@ -3,6 +3,15 @@ FROM buildpack-deps:${VARIANT}-curl LABEL dev.containers.features="common" +ARG VARIANT +RUN if [ "$VARIANT" = "noble" ]; then \ + if id "ubuntu" &>/dev/null; then \ + echo "Deleting user 'ubuntu' for $VARIANT" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user for $VARIANT"; \ + else \ + echo "User 'ubuntu' does not exist for $VARIANT"; \ + fi; \ + fi + # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends diff --git a/src/base-ubuntu/.devcontainer/devcontainer.json b/src/base-ubuntu/.devcontainer/devcontainer.json index 4a4d21a71..d6b7e7040 100644 --- a/src/base-ubuntu/.devcontainer/devcontainer.json +++ b/src/base-ubuntu/.devcontainer/devcontainer.json @@ -7,6 +7,8 @@ "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": "true", "username": "vscode", + "userUid": "1000", + "userGid": "1000", "upgradePackages": "true" }, "ghcr.io/devcontainers/features/git:1": { diff --git a/src/base-ubuntu/test-project/test.sh b/src/base-ubuntu/test-project/test.sh index bdb069077..545c48811 100755 --- a/src/base-ubuntu/test-project/test.sh +++ b/src/base-ubuntu/test-project/test.sh @@ -19,7 +19,21 @@ check "gitconfig-file-location" sh -c "ls /etc/gitconfig" check "gitconfig-contains-name" sh -c "cat /etc/gitconfig | grep 'name = devcontainers'" check "usr-local-etc-config-does-not-exist" test ! -f "/usr/local/etc/gitconfig" -check "uid" bash -c "id -u vscode | grep 1001" +check_ubuntu_user() { + if ! id -u ubuntu > /dev/null 2>&1; then + echo -e "✔️ User ubuntu does not exist." + else + echo -e "❌ User ubuntu exists." + exit 1; + fi +} + +if grep -q 'VERSION_CODENAME=noble' /etc/os-release; then + echo -e "\nThe base image is ubuntu:noble. Checking user Ubuntu.." + check "uid" "check_ubuntu_user" +else + echo -e "\nCannot check user Ubuntu. The base image is not ubuntu:noble." +fi # Report result reportResults