Skip to content

Commit 4c76653

Browse files
authored
MAINT: Optimize devcontainer Dockerfile (microsoft#1437)
1 parent 7822646 commit 4c76653

6 files changed

Lines changed: 52 additions & 50 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM mcr.microsoft.com/devcontainers/python:3.11
1+
# syntax=docker/dockerfile:1
2+
FROM mcr.microsoft.com/devcontainers/python:3.11-bookworm
23

34
# Makes installation faster
45
ENV UV_COMPILE_BYTECODE=1
6+
ENV DEBIAN_FRONTEND=noninteractive
57

68
SHELL ["/bin/bash", "-c"]
79

@@ -11,66 +13,61 @@ USER root
1113
RUN rm -f /etc/apt/sources.list.d/yarn.list 2>/dev/null || true
1214

1315
# Install required system packages + ODBC prerequisites
14-
RUN apt-get update && apt-get install -y \
15-
sudo \
16-
unixodbc \
17-
unixodbc-dev \
18-
libgl1 \
19-
git \
20-
curl \
21-
xdg-utils \
22-
build-essential \
23-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
16+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
17+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
18+
apt-get update \
19+
&& apt-get install -y --no-install-recommends \
20+
sudo \
21+
unixodbc \
22+
unixodbc-dev \
23+
libgl1 \
24+
git \
25+
curl \
26+
xdg-utils \
27+
build-essential
2428

25-
# Install the Azure CLI, Microsoft ODBC Driver 18 & SQL tools
29+
# Install Microsoft ODBC Driver 18 & SQL tools
2630
# Note: Debian Trixie's sqv rejects SHA1 signatures, so we use gpg directly to import the Microsoft key
27-
RUN apt-get update && apt-get install -y \
28-
apt-transport-https \
31+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
32+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
33+
apt-get update \
34+
&& apt-get install -y --no-install-recommends \
2935
ca-certificates \
3036
gnupg \
31-
lsb-release \
3237
&& curl -sL https://packages.microsoft.com/keys/microsoft.asc \
3338
| gpg --dearmor \
3439
> /usr/share/keyrings/microsoft-archive-keyring.gpg \
3540
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" \
3641
> /etc/apt/sources.list.d/microsoft.list \
3742
&& apt-get update \
38-
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 \
39-
&& apt-get install -y azure-cli \
40-
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> /etc/profile.d/sqltools.sh \
41-
&& apt-get clean \
42-
&& rm -rf /var/lib/apt/lists/*
43+
&& ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
44+
msodbcsql18 \
45+
mssql-tools18 \
46+
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> /etc/profile.d/sqltools.sh
4347

4448
# audio back-ends needed by Azure Speech SDK
45-
RUN apt-get update \
46-
&& DEBIAN_FRONTEND=noninteractive \
47-
apt-get install -y --no-install-recommends \
49+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
50+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
51+
apt-get update \
52+
&& apt-get install -y --no-install-recommends \
4853
libasound2 \
49-
libpulse0 \
50-
&& rm -rf /var/lib/apt/lists/*
54+
libpulse0
5155

5256
# Install uv system-wide and create pyrit-dev venv
53-
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
54-
&& mv /root/.local/bin/uv /usr/local/bin/uv \
55-
&& rm -rf /opt/venv \
56-
&& uv venv /opt/venv --python 3.11 --prompt pyrit-dev \
57-
&& chown -R vscode:vscode /opt/venv \
58-
&& ls -la /opt/venv/bin/activate
57+
COPY --from=ghcr.io/astral-sh/uv:0.10.8 /uv /uvx /bin/
58+
RUN uv venv /opt/venv --python 3.11 --prompt pyrit-dev \
59+
&& chown -R vscode:vscode /opt/venv
5960
ENV PATH="/opt/venv/bin:$PATH"
6061

62+
# Install Node.js 24.x LTS for frontend development
63+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
64+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
65+
curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
66+
&& apt-get install -y --no-install-recommends nodejs
67+
6168
# vscode user already exists in the base image, just ensure sudo access
6269
RUN echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
6370

64-
# Install Node.js 20.x and npm for frontend development
65-
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
66-
&& apt-get install -y nodejs \
67-
&& npm install -g npm@latest \
68-
&& npm install -g @github/copilot@0.0.421 \
69-
&& npm cache clean --force \
70-
&& rm -rf /root/.npm \
71-
&& apt-get clean \
72-
&& rm -rf /var/lib/apt/lists/*
73-
7471
# Pre-create common user caches and fix permissions
7572
RUN mkdir -p /home/vscode/.cache/pre-commit \
7673
&& mkdir -p /home/vscode/.vscode-server \
@@ -79,7 +76,7 @@ RUN mkdir -p /home/vscode/.cache/pre-commit \
7976
&& mkdir -p /home/vscode/.cache/venv \
8077
&& mkdir -p /home/vscode/.cache/pylance \
8178
&& chown -R vscode:vscode /home/vscode/.cache /home/vscode/.vscode-server \
82-
&& chmod -R 777 /home/vscode/.cache/pip /home/vscode/.cache/pylance /home/vscode/.cache/venv /home/vscode/.cache/uv\
79+
&& chmod -R 755 /home/vscode/.cache/pip /home/vscode/.cache/pylance /home/vscode/.cache/venv /home/vscode/.cache/uv \
8380
&& chmod -R 755 /home/vscode/.vscode-server
8481

8582
USER vscode
@@ -95,6 +92,6 @@ RUN git config --global core.preloadindex true \
9592
&& git config --global status.showUntrackedFiles all \
9693
&& git config --global core.fsmonitor true
9794

98-
# Set cache directories so they can be mounted
95+
# Set cache directories so they can be mounted
9996
ENV PIP_CACHE_DIR="/home/vscode/.cache/pip"
10097
ENV UV_CACHE_DIR="/home/vscode/.cache/uv"

.devcontainer/devcontainer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
]
9191
}
9292
},
93+
"features": {
94+
"ghcr.io/devcontainers/features/azure-cli:1": {
95+
"version": "latest"
96+
},
97+
"ghcr.io/devcontainers/features/copilot-cli:1": {
98+
"version": "latest"
99+
}
100+
},
93101
"postCreateCommand": "/bin/bash -i .devcontainer/devcontainer_setup.sh",
94102
"forwardPorts": [3000, 4213, 5000, 8000, 8888]
95103
}

.devcontainer/devcontainer_setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ ! -d "$MYPY_CACHE" ]; then
88
echo "Creating mypy cache directory..."
99
sudo mkdir -p $MYPY_CACHE
1010
sudo chown vscode:vscode $MYPY_CACHE
11-
sudo chmod 777 $MYPY_CACHE
11+
sudo chmod 755 $MYPY_CACHE
1212
else
1313
# Check ownership
1414
OWNER=$(stat -c '%U:%G' $MYPY_CACHE)
@@ -21,9 +21,9 @@ else
2121
# Check permissions
2222
PERMS=$(stat -c '%a' $MYPY_CACHE)
2323

24-
if [ "$PERMS" != "777" ]; then
24+
if [ "$PERMS" != "755" ]; then
2525
echo "Fixing mypy cache directory permissions..."
26-
sudo chmod -R 777 $MYPY_CACHE
26+
sudo chmod -R 755 $MYPY_CACHE
2727
fi
2828
fi
2929

build_scripts/prepare_package.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Microsoft Corporation.
32
# Licensed under the MIT license.
43

@@ -33,7 +32,7 @@ def build_frontend(frontend_dir: Path) -> bool:
3332
print(f"Found npm version: {result.stdout.strip()}")
3433
except (subprocess.CalledProcessError, FileNotFoundError):
3534
print("ERROR: npm is not installed or not in PATH")
36-
print("Please install Node.js 20.x and npm from https://nodejs.org/")
35+
print("Please install Node.js 24.x and npm from https://nodejs.org/")
3736
return False
3837

3938
# Check if package.json exists

docker/build_pyrit_docker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Microsoft Corporation.
32
# Licensed under the MIT license.
43

docker/run_pyrit_docker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Microsoft Corporation.
32
# Licensed under the MIT license.
43

0 commit comments

Comments
 (0)