From 686d928d90003c3787e4fc33358dbc626bc28fe9 Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Tue, 10 Sep 2024 13:37:08 +0200 Subject: [PATCH 1/8] Remove pages YAML file --- .github/workflows/pages.yml | 62 ------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml deleted file mode 100644 index cedae546..00000000 --- a/.github/workflows/pages.yml +++ /dev/null @@ -1,62 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# Sample workflow for building and deploying a Jekyll site to GitHub Pages -name: Deploy Jekyll site to Pages - -on: - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - # Build job - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.1' # Not needed with a .ruby-version file - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - cache-version: 0 # Increment this number if you need to re-download cached gems - - name: Setup Pages - id: pages - uses: actions/configure-pages@v2 - - name: Build with Jekyll - # Outputs to the './_site' directory by default - run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" - env: - JEKYLL_ENV: production - - name: Upload artifact - # Automatically uploads an artifact from the './_site' directory by default - uses: actions/upload-pages-artifact@v1 - - # Deployment job - deploy: - environment: - name: github-pages - url: "${{ steps.deployment.outputs.page_url }}" - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 From d999660d94126c8548514296cbca78c68eccaee6 Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 11:31:55 +0200 Subject: [PATCH 2/8] actions --- .github/workflows/deploy.yml | 35 +++++++++++ src/InfrastructureAsCode/main.bicep | 92 ++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..fb6905d0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,35 @@ +name: Azure Bicep + +on: + workflow_dispatch + +env: + targetEnv: dev + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + steps: + # Checkout code + - uses: actions/checkout@main + + # Log into Azure + - uses: azure/login@v2.1.1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + + # Deploy ARM template + - name: Run ARM deploy + uses: azure/arm-deploy@v1 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + resourceGroupName: ${{ secrets.AZURE_RG }} + template: ./src/InfrastructureAsCode/main.bicep + parameters: environment=${{ env.targetEnv }} \ No newline at end of file diff --git a/src/InfrastructureAsCode/main.bicep b/src/InfrastructureAsCode/main.bicep index 6dc69618..60943d22 100644 --- a/src/InfrastructureAsCode/main.bicep +++ b/src/InfrastructureAsCode/main.bicep @@ -8,10 +8,98 @@ var webAppName = '${uniqueString(resourceGroup().id)}-${environment}' var appServicePlanName = '${uniqueString(resourceGroup().id)}-mpnp-asp' var logAnalyticsName = '${uniqueString(resourceGroup().id)}-mpnp-la' var appInsightsName = '${uniqueString(resourceGroup().id)}-mpnp-ai' -var sku = 'S1' +var sku = 'P0V3' var registryName = '${uniqueString(resourceGroup().id)}mpnpreg' var registrySku = 'Standard' var imageName = 'techexcel/dotnetcoreapp' var startupCommand = '' -// TODO: complete this script + +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' = { + name: logAnalyticsName + location: location + properties: { + sku: { + name: 'PerGB2018' + } + retentionInDays: 90 + workspaceCapping: { + dailyQuotaGb: 1 + } + } +} + +resource appInsights 'Microsoft.Insights/components@2020-02-02' = { + name: appInsightsName + location: location + kind: 'web' + properties: { + Application_Type: 'web' + WorkspaceResourceId: logAnalyticsWorkspace.id + } +} + +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-11-01-preview' = { + name: registryName + location: location + sku: { + name: registrySku + } + properties: { + adminUserEnabled: true + } +} + +resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = { + name: appServicePlanName + location: location + kind: 'linux' + properties: { + reserved: true + } + sku: { + name: sku + } +} + +resource appServiceApp 'Microsoft.Web/sites@2023-12-01' = { + name: webAppName + location: location + properties: { + serverFarmId: appServicePlan.id + httpsOnly: true + clientAffinityEnabled: false + siteConfig: { + linuxFxVersion: 'DOCKER|${containerRegistry.name}.azurecr.io/${uniqueString(resourceGroup().id)}/${imageName}' + http20Enabled: true + minTlsVersion: '1.2' + appCommandLine: startupCommand + appSettings: [ + { + name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE' + value: 'false' + } + { + name: 'DOCKER_REGISTRY_SERVER_URL' + value: 'https://${containerRegistry.name}.azurecr.io' + } + { + name: 'DOCKER_REGISTRY_SERVER_USERNAME' + value: containerRegistry.name + } + { + name: 'DOCKER_REGISTRY_SERVER_PASSWORD' + value: containerRegistry.listCredentials().passwords[0].value + } + { + name: 'APPINSIGHTS_INSTRUMENTATIONKEY' + value: appInsights.properties.InstrumentationKey + } + ] + } + } +} + +output application_name string = appServiceApp.name +output application_url string = appServiceApp.properties.hostNames[0] +output container_registry_name string = containerRegistry.name From 94a25b538d9458017fbb9720460838bced57b86a Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 11:42:57 +0200 Subject: [PATCH 3/8] deploy --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fb6905d0..870e0761 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Azure Bicep +name: Azure Bicep-Team3 on: workflow_dispatch From 3d26a72bd56299bc8e4768f7773fa85691d6a6fb Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 11:53:05 +0200 Subject: [PATCH 4/8] ci-cd --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 870e0761..fb6905d0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Azure Bicep-Team3 +name: Azure Bicep on: workflow_dispatch From c64640403bd85c146f3ac1b8d2adbbac70093103 Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 12:27:08 +0200 Subject: [PATCH 5/8] docker deploy --- .github/workflows/dotnet-deploy-3.yml | 125 ++++++++++++++++++ .../src/RazorPagesTestSample/Dockerfile | 18 +++ 2 files changed, 143 insertions(+) create mode 100644 .github/workflows/dotnet-deploy-3.yml create mode 100644 src/Application/src/RazorPagesTestSample/Dockerfile diff --git a/.github/workflows/dotnet-deploy-3.yml b/.github/workflows/dotnet-deploy-3.yml new file mode 100644 index 00000000..ea1f6726 --- /dev/null +++ b/.github/workflows/dotnet-deploy-3.yml @@ -0,0 +1,125 @@ +name: .NET CI + +env: + registryName: pgtechexcelteam03.azurecr.io + repositoryName: techexcel/dotnetcoreapp + dockerFolderPath: ./src/Application/src/RazorPagesTestSample + my_prefix: pgtechexcelteam03 + my_registry_name: pgtechexcelteam03 + tag: ${{github.run_number}} + +on: + push: + branches: [ main, ci-cd ] + paths: src/Application/** + pull_request: + branches: [ main, ci-cd ] + paths: src/Application/** + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0 + + - name: Restore dependencies + run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + - name: Build + 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://${my_prefix}-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: '{my_prefix}-dev' + images: ${my_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-test: + + runs-on: ubuntu-latest + needs: deploy-to-dev + environment: + name: test + url: https://${my_prefix}-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: '${my_prefix}-test' + images: ${my_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-prod: + + runs-on: ubuntu-latest + needs: deploy-to-test + environment: + name: prod + url: https://${my_prefix}-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: '{your_prefix}-prod' + images: ${my_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} \ No newline at end of file diff --git a/src/Application/src/RazorPagesTestSample/Dockerfile b/src/Application/src/RazorPagesTestSample/Dockerfile new file mode 100644 index 00000000..ab3fcaf2 --- /dev/null +++ b/src/Application/src/RazorPagesTestSample/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +WORKDIR /app +COPY --from=build-env /app/out . +# Default ASP.NET port changed with .NET 8.0 +ENV ASPNETCORE_HTTP_PORTS=80 +ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"] \ No newline at end of file From 3f348416b0a9ad20e202a399a313bd4e80ca2442 Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 12:36:44 +0200 Subject: [PATCH 6/8] deploy added --- .github/workflows/dotnet-deploy-3.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet-deploy-3.yml b/.github/workflows/dotnet-deploy-3.yml index ea1f6726..db301a25 100644 --- a/.github/workflows/dotnet-deploy-3.yml +++ b/.github/workflows/dotnet-deploy-3.yml @@ -1,11 +1,11 @@ name: .NET CI env: - registryName: pgtechexcelteam03.azurecr.io + registryName: 5trwfn2pltpqempnpreg.azurecr.io repositoryName: techexcel/dotnetcoreapp dockerFolderPath: ./src/Application/src/RazorPagesTestSample - my_prefix: pgtechexcelteam03 - my_registry_name: pgtechexcelteam03 + my_prefix: 5trwfn2pltpqempnpreg + my_registry_name: 5trwfn2pltpqempnpreg tag: ${{github.run_number}} on: From baee2c905d0eef0c3058d0a3332253c29d70c195 Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 12:42:54 +0200 Subject: [PATCH 7/8] file added --- .github/workflows/dotnet-deploy-3.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-deploy-3.yml b/.github/workflows/dotnet-deploy-3.yml index db301a25..859649f3 100644 --- a/.github/workflows/dotnet-deploy-3.yml +++ b/.github/workflows/dotnet-deploy-3.yml @@ -1,4 +1,4 @@ -name: .NET CI +name: .NET CI with Docker env: registryName: 5trwfn2pltpqempnpreg.azurecr.io From aecda06aefd6a7ddfd106fb0877778bc0c2a1abd Mon Sep 17 00:00:00 2001 From: Pinaki Ghatak Date: Wed, 11 Sep 2024 12:44:27 +0200 Subject: [PATCH 8/8] file added --- .github/workflows/{dotnet-deploy-3.yml => deploywithdocker.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{dotnet-deploy-3.yml => deploywithdocker.yml} (100%) diff --git a/.github/workflows/dotnet-deploy-3.yml b/.github/workflows/deploywithdocker.yml similarity index 100% rename from .github/workflows/dotnet-deploy-3.yml rename to .github/workflows/deploywithdocker.yml