Skip to content

Commit c7c6ca8

Browse files
author
aligneddev
committed
devcontainer improvements
1 parent c132424 commit c7c6ca8

3 files changed

Lines changed: 50 additions & 20 deletions

File tree

.devcontainer/DEVCONTAINER.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project uses a DevContainer for consistent local development across all tea
66

77
- **Image Build**: `.devcontainer/Dockerfile` (based on `mcr.microsoft.com/devcontainers/dotnet:1-10.0-noble`)
88
- **Features**: Node.js 24+ and GitHub CLI
9-
- **Post-create bootstrap**: Restores NuGet packages, runs frontend `npm ci`, and builds the solution
9+
- **Post-create bootstrap**: Configures SSH permissions, trusts dev HTTPS certs, and installs frontend dependencies
1010

1111
## Git Credentials Setup
1212

@@ -66,11 +66,11 @@ The container exports these environment variables:
6666

6767
The `postCreateCommand` runs automatically after container creation:
6868

69-
1. `dotnet restore BikeTracking.slnx`
70-
2. `npm ci --prefix src/BikeTracking.Frontend`
71-
3. `dotnet build BikeTracking.slnx`
69+
1. Copies mounted host SSH files from `/root/.ssh-host` to `/root/.ssh` and applies secure file permissions
70+
2. `dotnet dev-certs https --trust`
71+
3. `npm ci --prefix src/BikeTracking.Frontend`
7272

73-
SDK/tool installation (required .NET SDK, CSharpier, Aspire CLI) is baked into the image build in `.devcontainer/Dockerfile`, not installed at container start.
73+
SDK/tool installation and .NET dependency restore are baked into the image build in `.devcontainer/devcontainer.Dockerfile`, not installed at container start.
7474

7575
**Output**: Terminal shows progress; container is ready when build succeeds.
7676

.devcontainer/devcontainer.Dockerfile

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ FROM mcr.microsoft.com/devcontainers/dotnet:1-10.0-noble
44

55
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
66

7-
RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor > /usr/share/keyrings/yarn-archive-keyring.gpg
7+
WORKDIR /workspaces/neCodeBikeTracking
88

