Wednesday, 3 August 2022

CI/CD with GitHub Actions to deploy Application to Azure App Service

 This is a follow up article of my previous article published here as CI/CD with GitHub Actions. There I was talking about basics of creating a GitHub action to automate project build and run tests.

"ConnectionStrings": {
"ConnectionString": "#{ConnectionString}#",
},

Note: Please follow my previous article if are new to GitHub Actions.

jobs:
build:
runs-on: windows-latest
environment: Production
steps:
- uses: actions/checkout@v2

- name: Replace token for appsettings.Production.json
uses: cschleiden/replace-tokens@v1.1
with:
tokenPrefix: '#{'
tokenSuffix: '}#'
files: '["src/DemoAPI/appsettings.Production.json"]'
env:
ConnectionString: ${{secrets.CONNECTION_STRING}}
      - name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
#include-prerelease: true

- name: Build projects
run: |
dotnet build src/DemoAPI/DemoAPI.sln --configuration Release

- name: Publish Project
run: |
dotnet publish src/DemoAPI/DemoAPI.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: .net-app
path: ./myapp
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: .net-app
path: upload_artifact
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'DemoAPI'
slot-name: 'production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: upload_artifact

No comments:

Post a Comment