File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,17 @@ FROM mcr.microsoft.com/playwright:v1.56.1-noble
33ARG DEBIAN_FRONTEND=noninteractive
44ARG TZ=UTC
55
6+ # Add user args (defaults can be overridden via devcontainer.json build.args)
7+ ARG USERNAME=serenity-js
8+ ARG USER_UID=1000
9+ ARG USER_GID=1000
10+
611ENV SHELL=/bin/bash
712ENV PATH="/opt/google/chrome:${PATH}"
13+ ENV HOME=/home/${USERNAME}
814
915RUN \
10- # Install Java
16+ # Install Java, chrome, edge etc.
1117 apt-get -y update && \
1218 apt-get -y install default-jre && \
1319 # Install Chrome
2834 apt-get clean && \
2935 rm -rf /var/lib/apt/lists/*
3036
37+ # Create a non-root user to run the workspace (more secure than using root)
38+ RUN set -eux; \
39+ # create group (if it doesn't already exist) and user with specified uid/gid
40+ if ! getent group ${USER_GID} >/dev/null 2>&1; then \
41+ groupadd --gid ${USER_GID} ${USERNAME}; \
42+ fi; \
43+ if ! id -u ${USERNAME} >/dev/null 2>&1; then \
44+ useradd -m -s /bin/bash -u ${USER_UID} -g ${USER_GID} ${USERNAME}; \
45+ fi; \
46+ # Ensure /workspaces exists and is owned by the non-root user so postCreateCommand can write
47+ mkdir -p /workspaces; \
48+ chown -R ${USERNAME}:${USERNAME} /workspaces /home/${USERNAME}
49+
50+ # Copy welcome message for Codespaces/Dev Containers
3151COPY welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt
52+
53+ # Switch to the non-root user for the running container
54+ USER ${USERNAME}
55+ WORKDIR /workspaces
Original file line number Diff line number Diff line change 11{
22 "build" : {
33 "context" : " ." ,
4- "dockerfile" : " Dockerfile"
4+ "dockerfile" : " Dockerfile" ,
5+ "args" : {
6+ "USERNAME" : " serenity-js" ,
7+ "USER_UID" : " 1000" ,
8+ "USER_GID" : " 1000"
9+ }
510 },
611
712 "features" : {
4853 }
4954 }
5055 }
51- }
56+ },
57+
58+ "remoteUser" : " serenity-js"
5259}
You can’t perform that action at this time.
0 commit comments