|
1 | | -# Use the official Go 1.24.5 image based on Debian Bookworm as the base |
| 1 | +# Go base image (Debian Bookworm) |
2 | 2 | FROM golang:1.24.5-bookworm |
3 | 3 |
|
4 | | -# Update package lists and install system dependencies: |
5 | | -# - Reinstall ca-certificates to ensure SSL works |
6 | | -# - Install sudo for privilege escalation |
7 | | -# - Install software-properties-common for repo management |
8 | | -# - Install git for source control |
| 4 | +# Install common dev dependencies |
9 | 5 | RUN apt-get update && \ |
10 | | - apt-get -y install --reinstall ca-certificates && \ |
11 | | - apt-get -y install sudo \ |
12 | | - software-properties-common \ |
| 6 | + apt-get -y install --no-install-recommends \ |
| 7 | + sudo \ |
13 | 8 | git \ |
14 | | - make |
| 9 | + make && \ |
| 10 | + rm -rf /var/lib/apt/lists/* |
15 | 11 |
|
16 | | -# Set environment variables for the new non-root user |
17 | | -ENV USER_NAME vscode |
18 | | -ENV USER_PASSWORD password |
| 12 | +# Create non-root vscode user with sudo |
| 13 | +RUN useradd -ms /bin/bash vscode && \ |
| 14 | + echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode |
19 | 15 |
|
20 | | -# Create a new user with bash as the shell, disabled password initially |
21 | | -RUN adduser --quiet --disabled-password --shell /bin/bash --home /home/$USER_NAME --gecos "User" $USER_NAME |
| 16 | +# Fix Go build cache permissions |
| 17 | +RUN mkdir -p /home/vscode/.cache/go-build && \ |
| 18 | + chown -R vscode:vscode /home/vscode/.cache |
22 | 19 |
|
23 | | -# Set password for the new user and add them to the sudo group |
24 | | -RUN echo "${USER_NAME}:${USER_PASSWORD}" | chpasswd && usermod -aG sudo $USER_NAME |
25 | | - |
26 | | -# Configure passwordless sudo for the new user |
27 | | -RUN echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME && chmod 0440 /etc/sudoers.d/$USER_NAME |
28 | | - |
29 | | -# Set HOME env variable for the new user |
30 | | -ENV HOME /home/$USER_NAME |
31 | | - |
32 | | -# Switch to the non-root user |
33 | | -USER $USER_NAME |
34 | | - |
35 | | -# Set working directory to the user's home directory |
36 | | -WORKDIR /home/$USER_NAME |
| 20 | +# Switch to vscode user |
| 21 | +USER vscode |
| 22 | +WORKDIR /workspaces |
0 commit comments