9-
# Install podman
10-
RUN apt-get update && apt-get install -y podman && rm -rf /var/lib/apt/lists/*
9+
ENV PATH="/usr/local/share/dotnet-tools:/root/.dotnet/tools:${PATH}"
1110

1211
ARG REQUIRED_DOTNET_SDK_VERSION=10.0.200
1312

13+
# Install podman and Node.js 24 in a single layer.
14+
# NodeSource nodejs already includes npm; installing distro npm causes conflicts.
15+
RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor > /usr/share/keyrings/yarn-archive-keyring.gpg && apt-get update \
16+
&& curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
17+
&& apt-get update \
18+
&& apt-get install -y --no-install-recommends podman nodejs \
19+
&& rm -rf /var/lib/apt/lists/* \
20+
&& npm --version
21+
1422
# Ensure the SDK version from global.json is available in the image.
1523
RUN if dotnet --list-sdks | grep -q "^${REQUIRED_DOTNET_SDK_VERSION}"; then \
1624
echo ".NET SDK ${REQUIRED_DOTNET_SDK_VERSION} already installed."; \
@@ -21,10 +29,26 @@ RUN if dotnet --list-sdks | grep -q "^${REQUIRED_DOTNET_SDK_VERSION}"; then \
2129
rm -f /tmp/dotnet-install.sh; \
2230
fi
2331

24-
# Install required CLI tools once at image build time.
25-
RUN dotnet tool restore
26-
32+
# Install Aspire workload early — this layer survives .csproj / manifest changes.
2733
RUN curl -fsSL https://aspire.dev/install.sh | bash
2834

29-
ENV PATH="/usr/local/share/dotnet-tools:/root/.dotnet/tools:${PATH}"
35+
# Copy dependency manifests first so restore layers can be cached.
36+
COPY global.json ./
37+
COPY BikeTracking.slnx ./
38+
COPY .config/dotnet-tools.json ./.config/dotnet-tools.json
39+
COPY src/BikeTracking.Api/BikeTracking.Api.csproj src/BikeTracking.Api/
40+
COPY src/BikeTracking.Api.Tests/BikeTracking.Api.Tests.csproj src/BikeTracking.Api.Tests/
41+
COPY src/BikeTracking.AppHost/BikeTracking.AppHost.csproj src/BikeTracking.AppHost/
42+
COPY src/BikeTracking.Domain.FSharp/BikeTracking.Domain.FSharp.fsproj src/BikeTracking.Domain.FSharp/
43+
COPY src/BikeTracking.Frontend/BikeTracking.Frontend.esproj src/BikeTracking.Frontend/
44+
COPY src/BikeTracking.ServiceDefaults/BikeTracking.ServiceDefaults.csproj src/BikeTracking.ServiceDefaults/
45+
46+
# Warm NuGet cache and install CLI tools in a single layer.
47+
RUN dotnet tool restore && dotnet restore BikeTracking.slnx
48+
49+
# Copy npm manifests and warm the npm package cache.
50+
# ~/.npm is outside the workspace bind mount, so the cache persists at runtime,
51+
# making postCreateCommand "npm ci" fast without re-downloading packages.
52+
COPY src/BikeTracking.Frontend/package.json src/BikeTracking.Frontend/package-lock.json /tmp/npm-warmup/
53+
RUN npm ci --prefix /tmp/npm-warmup && rm -rf /tmp/npm-warmup
3054

.devcontainer/devcontainer.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
"context": ".."
66
},
77
"features": {
8-
"ghcr.io/devcontainers/features/node:1": {
9-
"version": "24"
10-
},
118
"ghcr.io/devcontainers/features/github-cli:1": {}
129
},
1310
"containerEnv": {
1411
"NODE_ENV": "development",
12+
"ASPIRE_CONTAINER_RUNTIME": "podman",
1513
"SSL_CERT_DIR": "/root/.aspnet/dev-certs/trust:/usr/lib/ssl/certs"
1614
},
17-
"postCreateCommand": "export ASPIRE_CONTAINER_RUNTIME=podman && mkdir -p /root/.ssh && cp /root/.ssh-host/* /root/.ssh/ && chmod 700 /root/.ssh && chmod 600 /root/.ssh/config /root/.ssh/aligneddev_github /root/.ssh/omnitech_github && chmod 644 /root/.ssh/*.pub /root/.ssh/known_hosts 2>/dev/null; dotnet dev-certs https --trust && dotnet tool restore && dotnet restore BikeTracking.slnx && dotnet build BikeTracking.slnx && npm ci --prefix src/BikeTracking.Frontend",
15+
"postCreateCommand": "mkdir -p /root/.ssh && cp /root/.ssh-host/* /root/.ssh/ && chmod 700 /root/.ssh && chmod 600 /root/.ssh/config /root/.ssh/aligneddev_github /root/.ssh/omnitech_github && chmod 644 /root/.ssh/*.pub /root/.ssh/known_hosts 2>/dev/null; dotnet dev-certs https --trust && npm ci --prefix src/BikeTracking.Frontend",
1816
"customizations": {
1917
"vscode": {
2018
"extensions": [
@@ -53,17 +51,25 @@
5351
"editor.defaultFormatter": "esbenp.prettier-vscode",
5452
"editor.formatOnSave": true
5553
},
56-
"eslint.validate": ["javascript", "typescript", "typescriptreact"]
54+
"eslint.validate": ["javascript", "typescript", "typescriptreact"],
55+
"dotnetAcquisitionExtension.existingDotnetPath": [
56+
{
57+
"extensionId": "ms-dotnettools.csdevkit",
58+
"path": "/usr/share/dotnet"
59+
},
60+
{
61+
"extensionId": "ms-dotnettools.csharp",
62+
"path": "/usr/share/dotnet"
63+
}
64+
]
5765
}
5866
}
5967
},
6068
"remoteUser": "root",
6169
"remoteEnv": {
62-
"PATH": "${containerEnv:PATH}:/usr/local/share/dotnet-tools:/root/.dotnet/tools",
63-
"SSH_AUTH_SOCK": "/ssh-agent"
70+
"PATH": "${containerEnv:PATH}:/usr/local/share/dotnet-tools:/root/.dotnet/tools"
6471
},
6572
"mounts": [
66-
"source=${env:SSH_AUTH_SOCK},target=/ssh-agent,type=bind",
6773
"source=/mnt/c/Users/klogan/.ssh,target=/root/.ssh-host,type=bind,readonly"
6874
]
6975
}

0 commit comments

Comments
 (0)