Skip to content

Workflow file for this run

name: API Deployment
env:
registryName: qjektyorvoprmcosureg.azurecr.io
repositoryName: techexcel/csapi
dockerFolderPath: ./src/ContosoSuitesWebAPI
tag: ${{github.run_number}}
on:
push:
branches: [ main ]
paths: src/ContosoSuitesWebAPI/**
pull_request:
branches: [ main ]
paths: src/ContosoSuitesWebAPI/**
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0
- name: Restore dependencies
run: dotnet restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj
- name: Build
run: dotnet build --no-restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj
dockerBuildPush:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@v3
with:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ${{ secrets.ACR_LOGIN_SERVER }}
# Username used to log against the Docker registry
username: ${{ secrets.ACR_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.ACR_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true
- name: Docker Build
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath
- name: Docker Push
run: docker push $registryName/$repositoryName:$tag
deploy-to-prod:
runs-on: ubuntu-latest
needs: dockerBuildPush
environment:
name: prod
url: https://qjektyorvoprm-api.azurewebsites.net/
steps:
- uses: actions/checkout@v4
- name: 'Login via Azure CLI'
uses: azure/login@v2.1.1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/webapps-deploy@v2
with:
app-name: 'qjektyorvoprm-api'
images: qjektyorvoprmcosureg.azurecr.io/techexcel/csapi:${{github.run_number}}