Skip to content

Commit 4175ee9

Browse files
CopilotIEvangelist
andauthored
Document deployment state caching (#5301)
* Initial plan * Add local deployment state documentation Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> * Address feedback: Add intros, italicize paths, add CI/CD example Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> * Rename and relocate deployment state doc outside Azure section Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> * Clarify cache save behavior in GitHub Actions example Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent 5e7653c commit 4175ee9

File tree

5 files changed

+209
-1
lines changed

5 files changed

+209
-1
lines changed

.openpublishing.redirection.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@
335335
{
336336
"source_path_from_root": "/docs/fundamentals/build-container-images.md",
337337
"redirect_url": "/dotnet/aspire/fundamentals/custom-deployments"
338+
},
339+
{
340+
"source_path_from_root": "/docs/deployment/aspire-deploy/local-deployment-state.md",
341+
"redirect_url": "/dotnet/aspire/deployment/deployment-state-caching"
338342
}
339343
]
340344
}

docs/cli-reference/aspire-deploy.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ The following options are available:
5555

5656
- [!INCLUDE [option-project](includes/option-project.md)]
5757

58+
- **`-e, --environment`**
59+
60+
The deployment environment name. Defaults to `production`. Each environment maintains its own isolated deployment state file.
61+
62+
- **`--clear-cache`**
63+
64+
Clears the cached deployment state for the specified environment before deploying. When used, the deployment prompts for all values but doesn't save them to cache.
65+
5866
- **`-o, --output-path`**
5967

6068
The output path for deployment artifacts. Defaults to a folder named _deploy_ in the current directory.
@@ -84,3 +92,25 @@ The following options are available:
8492
```Command
8593
aspire deploy --project './projects/apphost/orchestration.AppHost.csproj' -- -fast
8694
```
95+
96+
- Deploy to a specific environment:
97+
98+
```Command
99+
aspire deploy --environment staging
100+
```
101+
102+
- Clear cached deployment state and deploy:
103+
104+
```Command
105+
aspire deploy --clear-cache
106+
```
107+
108+
- Clear cached deployment state for a specific environment:
109+
110+
```Command
111+
aspire deploy --environment staging --clear-cache
112+
```
113+
114+
## See also
115+
116+
- [Deployment state caching](../deployment/deployment-state-caching.md)

