Skip to content

Commit 8f81e2b

Browse files
authored
Optimize to increase rebuild speed (#48)
- Adds dockerignore to prevent accidental data leakage - Combine unminimize and apt install layers -- unminimize does an `apt update` in the background already. Combining apt steps increases docker's ability to reuse context within the same layer and removes an extra `apt update` step - Use a Docker cache mount for apt layer. Allows the build to reuse apt artifacts across rebuild - Remove temp files from tool installs to reduce image size - Postcreate installs a few tools in parallel instead of serially - Poststart checks for claude code updates. Since the Claude install is in the docker file, the installed version of claude is cached by docker on image build and may not update unless you ask for an update
1 parent e605357 commit 8f81e2b

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

.devcontainer/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Prevent sensitive files from entering build context
2+
.aws/
3+
dev-certs/
4+
msbuild/

.devcontainer/Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
FROM mcr.microsoft.com/devcontainers/dotnet:2.0.5-10.0-noble
23

34
ARG TARGETARCH
@@ -12,9 +13,6 @@ RUN mkdir -p /etc/apt/keyrings && \
1213
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /etc/apt/keyrings/yarn.gpg && \
1314
echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
1415

15-
# Install man pages
16-
RUN yes | unminimize
17-
1816
# Custom Cert Support
1917
COPY ./certs /usr/local/share/ca-certificates/custom/
2018
RUN find /usr/local/share/ca-certificates/custom -type f ! -name '*.crt' -delete \
@@ -27,13 +25,15 @@ ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt \
2725
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
2826
PIP_CERT=/etc/ssl/certs/ca-certificates.crt
2927

30-
# required for those running ARM builds, possibly confined only to Angular 16. Try back later.
31-
RUN apt update && apt install -y python3-dev
32-
33-
RUN apt install -y \
28+
# Install man pages and additional packages
29+
# unminimize runs apt-get update internally, so the index is fresh for the install that follows
30+
# Use a docker cache mount to increase rebuild speed
31+
RUN --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
32+
--mount=type=cache,target=/var/cache/apt,sharing=locked \
33+
yes | unminimize && \
34+
apt-get install -y --no-install-recommends \
3435
php \
3536
php-cli
36-
3737
# Install Vale
3838
ARG VALE_VERSION=3.12.0
3939
RUN set -eux; \
@@ -51,7 +51,8 @@ RUN set -eux; \
5151

5252
# Install k-alias
5353
RUN git clone https://github.com/jaggedmountain/k-alias.git /tmp/k-alias && \
54-
cp /tmp/k-alias/[h,k]* /usr/local/bin
54+
cp /tmp/k-alias/[h,k]* /usr/local/bin && \
55+
rm -rf /tmp/k-alias
5556

5657
# Install AWS CLI with Session Manager Plugin
5758
RUN case "${TARGETARCH}" in \
@@ -65,7 +66,8 @@ RUN case "${TARGETARCH}" in \
6566
unzip -q /tmp/awscliv2.zip -d /tmp && \
6667
/tmp/aws/install --update && \
6768
curl "${SSM_URL}" -o /tmp/session-manager-plugin.deb && \
68-
dpkg -i /tmp/session-manager-plugin.deb
69+
dpkg -i /tmp/session-manager-plugin.deb && \
70+
rm -rf /tmp/awscliv2.zip /tmp/aws /tmp/session-manager-plugin.deb
6971

7072
# Configure AWS CLI bash completion
7173
RUN echo '' >> /home/vscode/.bashrc && \

.devcontainer/postcreate.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ sudo chown -R $(whoami): /home/vscode/.claude
1212
scripts/clone-repos.sh
1313
scripts/add-moodle-mounts.sh
1414

15-
curl -sSL https://aspire.dev/install.sh | bash
16-
dotnet tool install --global dotnet-ef --version 10
15+
echo "Installing tools..."
16+
17+
(curl -sSL https://aspire.dev/install.sh | bash) &
18+
ASPIRE_PID=$!
19+
20+
(dotnet tool install --global dotnet-ef --version 10) &
21+
DOTNET_EF_PID=$!
22+
23+
(npm config -g set fund false && npm install -g @angular/cli@latest) &
24+
ANGULAR_PID=$!
25+
26+
wait $ASPIRE_PID $DOTNET_EF_PID $ANGULAR_PID
27+
echo "Tool installs complete."
28+
1729
dotnet dev-certs https --trust
1830

1931
# Generate crucible-dev certificates
@@ -53,9 +65,6 @@ sudo update-ca-certificates
5365

5466
echo "Crucible-dev certificates generated and trusted."
5567

56-
npm config -g set fund false
57-
npm install -g @angular/cli@latest
58-
5968
# Stage custom CA certs so Minikube trusts them
6069
CUSTOM_CERT_SOURCE="/usr/local/share/ca-certificates/custom"
6170
MINIKUBE_CERT_DEST="${HOME}/.minikube/files/etc/ssl/certs/custom"

.devcontainer/poststart.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright 2025 Carnegie Mellon University. All Rights Reserved.
33
# Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.
44

5+
claude update &
6+
57
scripts/sync-repos.sh --pull
68

79
# Welcome message

0 commit comments

Comments
 (0)