Added devcontainer setup (devcontainer.json, docker-compose.yml, postCreateCommand.sh) (#18541)

* Added devcontainer setup (devcontainer.json, docker-compose.yml, postCreateCommand.sh)

* Restructure devcontainers with browser-gui, native-gui variants and shared config

* Rename postCreateCommand.sh to kebab-case

* Updated dev container name to appear under the `bitwarden_common` docker compose stack

* Exclude .devcontainer from Checkmarx KICS scans

* Add sca and containers filters for Checkmarx

* Remove sca and containers filters from Checkmarx config

* Revert "Remove sca and containers filters from Checkmarx config"

This reverts commit 4eb4c0c124.

* Mask node_modules and Rust target from host sync in devcontainer

* Fix ownership of anonymous volume mount points in devcontainer

* Build desktop native module in devcontainer post-create script

* Fix Checkmarx config filters to use glob pattern for .devcontainer

* Revert "Fix Checkmarx config filters to use glob pattern for .devcontainer"

This reverts commit ab1c70fcf6.

---------

Co-authored-by: Amy Galles <9685081+AmyLGalles@users.noreply.github.com>
This commit is contained in:
Conner Turnbull
2026-04-08 15:58:05 -04:00
committed by GitHub
parent 79039c5417
commit c017802c92
10 changed files with 237 additions and 0 deletions

View File

@@ -10,3 +10,9 @@ checkmarx:
presetName: "BW ASA Premium"
# Exclude spec files, and test specific files
filter: "!*.spec.ts,!**/spec/**,!apps/desktop/native-messaging-test-runner/**"
kics:
filter: "!.devcontainer"
sca:
filter: "!.devcontainer"
containers:
filter: "!.devcontainer"

View File

@@ -0,0 +1,31 @@
{
"name": "Bitwarden Clients (macOS / GitHub Codespaces)",
"dockerComposeFile": "../common/docker-compose.yml",
"service": "bitwarden_clients",
"workspaceFolder": "/workspace",
"features": {
"ghcr.io/devcontainers/features/rust:1": {},
"ghcr.io/devcontainers/features/desktop-lite:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"angular.ng-template",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"nrwl.angular-console",
"bradlc.vscode-tailwindcss"
]
}
},
"postCreateCommand": "bash .devcontainer/common/post-create-command.sh",
"forwardPorts": [8080, 8081, 6006, 6080],
"portsAttributes": {
"default": { "onAutoForward": "ignore" },
"8080": { "label": "Web Vault", "onAutoForward": "notify" },
"8081": { "label": "Web Vault (Self-hosted)", "onAutoForward": "notify" },
"6006": { "label": "Storybook", "onAutoForward": "notify" },
"6080": { "label": "Desktop (noVNC)", "onAutoForward": "ignore" }
}
}

View File

@@ -0,0 +1,11 @@
# Devcontainer setup configuration
# Copy to .env and modify as needed
# Install Rust nightly toolchain and cargo tools for desktop native module
SETUP_DESKTOP_NATIVE=yes
# Install mkcert and generate SSL certificates for localhost (needed for WebAuthn)
SETUP_MKCERT=yes
# Run npm ci to install dependencies
RUN_NPM_CI=yes

View File

@@ -0,0 +1,11 @@
name: bitwarden_common
services:
bitwarden_clients:
image: mcr.microsoft.com/devcontainers/typescript-node:22
volumes:
- ../../:/workspace:cached
- /workspace/node_modules
- /workspace/apps/desktop/desktop_native/target
shm_size: "1gb"
command: sleep infinity

