Listen to this Post
Learn how to automate your .NET application deployments using GitHub Actions. This article provides a 3-step pipeline that builds and tests your .NET application, applies migrations using EF bundles, and deploys the application to Azure App Service. Each step depends on the previous one, ensuring a seamless deployment process.
Step-by-Step Pipeline:
1. Build and Test:
name: .NET CI on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: '5.0.x' - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal
2. Apply Migrations:
- name: Apply EF Migrations run: dotnet ef database update
3. Deploy to Azure App Service:
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
with:
app-name: 'YourAppName'
slot-name: 'production'
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
Additional Resources:
What Undercode Say:
Automating deployments with GitHub Actions is a powerful way to ensure that your .NET applications are always up-to-date and reduce manual intervention. By following the 3-step pipeline outlined above, you can build, test, and deploy your applications with confidence.
In addition to the provided YAML configurations, here are some useful commands and tips for managing your deployments:
- Check Application Logs:
az webapp log tail --name YourAppName --resource-group YourResourceGroup
-
Rollback a Deployment:
az webapp deployment source update --name YourAppName --resource-group YourResourceGroup --src-url https://github.com/YourRepo --branch previous-commit
-
Environment-Specific Configurations:
Use Azure Key Vault to manage environment-specific configurations securely:az keyvault secret set --vault-name YourKeyVault --name YourSecretName --value YourSecretValue
-
Database Rollback Strategies:
Implement a rollback strategy by creating a backup before applying migrations:sqlcmd -S YourServer -d YourDatabase -Q "BACKUP DATABASE YourDatabase TO DISK='YourBackupPath.bak'"
-
Review SQL Scripts:
To review the exact SQL executed by EF bundles, use the following command:dotnet ef migrations script --idempotent
By integrating these practices into your CI/CD pipeline, you can ensure a robust and reliable deployment process. For further reading, explore the provided URLs to deepen your understanding of GitHub Actions and Clean Architecture.
Conclusion:
Automating your deployment process with GitHub Actions not only saves time but also reduces the risk of human error. By leveraging the power of CI/CD, you can focus more on developing features and less on the intricacies of deployment. Remember to always have a rollback strategy in place and use environment-specific configurations to maintain consistency across different stages of your application lifecycle. Happy coding!
References:
Hackers Feeds, Undercode AI


