refactor(devcontainer): streamline Dockerfile and update VS Code settings for Clang 12

This commit is contained in:
whaffman 2025-09-24 13:15:24 +00:00
parent 878fe4790a
commit 15d749eae9
2 changed files with 13 additions and 49 deletions

View File

@ -3,33 +3,15 @@ FROM ubuntu:22.04
# Set environment variables for non-interactive installation # Set environment variables for non-interactive installation
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# Install essential development tools # Install development tools in one layer
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
# Build essentials # Build essentials
build-essential \ build-essential \
# Add LLVM repository for specific Clang versions # Clang 12 toolchain
wget \
lsb-release \
software-properties-common \
gnupg \
&& rm -rf /var/lib/apt/lists/*
# Install development tools - Ubuntu 22.04 approach
RUN apt-get update && apt-get install -y \
# Build essentials
build-essential \
# Check what Clang versions are available and install Clang 12 if possible
software-properties-common \
wget \
gnupg \
&& apt-get update && \
# Install available Clang tools (Ubuntu 22.04 has clang-12 available)
apt-get install -y \
clang-12 \ clang-12 \
clang++-12 \ clang++-12 \
clang-format-12 \ clang-format-12 \
clang-tidy-12 \ clang-tidy-12 \
# clangd and lldb may have different versioning
clangd \ clangd \
lldb \ lldb \
# Build tools # Build tools
@ -56,13 +38,13 @@ RUN apt-get update && apt-get install -y \
# Clean up # Clean up
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Create symbolic links to make clang-12 the default # Set up Clang 12 alternatives
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 \ RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 \
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 \ && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 \
&& update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 100 \ && update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 100 \
&& update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100 && update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100
# Create a non-root user for development # Create non-root user
RUN groupadd --gid 1000 vscode \ RUN groupadd --gid 1000 vscode \
&& useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \ && useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \
&& apt-get update \ && apt-get update \
@ -71,7 +53,7 @@ RUN groupadd --gid 1000 vscode \
&& chmod 0440 /etc/sudoers.d/vscode \ && chmod 0440 /etc/sudoers.d/vscode \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Set clang-12 as the default compiler # Set environment variables
ENV CC=clang-12 ENV CC=clang-12
ENV CXX=clang++-12 ENV CXX=clang++-12

View File

@ -20,12 +20,12 @@
// Container-specific VS Code settings // Container-specific VS Code settings
"settings": { "settings": {
"C_Cpp.default.compilerPath": "/usr/bin/clang++", "C_Cpp.default.compilerPath": "/usr/bin/clang++-12",
"C_Cpp.default.cStandard": "c17", "C_Cpp.default.cStandard": "c17",
"C_Cpp.default.cppStandard": "c++20", "C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.intelliSenseMode": "linux-clang-x64", "C_Cpp.default.intelliSenseMode": "linux-clang-x64",
"cmake.configureOnOpen": false, "cmake.configureOnOpen": false,
"clang-format.executable": "/usr/bin/clang-format", "clang-format.executable": "/usr/bin/clang-format-12",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"[cpp]": { "[cpp]": {
"editor.defaultFormatter": "xaver.clang-format" "editor.defaultFormatter": "xaver.clang-format"
@ -36,27 +36,15 @@
"files.associations": { "files.associations": {
"*.hpp": "cpp", "*.hpp": "cpp",
"*.tpp": "cpp" "*.tpp": "cpp"
},
"vscode" : {
"settings" : {
"remote.SSH.forwardAgent": true
} }
} }
}
} }
}, },
// Container configuration // Container configuration
"workspaceFolder": "/workspace", // "workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
// Development user setup
"remoteUser": "vscode", "remoteUser": "vscode",
// Container lifecycle hooks
"postCreateCommand": "echo 'Container ready for C++ development!'",
// Port forwarding for web server testing // Port forwarding for web server testing
"forwardPorts": [8080, 3000], "forwardPorts": [8080, 3000],
"portsAttributes": { "portsAttributes": {
@ -70,18 +58,12 @@
} }
}, },
// Container features // Additional dev container features (SSH agent removed)
"features": { "features": {
"ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {}
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest",
"forwardPorts": [22]
}
}, },
// Mount points for better performance // Simple post-create setup
"mounts": [ "postCreateCommand": "echo 'Dev container ready! Use GitHub CLI (gh auth login) or configure Git with HTTPS for GitHub access.'"
"source=webserv-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
]
} }