docs/deployment/aspire-deploy/aca-deployment-aspire-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Save to user secrets: [y/n] (n): n
139139
```
140140

141141
> [!NOTE]
142-
> The CLI will continuously prompt until all unresolved parameters are provided with values. While Azure deployment is in preview, the CLI will prompt to save values in user secrets but not use them, as [deployment state is not supported](https://github.com/dotnet/aspire/issues/11444).
142+
> The CLI continuously prompts until all unresolved parameters are provided with values. The `aspire deploy` command caches deployment state locally to streamline subsequent deployments. For more information, see [Deployment state caching](../deployment-state-caching.md).
143143
144144
Once parameters are collected, Azure infrastructure is provisioned using Bicep templates. This step creates the necessary Azure resources including the Container Apps environment, Container Registry, and any backing services like Redis caches:
145145

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
title: Deployment state caching
3+
description: Learn how the aspire deploy command manages deployment state through cached configuration files.
4+
ms.date: 10/17/2025
5+
ai-usage: ai-assisted
6+
---
7+
8+
# Deployment state caching
9+
10+
The `aspire deploy` command manages deployment state through cached configuration files stored locally on your machine. This caching mechanism streamlines repeated deployments by preserving provisioning settings and parameters, making subsequent deployments faster and more efficient.
11+
12+
## Default behavior
13+
14+
The `aspire deploy` command automatically manages deployment state based on whether cached configuration exists for your application and target environment.
15+
16+
### First deployment
17+
18+
When you run `aspire deploy` for the first time, or for the first time in a target `--environment`, the command:
19+
20+
1. Prompts for provisioning information (subscription ID, resource group name, location).
21+
1. Prompts for deployment parameters (for example, API keys, connection strings).
22+
1. Initiates the deployment process.
23+
1. Saves all prompted values and deployment state to `~/.aspire/deployments/{AppHostSha}/production.json`.
24+
25+
### Subsequent deployments
26+
27+
On subsequent `aspire deploy` executions, the command:
28+
29+
1. Detects the existing deployment state file at _~/.aspire/deployments/{AppHostSha}/production.json_.
30+
1. Notifies you that settings will be read from the cached file.
31+
1. Prompts for confirmation to load the cached settings.
32+
1. Loads the configuration from the cached file into the configuration provider.
33+
1. Proceeds with deployment using the cached values (no re-prompting).
34+
35+
## Environment-specific deployments
36+
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+
39+
### Specify an environment
40+
41+
Use the `--environment` flag to deploy to different environments:
42+
43+
```Aspire
44+
aspire deploy --environment staging
45+
```
46+
47+
**First deployment to a specific environment:**
48+
49+
- Prompts for all provisioning and parameter information.
50+
- Saves deployment state to _~/.aspire/deployments/{AppHostSha}/{environment}.json_ (for example, _staging.json_).
51+
52+
**Subsequent deployments:**
53+
54+
- Reads the environment-specific cached file.
55+
- Loads configuration from the cached state.
56+
- Uses cached values without prompting.
57+
58+
### Environment variable support
59+
60+
The deployment environment can also be specified using the `DOTNET_ENVIRONMENT` environment variable:
61+
62+
```bash
63+
export DOTNET_ENVIRONMENT=staging && aspire deploy
64+
```
65+
66+
This behaves identically to using the `--environment` flag, loading the appropriate cached configuration file.
67+
68+
## Cache management
69+
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+
72+
### Clear the cache
73+
74+
Use the `--clear-cache` flag to reset deployment state:
75+
76+
```Aspire
77+
aspire deploy --clear-cache
78+
```
79+
80+
**Behavior:**
81+
82+
1. Prompts for confirmation before deleting the cache for the specified environment.
83+
1. Deletes the environment-specific deployment state file (for example, _~/.aspire/deployments/{AppHostSha}/production.json_).
84+
1. Prompts for all provisioning and parameter information as if deploying for the first time.
85+
1. Proceeds with deployment.
86+
1. **Does not save the prompted values** to cache.
87+
88+
### Environment-specific cache clearing
89+
90+
The `--clear-cache` flag respects the environment context:
91+
92+
```Aspire
93+
aspire deploy --environment staging --clear-cache
94+
```
95+
96+
This clears only the _staging.json_ cache file while leaving other environment caches (like _production.json_) intact.
97+
98+
## File storage location
99+
100+
- **Path pattern:** _~/.aspire/deployments/{AppHostSha}/{environment}.json_.
101+
- **Default environment:** `production`.
102+
- **AppHostSha:** A hash value representing the application host configuration, ensuring deployment states are specific to each application configuration.
103+
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. The `actions/cache` action automatically restores the cache before the deployment step and saves any updates to the cache after the job completes. 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+
145+
## Security considerations
146+
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:
148+
149+
- Files are stored outside of source code to mitigate against accidental secret leaks in version control.
150+
- Secrets are stored in plain text in the local file system.
151+
- Any process running under your user account can access these files.
152+
153+
Consider these security best practices:
154+
155+
- Ensure your local machine has appropriate security measures in place.
156+
- Be cautious when sharing or backing up files from the _~/.aspire/deployments_ directory.
157+
- Use the `--clear-cache` flag when you need to change sensitive parameter values.
158+
159+
## Key points
160+
161+
- Each environment maintains its own isolated deployment state.
162+
- Cached values persist across deployments unless explicitly cleared.
163+
- The `--clear-cache` flag performs a one-time deployment without persisting new values.
164+
- Environment selection can be specified via flag or environment variable.
165+
- You're prompted for confirmation when loading cached settings.
166+
- Cache files are stored per application (via AppHostSha) and per environment.
167+
168+
## See also
169+
170+
- [aspire deploy command reference](../cli-reference/aspire-deploy.md)
171+
- [Deploy to Azure Container Apps using Aspire CLI](aspire-deploy/aca-deployment-aspire-cli.md)

docs/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ items:
495495
href: deployment/overview.md
496496
- name: Building custom deployment pipelines
497497
href: fundamentals/custom-deployments.md
498+
- name: Deployment state caching
499+
href: deployment/deployment-state-caching.md
500+
displayName: deployment state,deployment cache,clear-cache,deployment settings,aspire deploy
498501
- name: Azure deployment with Aspire
499502
items:
500503
- name: Deploy to Azure Container Apps using Aspire CLI

0 commit comments

Comments
 (0)