Skip to content

Commit 6a0d8d5

Browse files
committed
Update docs to switch to APPSETTINGS_JSON
1 parent c7bdb6e commit 6a0d8d5

File tree

2 files changed

+66
-50
lines changed

2 files changed

+66
-50
lines changed

MyApp/_includes/spa-info.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,20 @@ Configure in `appsettings.json` or environment:
3030

3131
### App Settings Secrets
3232

33-
Instead of polluting each GitHub Reposity with multiple App-specific GitHub Action Secrets, you can save all your secrets in a single `APPSETTINGS_PATCH` GitHub Action Secret to patch `appsettings.json` with environment-specific configuration using [JSON Patch](https://jsonpatch.com). E.g:
33+
Instead of polluting each GitHub Repository with multiple App-specific GitHub Action Secrets, all templates includes built-in support in its GitHub Action workflows for updating an App's entire `appsettings.Production.json` inside a single `APPSETTINGS_JSON` GitHub Action Secret.
3434

35-
```json
36-
[
37-
{
38-
"op":"replace",
39-
"path":"/ConnectionStrings/DefaultConnection",
40-
"value":"Server=service-postgres;Port=5432;User Id=dbuser;Password=dbpass;Database=dbname;Pooling=true;"
41-
},
42-
{ "op":"add", "path":"/SmtpConfig", "value":{
43-
"UserName": "SmptUser",
44-
"Password": "SmptPass",
45-
"Host": "email-smtp.us-east-1.amazonaws.com",
46-
"Port": 587,
47-
"From": "[email protected]",
48-
"FromName": "MyApp",
49-
50-
}
51-
},
52-
{ "op":"add", "path":"/Admins", "value": ["[email protected]","[email protected]"] },
53-
{ "op":"add", "path":"/CorsFeature/allowOriginWhitelist/-", "value":"https://servicestack.net" }
54-
]
35+
### Workflow: Development to Production
36+
37+
Run the `secret:prod` npm script to securely store your production configuration in GitHub Actions:
38+
39+
```bash
40+
npm run secret:prod
41+
```
42+
43+
This uses the GitHub CLI to add your `appsettings.Production.json` to your GitHub repository's Action secrets:
44+
45+
```bash
46+
gh secret set APPSETTINGS_JSON < appsettings.Production.json
5547
```
5648

5749
### SMTP Email

MyApp/_pages/kamal-deploy.md

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,64 @@ Hostname used for SSL certificate and Kamal proxy: www.example.org
9292
gh secret set KAMAL_DEPLOY_HOST [www.example.org]
9393
:::
9494

95-
You could register any App-specific secrets here, although our preference is instead of polluting each
96-
GitHub Repository with multiple App-specific GitHub Action Secrets, you can save all your secrets in a single
97-
`APPSETTINGS_PATCH` GitHub Action Secret to patch `appsettings.json` with environment-specific configuration
98-
using [JSON Patch](https://jsonpatch.com). E.g:
95+
### App Settings Secrets
9996

100-
JSON Patch to apply to appsettings.json:
101-
:::sh
102-
gh secret set APPSETTINGS_PATCH [json-patch]
103-
:::
104-
105-
JSON Patch example:
97+
You could register any App-specific secrets here, although our preference is to instead save all your secrets in a single `APPSETTINGS_JSON` GitHub Action Secret which will get written inside the Docker container `appsettings.Production.json`, e.g:
10698

10799
```json
108-
[
109-
{
110-
"op":"replace",
111-
"path":"/ConnectionStrings/DefaultConnection",
112-
"value":"Server=service-postgres;Port=5432;User Id=dbuser;Password=dbpass;Database=dbname"
113-
},
114-
{ "op":"add", "path":"/SmtpConfig", "value":{
115-
"UserName": "SmptUser",
116-
"Password": "SmptPass",
117-
"Host": "email-smtp.us-east-1.amazonaws.com",
118-
"Port": 587,
119-
"From": "[email protected]",
120-
"FromName": "MyApp",
121-
122-
}
123-
},
124-
{ "op":"add", "path":"/Admins", "value": ["[email protected]","[email protected]"] },
125-
{ "op":"add", "path":"/CorsFeature/allowOriginWhitelist/-", "value":"https://example.org" }
126-
]
100+
{
101+
"ConnectionStrings": {
102+
"DefaultConnection": "Server=service-postgres;Port=5432;User Id=dbuser;Password=dbpass;Database=dbname;Pooling=true;"
103+
},
104+
"SmtpConfig": {
105+
"UserName": "SmtpUser",
106+
"Password": "SmtpPass",
107+
"Host": "email-smtp.us-east-1.amazonaws.com",
108+
"Port": 587,
109+
"From": "[email protected]",
110+
"FromName": "MyApp",
111+
112+
}
113+
},
114+
115+
}
127116
```
128117

118+
After changing `appsettings.Production.json` update your `APPSETTINGS_JSON` GitHub Action Secret with:
119+
120+
```bash
121+
npm run secret:prod
122+
```
123+
124+
This uses the GitHub CLI to add your `appsettings.Production.json` to your GitHub repository's Action secrets:
125+
126+
```bash
127+
gh secret set APPSETTINGS_JSON < appsettings.Production.json
128+
```
129+
130+
**How It Works:**
131+
132+
1. **Development** - Create `appsettings.Production.json` locally with your production configuration
133+
2. **Upload** - Run `npm run secret:prod` to store it as a GitHub Action secret (never committed to git)
134+
3. **Deployment** - GitHub Actions injects the secret as the `APPSETTINGS_JSON_BASE64` environment variable
135+
4. **Runtime** - The container startup script decodes and writes it to `/app/dotnet/appsettings.Production.json`
136+
5. **Isolation** - The file is written with root-only permissions, preventing Node.js access
137+
138+
Configuration in [config/deploy.yml](https://github.com/NetCoreTemplates/next-rsc/blob/main/config/deploy.yml):
139+
140+
```yaml
141+
# config/deploy.yml
142+
env:
143+
secret:
144+
- APPSETTINGS_JSON_BASE64 # Base64-encoded production config
145+
```
146+
147+
**Benefits:**
148+
- Secrets never committed to git repository
149+
- Secrets never baked into Docker image layers
150+
- Same Docker image can be used across all environments
151+
- Production configuration remains isolated from Node.js process
152+
129153
### Inferred Variables
130154
131155
These variables are inferred from the GitHub Action context and don't need to be configured.

0 commit comments

Comments
 (0)