Skip to content

Commit 4ed162e

Browse files
CopilotIEvangelist
andcommitted
Address feedback: Add intros, italicize paths, add CI/CD example
Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent fc87103 commit 4ed162e

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

docs/deployment/aspire-deploy/local-deployment-state.md

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ The `aspire deploy` command manages deployment state through cached configuratio
1111

1212
## Default behavior
1313

14+
The `aspire deploy` command automatically manages deployment state based on whether cached configuration exists for your application and target environment.
15+
1416
### First deployment
1517

16-
When you run `aspire deploy` for the first time, the command:
18+
When you run `aspire deploy` for the first time, or for the first time in a target `--environment`, the command:
1719

1820
1. Prompts for provisioning information (subscription ID, resource group name, location).
1921
1. Prompts for deployment parameters (for example, API keys, connection strings).
@@ -24,14 +26,16 @@ When you run `aspire deploy` for the first time, the command:
2426

2527
On subsequent `aspire deploy` executions, the command:
2628

27-
1. Detects the existing deployment state file at `~/.aspire/deployments/{AppHostSha}/production.json`.
29+
1. Detects the existing deployment state file at _~/.aspire/deployments/{AppHostSha}/production.json_.
2830
1. Notifies you that settings will be read from the cached file.
2931
1. Prompts for confirmation to load the cached settings.
3032
1. Loads the configuration from the cached file into the configuration provider.
3133
1. Proceeds with deployment using the cached values (no re-prompting).
3234

3335
## Environment-specific deployments
3436

37+
Different deployment environments (such as development, staging, and production) typically require different configurations, resource names, and connection strings. The `aspire deploy` command supports environment-specific deployments, ensuring that each environment maintains isolated deployment state.
38+
3539
### Specify an environment
3640

3741
Use the `--environment` flag to deploy to different environments:
@@ -43,7 +47,7 @@ aspire deploy --environment staging
4347
**First deployment to a specific environment:**
4448

4549
- Prompts for all provisioning and parameter information.
46-
- Saves deployment state to `~/.aspire/deployments/{AppHostSha}/{environment}.json` (for example, `staging.json`).
50+
- Saves deployment state to _~/.aspire/deployments/{AppHostSha}/{environment}.json_ (for example, _staging.json_).
4751

4852
**Subsequent deployments:**
4953

@@ -63,6 +67,8 @@ This behaves identically to using the `--environment` flag, loading the appropri
6367

6468
## Cache management
6569

70+
The `aspire deploy` command provides mechanisms to manage cached deployment state, giving you control over when to use cached values and when to start fresh.
71+
6672
### Clear the cache
6773

6874
Use the `--clear-cache` flag to reset deployment state:
@@ -74,7 +80,7 @@ aspire deploy --clear-cache
7480
**Behavior:**
7581

7682
1. Prompts for confirmation before deleting the cache for the specified environment.
77-
1. Deletes the environment-specific deployment state file (for example, `~/.aspire/deployments/{AppHostSha}/production.json`).
83+
1. Deletes the environment-specific deployment state file (for example, _~/.aspire/deployments/{AppHostSha}/production.json_).
7884
1. Prompts for all provisioning and parameter information as if deploying for the first time.
7985
1. Proceeds with deployment.
8086
1. **Does not save the prompted values** to cache.
@@ -87,17 +93,58 @@ The `--clear-cache` flag respects the environment context:
8793
aspire deploy --environment staging --clear-cache
8894
```
8995

90-
This clears only the `staging.json` cache file while leaving other environment caches (like `production.json`) intact.
96+
This clears only the _staging.json_ cache file while leaving other environment caches (like _production.json_) intact.
9197

9298
## File storage location
9399

94-
- **Path pattern:** `~/.aspire/deployments/{AppHostSha}/{environment}.json`
95-
- **Default environment:** `production`
100+
- **Path pattern:** _~/.aspire/deployments/{AppHostSha}/{environment}.json_.
101+
- **Default environment:** `production`.
96102
- **AppHostSha:** A hash value representing the application host configuration, ensuring deployment states are specific to each application configuration.
97103

104+
## Use deployment state in CI/CD pipelines
105+
106+
When using the `aspire deploy` command in continuous integration and deployment (CI/CD) pipelines, you might want to persist deployment state across pipeline runs. This approach can be useful for maintaining consistent deployment configurations without manual intervention.
107+
108+
### GitHub Actions example
109+
110+
The following example demonstrates how to cache deployment state in a GitHub Actions workflow using the `actions/cache` action:
111+
112+
```yaml
113+
name: Deploy to Azure
114+
115+
on:
116+
push:
117+
branches: [ main ]
118+
119+
jobs:
120+
deploy:
121+
runs-on: ubuntu-latest
122+
steps:
123+
- uses: actions/checkout@v4
124+
125+
- name: Cache Aspire deployment state
126+
uses: actions/cache@v4
127+
with:
128+
path: ~/.aspire/deployments
129+
key: aspire-deploy-${{ hashFiles('**/AppHost.csproj') }}-${{ github.ref }}
130+
restore-keys: |
131+
aspire-deploy-${{ hashFiles('**/AppHost.csproj') }}-
132+
aspire-deploy-
133+
134+
- name: Deploy with Aspire CLI
135+
run: aspire deploy --environment production
136+
env:
137+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
138+
```
139+
140+
This workflow caches the _~/.aspire/deployments_ directory, using the AppHost project file hash and branch reference as cache keys. Subsequent workflow runs restore the cached deployment state, allowing automated deployments without re-prompting for configuration values.
141+
142+
> [!CAUTION]
143+
> When caching deployment state in CI/CD pipelines, ensure that your pipeline has appropriate access controls and secret management practices in place, as the cached state might contain sensitive configuration values.
144+
98145
## Security considerations
99146
100-
The deployment state files are stored locally on your machine in the `~/.aspire/deployments` directory. These files contain provisioning settings and parameter values, including secrets that might be associated with parameter resources. The `aspire deploy` command follows the same security pattern as .NET's user secrets manager:
147+
The deployment state files are stored locally on your machine in the _~/.aspire/deployments_ directory. These files contain provisioning settings and parameter values, including secrets that might be associated with parameter resources. The `aspire deploy` command follows the same security pattern as .NET's user secrets manager:
101148

102149
- Files are stored outside of source code to mitigate against accidental secret leaks in version control.
103150
- Secrets are stored in plain text in the local file system.
@@ -106,7 +153,7 @@ The deployment state files are stored locally on your machine in the `~/.aspire/
106153
Consider these security best practices:
107154

108155
- Ensure your local machine has appropriate security measures in place.
109-
- Be cautious when sharing or backing up files from the `~/.aspire/deployments` directory.
156+
- Be cautious when sharing or backing up files from the _~/.aspire/deployments_ directory.
110157
- Use the `--clear-cache` flag when you need to change sensitive parameter values.
111158

112159
## Key points

0 commit comments

Comments
 (0)