Skip to content

Commit 10e98b1

Browse files
author
aligneddev
committed
user-secrets into devcontainer
1 parent d5811b3 commit 10e98b1

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

.devcontainer/DEVCONTAINER.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,29 @@ Note the devcontainer.json setup with
136136
},
137137
"mounts": [
138138
"source=${env:SSH_AUTH_SOCK},target=/ssh-agent,type=bind",
139-
"source=/mnt/c/Users/klogan/.ssh,target=/root/.ssh-host,type=bind,readonly"
139+
"source=${localEnv:HOME}/.ssh,target=/root/.ssh-host,type=bind,readonly",
140+
"source=${localEnv:HOME}/.microsoft/usersecrets,target=/root/.microsoft/usersecrets,type=bind"
140141
]
141142

142143
### Secrets Management
143144

144145
- Local development: Use .NET User Secrets or environment variables
145146
- CI/CD: Use GitHub repository secrets or Azure Key Vault
146147
- DevContainer environment variables in `devcontainer.json` are for non-sensitive values only
148+
- Persist User Secrets in Dev Containers by bind-mounting your host user-secrets directory to `/root/.microsoft/usersecrets`
149+
150+
Example mount paths by host OS:
151+
- Linux/macOS host: `source=${localEnv:HOME}/.microsoft/usersecrets,target=/root/.microsoft/usersecrets,type=bind`
152+
- Windows host: `source=${localEnv:APPDATA}/Microsoft/UserSecrets,target=/root/.microsoft/usersecrets,type=bind`
153+
154+
If you use Docker Compose directly, the same mapping applies:
155+
156+
```yaml
157+
services:
158+
api:
159+
volumes:
160+
- ${HOME}/.microsoft/usersecrets:/root/.microsoft/usersecrets
161+
```
147162
148163
## Advanced Customization
149164
@@ -180,7 +195,8 @@ Edit `mounts` array to add more host directories (e.g., for shared data):
180195

181196
```json
182197
"mounts": [
183-
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/root/.ssh,readonly",
198+
"source=${localEnv:HOME}/.ssh,target=/root/.ssh-host,type=bind,readonly",
199+
"source=${localEnv:HOME}/.microsoft/usersecrets,target=/root/.microsoft/usersecrets,type=bind",
184200
"source=/path/on/host,target=/path/in/container"
185201
]
186202
```

.devcontainer/devcontainer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "Bike Tracking - Full Stack",
2+
"name": "Bike Commuter Tracker - Full Stack",
33
"build": {
44
"dockerfile": "devcontainer.Dockerfile",
55
"context": ".."
@@ -70,6 +70,7 @@
7070
"PATH": "${containerEnv:PATH}:/usr/local/share/dotnet-tools:/root/.dotnet/tools"
7171
},
7272
"mounts": [
73-
"source=/mnt/c/Users/klogan/.ssh,target=/root/.ssh-host,type=bind,readonly"
73+
"source=${localEnv:HOME}/.ssh,target=/root/.ssh-host,type=bind,readonly",
74+
"source=/mnt/c/Users/klogan/AppData/Roaming/Microsoft/UserSecrets,target=/root/.microsoft/usersecrets,type=bind"
7475
]
7576
}

specs/010-gas-price-lookup/quickstart.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@ When a user creates or edits a ride, the form now shows a **Gas Price ($/gal)**
3535

3636
## EIA API Key Setup (Development)
3737

38-
The EIA API key is required for the lookup to succeed. In development, set it via .NET User Secrets:
38+
The EIA API key is required for the lookup to succeed. In development (on your local machine), set it via .NET User Secrets:
3939

4040
```bash
4141
cd src/BikeTracking.Api
4242
dotnet user-secrets set "GasPriceLookup:EiaApiKey" "YOUR_EIA_KEY_HERE"
4343
```
4444

45+
If you run the API in a dev container, bind-mount your host User Secrets directory so secrets persist across container rebuilds:
46+
47+
```yaml
48+
# docker-compose.yml
49+
services:
50+
api:
51+
volumes:
52+
- ${HOME}/.microsoft/usersecrets:/root/.microsoft/usersecrets
53+
```
54+
55+
Windows host path equivalent:
56+
57+
```text
58+
%APPDATA%\Microsoft\UserSecrets -> /root/.microsoft/usersecrets
59+
```
60+
4561
Get a free key at: https://www.eia.gov/opendata/register.php
4662

4763
Without the key, the field will fall back to the last ride's gas price (or remain empty for new users). The ride can still be saved — gas price is always optional.

0 commit comments

Comments
 (0)