Skip to content

Commit

Permalink
[base-ubuntu] - remove existing ubuntu user (#1170)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
gauravsaini04 authored Sep 19, 2024
1 parent 1b3dfcc commit dcfef0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/base-ubuntu/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your-package-list-here>
2 changes: 2 additions & 0 deletions src/base-ubuntu/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 15 additions & 1 deletion src/base-ubuntu/test-project/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dcfef0d

Please sign in to comment.