From a73e042857d6777d72862110952bef865fb557d8 Mon Sep 17 00:00:00 2001 From: AJ Enns Date: Fri, 13 Sep 2024 12:58:10 -0500 Subject: [PATCH 1/2] Add Azure deployment workflows for dev, test, and prod environments --- .github/workflows/dotnet-deploy-1.yml | 63 ++++++++++++++++++- .../RazorPagesTestSample/Pages/Error.cshtml | 2 +- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet-deploy-1.yml b/.github/workflows/dotnet-deploy-1.yml index e5214a41..01e27b7c 100644 --- a/.github/workflows/dotnet-deploy-1.yml +++ b/.github/workflows/dotnet-deploy-1.yml @@ -60,4 +60,65 @@ jobs: run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath - name: Docker Push - run: docker push $registryName/$repositoryName:$tag \ No newline at end of file + run: docker push $registryName/$repositoryName:$tag + + deploy-to-dev: + + runs-on: ubuntu-latest + needs: dockerBuildPush + environment: + name: dev + url: https://mpplabajep-dev.azurewebsites.net/ + + steps: + - name: 'Login via Azure CLI' + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: 'mpplabajep-dev' + images: mpplabajep.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-test: + + runs-on: ubuntu-latest + needs: deploy-to-dev + environment: + name: test + url: https://mpplabajep-test.azurewebsites.net/ + + steps: + - uses: actions/checkout@v3 + + - name: 'Login via Azure CLI' + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: 'mpplabajep-test' + images: mpplabajep.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-prod: + + runs-on: ubuntu-latest + needs: deploy-to-test + environment: + name: prod + url: https://mpplabajep-prod.azurewebsites.net/ + + steps: + - uses: actions/checkout@v3 + + - name: 'Login via Azure CLI' + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: 'mpplabajep-prod' + images: mpplabajep.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} \ No newline at end of file diff --git a/src/Application/src/RazorPagesTestSample/Pages/Error.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Error.cshtml index 6f92b956..b34f2566 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Error.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Error.cshtml @@ -5,7 +5,7 @@ }

Error.

-

An error occurred while processing your request.

+

An error occurred while processing your request.

@if (Model.ShowRequestId) { From 7999f45ed923e9128c5683d098a68e76fa40fb75 Mon Sep 17 00:00:00 2001 From: AJ Enns Date: Fri, 13 Sep 2024 13:07:37 -0500 Subject: [PATCH 2/2] Refactor .NET CI workflow to support CI/CD; streamline paths and update .NET version handling --- .github/workflows/dotnet-deploy-1.yml | 81 +++++---------------------- 1 file changed, 14 insertions(+), 67 deletions(-) diff --git a/.github/workflows/dotnet-deploy-1.yml b/.github/workflows/dotnet-deploy-1.yml index 01e27b7c..1831f263 100644 --- a/.github/workflows/dotnet-deploy-1.yml +++ b/.github/workflows/dotnet-deploy-1.yml @@ -1,23 +1,19 @@ -name: .NET CI +name: .NET CI/CD -env: - registryName: mpplabajep.azurecr.io - repositoryName: techexcel/dotnetcoreapp - dockerFolderPath: ./src/Application/src/RazorPagesTestSample - tag: ${{github.run_number}} - on: push: branches: [ main ] - paths: src/Application/** + paths: + - src/Application/** pull_request: branches: [ main ] - paths: src/Application/** + paths: + - src/Application/** # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + jobs: build: - runs-on: ubuntu-latest steps: @@ -25,70 +21,22 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0 - + dotnet-version: '8.0.x' + - name: Restore dependencies - run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + run: dotnet restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj - name: Build - run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + run: dotnet build --no-restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj - name: Test - run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj - - dockerBuildPush: - - runs-on: ubuntu-latest - needs: build - - steps: - - uses: actions/checkout@v3 - - - name: Docker Login - # You may pin to the exact commit or the version. - # uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c - uses: docker/login-action@v1.9.0 - 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-dev: - - runs-on: ubuntu-latest - needs: dockerBuildPush - environment: - name: dev - url: https://mpplabajep-dev.azurewebsites.net/ - - steps: - - name: 'Login via Azure CLI' - uses: azure/login@v2.1.1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - uses: azure/webapps-deploy@v2 - with: - app-name: 'mpplabajep-dev' - images: mpplabajep.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + run: dotnet test --no-build --verbosity normal src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj deploy-to-test: - runs-on: ubuntu-latest - needs: deploy-to-dev + needs: build environment: name: test url: https://mpplabajep-test.azurewebsites.net/ - + steps: - uses: actions/checkout@v3 @@ -103,13 +51,12 @@ jobs: images: mpplabajep.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} deploy-to-prod: - runs-on: ubuntu-latest needs: deploy-to-test environment: name: prod url: https://mpplabajep-prod.azurewebsites.net/ - + steps: - uses: actions/checkout@v3