Deploy .NET Aspire applications to remote hosts via SSH with a single command. This sample demonstrates future deployment pipeline patterns for Aspire.
aspire-publish.v2.mp4
- .NET 8 SDK - https://dotnet.microsoft.com/en-us/download
- Docker Desktop or Docker CLI - https://www.docker.com/get-started/
- SSH client (typically included with Windows 10/11, macOS, and Linux)
- Aspire 9.4 CLI (Nightly): Follow the installation guide at https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md#install-the-daily-cli
dotnet tool install --global aspire.cli --prerelease --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json
Add SSH deployment support to your Aspire app host:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddDockerComposeEnvironment("env")
.WithSshDeploySupport();
var cache = builder.AddRedis("cache");
var apiService = builder.AddProject<Projects.DockerPipelinesSample_ApiService>("apiservice")
.WithHttpHealthCheck("/health");
builder.AddProject<Projects.DockerPipelinesSample_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithHttpHealthCheck("/health")
.WithReference(cache)
.WaitFor(cache)
.WithReference(apiService)
.WaitFor(apiService);
builder.Build().Run();
Deploy your application using the Aspire CLI:
# Deploy with interactive prompts
aspire deploy
Sample implementation showcasing configurable deployment pipelines that can be shared as NuGet packages, prompt for values, and integrate with IConfiguration.
- SSH-based Docker deployment to remote hosts
- Interactive configuration prompts
- Integration with appsettings.json and environment variables
- Configurable deployment paths and Docker registries
When deploying, the pipeline will prompt for required values if they're not already configured:
- SSH Host: The target deployment server hostname/IP
- SSH Username: Username for SSH authentication
- SSH Port: SSH port (defaults to 22)
- SSH Key Path: Path to SSH private key file
- Remote Deploy Path: Target directory on remote host (optional, defaults to
/home/{username}/aspire-app
) - Registry URL: Docker registry URL (e.g., docker.io)
- Repository Prefix: Docker repository prefix/username
You can pre-configure deployment settings in your appsettings.json
:
{
"DockerSSH": {
"SshHost": "your-server.com",
"SshUsername": "your-username",
"SshPort": "22",
"SshKeyPath": "path/to/your/private-key",
"RemoteDeployPath": "/opt/your-app",
"RegistryUrl": "docker.io",
"RepositoryPrefix": "your-docker-username"
}
}
Alternatively, use environment variables:
DOCKERSSH__SSHHOST=your-server.com
DOCKERSSH__SSHUSERNAME=your-username
DOCKERSSH__SSHPORT=22
DOCKERSSH__SSHKEYPATH=path/to/your/private-key
DOCKERSSH__REMOTEDEPLOYPATH=/opt/your-app
DOCKERSSH__REGISTRYURL=docker.io
DOCKERSSH__REPOSITORYPREFIX=your-docker-username
- .NET Aspire 9.4 CLI (Nightly Build): Required for deployment functionality
- Follow the installation guide: https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md#install-the-daily-cli
- .NET 8 SDK: Required for building and running Aspire applications
- Docker: Must be installed on both local development machine and target deployment host
- SSH Access: SSH connectivity to the target deployment host
The remote deployment host must have:
- Docker installed and running
- SSH server configured and accessible
- User account with Docker permissions (user should be in the
docker
group) - Network connectivity for downloading Docker images (if not transferred locally)
- Configuration Resolution: Reads deployment settings from configuration sources and prompts for missing values
- Docker Image Building: Builds Docker images for all containerized projects in the Aspire application
- Image Transfer: Transfers Docker images to the remote host via SSH
- Container Deployment: Deploys and starts containers on the remote host
- Service Coordination: Ensures proper startup order and inter-service communication
The SSH deployment pipeline consists of:
DockerSSHPipeline
: Core resource that manages the SSH deployment processWithSshDeploySupport
: Extension method that registers the pipeline with the Aspire application- Configuration providers: Handle interactive prompts and settings resolution
- SSH client: Manages secure communication with the remote host
The samples/DockerPipelinesSample
directory contains a complete example showing:
- AppHost: Aspire application host with SSH deployment enabled
- ApiService: Sample API service for deployment
- Web: Sample web application
- ServiceDefaults: Shared service configuration
To run the sample:
aspire run
To deploy the sample:
aspire deploy
The WithSshDeploySupport
extension method currently doesn't accept parameters. All configuration is handled through the configuration system (appsettings.json, environment variables, or interactive prompts).
- SSH Keys: Consider using SSH key-based authentication instead of passwords
- Secrets Management: Use secure configuration providers for sensitive data
- Network Security: Ensure SSH connections are properly secured
- Container Security: Follow Docker security best practices for deployed containers
This sample implementation demonstrates the foundation for more advanced deployment pipeline features:
- Multiple deployment targets: Azure, AWS, Kubernetes, etc.
- CI/CD integration: GitHub Actions, Azure DevOps, etc.
- Advanced orchestration: Service mesh integration, load balancing
- Monitoring integration: Health checks, logging, metrics collection
- Advanced SSH deployment scenarios: multi-host deployments, blue-green deployment strategies, health check integration, rollback capabilities