Skip to content

Commit 82b3624

Browse files
authored
Dockerize devtools frontend (#39)
## Pull Request Overview This PR adds Docker support for the Chrome DevTools frontend, enabling containerized deployment of the development tools with Nginx serving the built assets. Key changes: - Adds multi-stage Docker build configuration with Ubuntu build stage and lightweight Nginx production stage - Implements Docker Compose setup for easy container management with health checks and networking - Provides comprehensive documentation with usage examples and troubleshooting guide
1 parent 92c1eb5 commit 82b3624

File tree

5 files changed

+422
-0
lines changed

5 files changed

+422
-0
lines changed

docker/.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Git files (not needed for build)
2+
.git/
3+
4+
# Build outputs (will be regenerated during Docker build)
5+
out/
6+
7+
# Large Chrome binaries (not needed for build)
8+
third_party/chrome/
9+
10+
# Node modules (will be installed fresh during build)
11+
node_modules/
12+
**/node_modules/
13+
14+
# IDE and temp files
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
*~
20+
.DS_Store
21+
22+
# Log files
23+
*.log
24+
logs/
25+
chrome_logs*.txt
26+
27+
# Local development files
28+
.env
29+
.env.local
30+
test-server.pid
31+
32+
# Docker files themselves (prevent recursion)
33+
docker/
34+
Dockerfile
35+
docker-compose.yml
36+
.dockerignore

docker/Dockerfile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Multi-stage build for Chrome DevTools Frontend
2+
# Stage 1: Builder - Use x86-64 for build compatibility
3+
FROM --platform=linux/amd64 ubuntu:22.04 AS builder
4+
5+
# Install required packages for the build
6+
RUN apt-get update && apt-get install -y \
7+
curl \
8+
git \
9+
python3 \
10+
python3-pip \
11+
python-is-python3 \
12+
wget \
13+
unzip \
14+
lsb-release \
15+
sudo \
16+
ca-certificates \
17+
gnupg \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Install Node.js 18.x (LTS)
21+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
22+
apt-get install -y nodejs && \
23+
rm -rf /var/lib/apt/lists/*
24+
25+
# Set up working directory
26+
WORKDIR /workspace
27+
28+
# Copy the entire repository
29+
COPY . .
30+
31+
# Clone depot_tools if not exists and add to PATH
32+
RUN if [ ! -d "third_party/depot_tools" ]; then \
33+
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git third_party/depot_tools; \
34+
fi
35+
36+
# Set PATH to include depot_tools
37+
ENV PATH="/workspace/third_party/depot_tools:${PATH}"
38+
39+
# Set environment variables to bypass CIPD issues
40+
ENV VPYTHON_BYPASS="manually managed python not supported by chrome operations"
41+
ENV DEPOT_TOOLS_UPDATE=0
42+
43+
# Download Node.js binary for the expected path (x86-64)
44+
RUN mkdir -p third_party/node/linux && \
45+
cd third_party/node/linux && \
46+
wget -q https://nodejs.org/dist/v18.20.0/node-v18.20.0-linux-x64.tar.xz && \
47+
tar -xf node-v18.20.0-linux-x64.tar.xz && \
48+
mv node-v18.20.0-linux-x64 node-linux-x64 && \
49+
rm -rf node-v18.20.0-linux-x64.tar.xz
50+
51+
# Download correct ninja binary for x86-64
52+
RUN rm -rf third_party/ninja && \
53+
mkdir -p third_party/ninja && \
54+
wget -O /tmp/ninja.zip https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip && \
55+
unzip -o /tmp/ninja.zip -d third_party/ninja/ && \
56+
chmod +x third_party/ninja/ninja && \
57+
rm /tmp/ninja.zip
58+
59+
# Create a simple python3 wrapper for vpython3
60+
RUN echo '#!/bin/bash\nexec python3 "$@"' > /usr/local/bin/vpython3 && \
61+
chmod +x /usr/local/bin/vpython3
62+
63+
# Run npm install and build
64+
RUN npm install && \
65+
npm run build
66+
67+
# Stage 2: Production
68+
FROM nginx:alpine
69+
70+
# Copy only the built frontend files from builder stage
71+
COPY --from=builder /workspace/out/Default/gen/front_end /usr/share/nginx/html
72+
73+
# Copy nginx configuration
74+
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
75+
76+
# Expose port 8000 to match the original Python server port
77+
EXPOSE 8000
78+
79+
# Health check
80+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
81+
CMD wget --no-verbose --tries=1 --spider http://localhost:8000/ || exit 1
82+
83+
# Start nginx
84+
CMD ["nginx", "-g", "daemon off;"]

docker/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Docker Setup for Chrome DevTools Frontend
2+
3+
This directory contains Docker configuration files for building and running the Chrome DevTools Frontend in a containerized environment.
4+
5+
## Overview
6+
7+
The Docker setup uses a multi-stage build process:
8+
1. **Build Stage**: Compiles the DevTools frontend using the full development environment
9+
2. **Production Stage**: Serves only the built files using Nginx (lightweight, ~50MB final image)
10+
11+
## Prerequisites
12+
13+
- Docker Engine 20.10+ installed
14+
- Docker Compose v2.0+ (optional, for easier management)
15+
- At least 8GB of available disk space for the build process
16+
- 4GB+ RAM recommended for building
17+
18+
## Quick Start
19+
20+
### Building the Docker Image
21+
22+
From the repository root directory:
23+
24+
```bash
25+
# Build the Docker image
26+
docker build -f docker/Dockerfile -t devtools-frontend .
27+
28+
# Or use docker-compose (recommended)
29+
docker-compose -f docker/docker-compose.yml build
30+
```
31+
32+
### Running the Container
33+
34+
```bash
35+
# Using docker run
36+
docker run -d -p 8000:8000 --name devtools-frontend devtools-frontend
37+
38+
# Or using docker-compose (recommended)
39+
docker-compose -f docker/docker-compose.yml up -d
40+
```
41+
42+
The DevTools will be available at: http://localhost:8000
43+
44+
### Accessing DevTools
45+
46+
Once the container is running, open Chrome or Chromium with:
47+
48+
```bash
49+
# macOS
50+
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --custom-devtools-frontend=http://localhost:8000/
51+
52+
# Linux
53+
google-chrome --custom-devtools-frontend=http://localhost:8000/
54+
55+
# Windows
56+
chrome.exe --custom-devtools-frontend=http://localhost:8000/
57+
```
58+
59+
## File Structure
60+
61+
```
62+
docker/
63+
├── Dockerfile # Multi-stage build configuration
64+
├── .dockerignore # Files to exclude from Docker context
65+
├── nginx.conf # Nginx server configuration
66+
├── docker-compose.yml # Docker Compose configuration
67+
└── README.md # This file
68+
```
69+
70+
## Advanced Usage
71+
72+
### Development Mode
73+
74+
For development with local file changes:
75+
76+
1. Build the project locally first:
77+
```bash
78+
npm run build
79+
```
80+
81+
2. Run the container with volume mount:
82+
```bash
83+
docker run -d -p 8000:8000 \
84+
-v $(pwd)/out/Default/gen/front_end:/usr/share/nginx/html:ro \
85+
--name devtools-frontend-dev \
86+
devtools-frontend
87+
```
88+
89+
Or uncomment the volume mount in `docker-compose.yml`.
90+
91+
### Custom Port
92+
93+
To run on a different port:
94+
95+
```bash
96+
# Using docker run
97+
docker run -d -p 9000:8000 devtools-frontend
98+
99+
# Using docker-compose
100+
DEVTOOLS_PORT=9000 docker-compose -f docker/docker-compose.yml up -d
101+
```
102+
103+
Then update your Chrome launch command accordingly.
104+
105+
### Building with Cache
106+
107+
To speed up rebuilds, Docker automatically caches layers. To force a fresh build:
108+
109+
```bash
110+
docker build -f docker/Dockerfile --no-cache -t devtools-frontend .
111+
```
112+
113+
### Viewing Logs
114+
115+
```bash
116+
# Using docker
117+
docker logs devtools-frontend
118+
119+
# Using docker-compose
120+
docker-compose -f docker/docker-compose.yml logs -f
121+
```
122+
123+
### Stopping the Container
124+
125+
```bash
126+
# Using docker
127+
docker stop devtools-frontend
128+
docker rm devtools-frontend
129+
130+
# Using docker-compose
131+
docker-compose -f docker/docker-compose.yml down
132+
```
133+
134+
## Troubleshooting
135+
136+
### Build Fails
137+
138+
If the build fails:
139+
1. Ensure you have enough disk space (8GB+ free)
140+
2. Check Docker memory limits (4GB+ recommended)
141+
3. Try building with `--no-cache` flag
142+
4. Check the build logs for specific errors
143+
144+
### Container Won't Start
145+
146+
1. Check if port 8000 is already in use:
147+
```bash
148+
lsof -i :8000 # macOS/Linux
149+
netstat -an | findstr :8000 # Windows
150+
```
151+
152+
2. View container logs:
153+
```bash
154+
docker logs devtools-frontend
155+
```
156+
157+
### DevTools Not Loading
158+
159+
1. Verify the container is running:
160+
```bash
161+
docker ps
162+
```
163+
164+
2. Check Nginx is serving files:
165+
```bash
166+
curl http://localhost:8000/
167+
```
168+
169+
3. Ensure Chrome is launched with the correct flag
170+
171+
## Performance
172+
173+
- **Build time**: ~10-20 minutes (first build, depending on system)
174+
- **Image size**: ~50MB (production image with Nginx)
175+
- **Memory usage**: ~50-100MB at runtime
176+
- **Startup time**: <5 seconds
177+
178+
## Security Notes
179+
180+
- The Nginx configuration includes security headers
181+
- CORS is enabled for DevTools functionality
182+
- The container runs as non-root user (nginx)
183+
- No sensitive data is included in the final image
184+
185+
## Contributing
186+
187+
When modifying the Docker setup:
188+
1. Test builds locally before committing
189+
2. Update this README if configuration changes
190+
3. Keep the final image size minimal
191+
4. Follow Docker best practices for multi-stage builds
192+
193+
## License
194+
195+
Same as the Chrome DevTools Frontend project - BSD-3-Clause

docker/docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3.8'
2+
3+
services:
4+
devtools-frontend:
5+
build:
6+
context: ..
7+
dockerfile: docker/Dockerfile
8+
image: devtools-frontend:latest
9+
container_name: devtools-frontend
10+
ports:
11+
- "8000:8000"
12+
restart: unless-stopped
13+
volumes:
14+
# For development: mount the built files directly (optional)
15+
# Uncomment the line below to use local files instead of container files
16+
# - ../out/Default/gen/front_end:/usr/share/nginx/html:ro
17+
environment:
18+
- NGINX_HOST=localhost
19+
- NGINX_PORT=8000
20+
healthcheck:
21+
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8000/"]
22+
interval: 30s
23+
timeout: 10s
24+
retries: 3
25+
start_period: 40s
26+
networks:
27+
- devtools-network
28+
29+
networks:
30+
devtools-network:
31+
driver: bridge
32+
33+
# Optional: Add a development configuration
34+
# Use: docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml up
35+
# Create docker-compose.dev.yml for development-specific overrides

0 commit comments

Comments
 (0)