Skip to content

Commit dcfef0d

Browse files
[base-ubuntu] - remove existing ubuntu user (devcontainers#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
1 parent 1b3dfcc commit dcfef0d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/base-ubuntu/.devcontainer/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ FROM buildpack-deps:${VARIANT}-curl
33

44
LABEL dev.containers.features="common"
55

6+
ARG VARIANT
7+
RUN if [ "$VARIANT" = "noble" ]; then \
8+
if id "ubuntu" &>/dev/null; then \
9+
echo "Deleting user 'ubuntu' for $VARIANT" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user for $VARIANT"; \
10+
else \
11+
echo "User 'ubuntu' does not exist for $VARIANT"; \
12+
fi; \
13+
fi
14+
615
# [Optional] Uncomment this section to install additional OS packages.
716
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
817
# && apt-get -y install --no-install-recommends <your-package-list-here>

src/base-ubuntu/.devcontainer/devcontainer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"ghcr.io/devcontainers/features/common-utils:2": {
88
"installZsh": "true",
99
"username": "vscode",
10+
"userUid": "1000",
11+
"userGid": "1000",
1012
"upgradePackages": "true"
1113
},
1214
"ghcr.io/devcontainers/features/git:1": {

src/base-ubuntu/test-project/test.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ check "gitconfig-file-location" sh -c "ls /etc/gitconfig"
1919
check "gitconfig-contains-name" sh -c "cat /etc/gitconfig | grep 'name = devcontainers'"
2020
check "usr-local-etc-config-does-not-exist" test ! -f "/usr/local/etc/gitconfig"
2121

22-
check "uid" bash -c "id -u vscode | grep 1001"
22+
check_ubuntu_user() {
23+
if ! id -u ubuntu > /dev/null 2>&1; then
24+
echo -e "✔️ User ubuntu does not exist."
25+
else
26+
echo -e "❌ User ubuntu exists."
27+
exit 1;
28+
fi
29+
}
30+
31+
if grep -q 'VERSION_CODENAME=noble' /etc/os-release; then
32+
echo -e "\nThe base image is ubuntu:noble. Checking user Ubuntu.."
33+
check "uid" "check_ubuntu_user"
34+
else
35+
echo -e "\nCannot check user Ubuntu. The base image is not ubuntu:noble."
36+
fi
2337

2438
# Report result
2539
reportResults

0 commit comments

Comments
 (0)