View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
echo "Running post-create-command.sh"
# Load configuration (use .env.example as fallback for defaults)
if [ -f ".devcontainer/common/.env" ]; then
source .devcontainer/common/.env
else
source .devcontainer/common/.env.example
fi
# Configure git safe directory
git config --global --add safe.directory /workspace
echo "Installing system dependencies..."
# Packages needed:
# libnss3-tools: mkcert certificate installation
# build-essential, pkg-config: native module compilation
# libsecret-1-dev, libglib2.0-dev: desktop native module dependencies
# Remaining packages: Electron runtime dependencies
sudo apt-get update && sudo apt-get install -y \
libnss3-tools \
build-essential \
pkg-config \
libsecret-1-dev \
libglib2.0-dev \
libdbus-1-3 \
libgtk-3-0 \
libnss3 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libx11-xcb1 \
libxcb-dri3-0 \
libxtst6 \
libxss1 \
libasound2 \
libgbm1
if [ "$SETUP_MKCERT" = "yes" ]; then
# Install mkcert for SSL certificates (needed for WebAuthn)
echo "Installing mkcert..."
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo mv mkcert-v*-linux-amd64 /usr/local/bin/mkcert
# Generate SSL certificates for localhost
echo "Generating SSL certificates..."
mkcert -install
cd /workspace/apps/web
mkcert -cert-file dev-server.local.pem -key-file dev-server.local.pem localhost bitwarden.test
cd /workspace
fi
# Fix ownership of anonymous volume mount points (created as root by Docker)
sudo chown node:node /workspace/node_modules /workspace/apps/desktop/desktop_native/target
if [ "$RUN_NPM_CI" = "yes" ]; then
# Install npm dependencies
echo "Running npm ci..."
npm ci
fi
if [ "$SETUP_DESKTOP_NATIVE" = "yes" ]; then
# Install Rust nightly toolchain (required for desktop native module)
echo "Installing Rust nightly toolchain..."
rustup toolchain install nightly
# Install cargo tools for pre-commit hooks (optional but recommended)
echo "Installing cargo tools for pre-commit hooks..."
cargo install cargo-sort cargo-udeps cargo-deny
# Build the desktop native module
echo "Building desktop native module..."
cd /workspace/apps/desktop/desktop_native/napi
npm run build
cd /workspace
fi
echo "post-create-command.sh completed"

View File

@@ -0,0 +1,29 @@
{
"name": "Bitwarden Clients (macOS XQuartz)",
"dockerComposeFile": ["../common/docker-compose.yml", "docker-compose.override.yml"],
"service": "bitwarden_clients",
"workspaceFolder": "/workspace",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"angular.ng-template",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"nrwl.angular-console",
"bradlc.vscode-tailwindcss"
]
}
},
"postCreateCommand": "bash .devcontainer/common/post-create-command.sh",
"forwardPorts": [8080, 8081, 6006],
"portsAttributes": {
"default": { "onAutoForward": "ignore" },
"8080": { "label": "Web Vault", "onAutoForward": "notify" },
"8081": { "label": "Web Vault (Self-hosted)", "onAutoForward": "notify" },
"6006": { "label": "Storybook", "onAutoForward": "notify" }
}
}

View File

@@ -0,0 +1,4 @@
services:
bitwarden_clients:
environment:
- DISPLAY=host.docker.internal:0

View File

@@ -0,0 +1,30 @@
{
"name": "Bitwarden Clients (Windows / Linux)",
"dockerComposeFile": ["../common/docker-compose.yml", "docker-compose.override.yml"],
"service": "bitwarden_clients",
"workspaceFolder": "/workspace",
"initializeCommand": "bash .devcontainer/native-gui/setup-x11.sh",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"angular.ng-template",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"nrwl.angular-console",
"bradlc.vscode-tailwindcss"
]
}
},
"postCreateCommand": "bash .devcontainer/common/post-create-command.sh",
"forwardPorts": [8080, 8081, 6006],
"portsAttributes": {
"default": { "onAutoForward": "ignore" },
"8080": { "label": "Web Vault", "onAutoForward": "notify" },
"8081": { "label": "Web Vault (Self-hosted)", "onAutoForward": "notify" },
"6006": { "label": "Storybook", "onAutoForward": "notify" }
}
}

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Generates docker-compose.override.yml for X11 forwarding
# Detects Windows (WSL2) vs native Linux
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OVERRIDE_FILE="$SCRIPT_DIR/docker-compose.override.yml"
if grep -qi microsoft /proc/version 2>/dev/null; then
echo "Detected Windows (WSL2) - configuring WSLg..."
cat > "$OVERRIDE_FILE" << 'EOF'
services:
bitwarden_clients:
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- /mnt/wslg:/mnt/wslg
environment:
- DISPLAY=${DISPLAY:-:0}
- WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-wayland-0}
- XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/mnt/wslg/runtime-dir}
- PULSE_SERVER=${PULSE_SERVER:-/mnt/wslg/PulseServer}
EOF
else
echo "Detected Linux - configuring X11..."
cat > "$OVERRIDE_FILE" << 'EOF'
services:
bitwarden_clients:
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=${DISPLAY:-:0}
EOF
fi

4
.gitignore vendored
View File

@@ -56,3 +56,7 @@ apps/**/config/local.json
# Nx
.nx
# DevContainer generated files
.devcontainer/native-gui/docker-compose.override.yml
.devcontainer/common/.env