diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml deleted file mode 100644 index bb6154bb..00000000 --- a/.github/workflows/build-all.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: "Build - all" -on: - pull_request: - branches: [main] - -jobs: - build-api: - uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main - with: - solution_file: "src/Api/Company.Api.sln" - project_file: "src/Api/Company.Api/Company.Api.csproj" - dotnet_version: 7.0.302 - - build-website: - uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main - with: - solution_file: "src/Website/Company.Website.sln" - project_file: "src/Website/Company.Website/Company.Website.csproj" - dotnet_version: 7.0.302 diff --git a/.github/workflows/instance-deploy-prod.yml b/.github/workflows/instance-deploy-prod.yml index 108a21c9..c07990da 100644 --- a/.github/workflows/instance-deploy-prod.yml +++ b/.github/workflows/instance-deploy-prod.yml @@ -33,18 +33,20 @@ jobs: with: solution_file: "src/Api/Company.Api.sln" project_file: "src/Api/Company.Api/Company.Api.csproj" - dotnet_version: 7.0.302 - artifact_name: "api" - self_contained: false + dotnet_version: 8.0.203 + dockerfile_name: "src/Api/Company.Api/dockerfile" + image_name: "onlinestore-api" + secrets: inherit build-website: uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main with: solution_file: "src/Website/Company.Website.sln" project_file: "src/Website/Company.Website/Company.Website.csproj" - dotnet_version: 7.0.302 - artifact_name: "website" - self_contained: true + dotnet_version: 8.0.203 + dockerfile_name: "src/Website/Company.Website/dockerfile" + image_name: "onlinestore-website" + secrets: inherit deploy-terraform-prod: needs: [variables, build-api, build-website] @@ -95,10 +97,10 @@ jobs: - name: Save terraform outputs shell: bash run: | - terraform -chdir=instance output -raw web_app_api_name > web_app_api_name.txt - terraform -chdir=instance output -raw web_app_api_hostname > web_app_api_hostname.txt - terraform -chdir=instance output -raw web_app_website_name > web_app_website_name.txt - terraform -chdir=instance output -raw web_app_website_hostname > web_app_website_hostname.txt + terraform -chdir=instance output -raw resource_group_name > terraform-outputs/resource_group_name.txt + terraform -chdir=instance output -raw container_app_api_fqdn > terraform-outputs/container_app_api_fqdn.txt + terraform -chdir=instance output -raw container_app_website_fqdn > terraform-outputs/container_app_website_fqdn.txt + terraform -chdir=instance output -raw container_instance_monitoring_fqdn > terraform-outputs/container_instance_monitoring_fqdn.txt # -raw cannot handle null values - https://github.com/hashicorp/terraform/issues/32384 terraform -chdir=instance show -json | jq -r '.values.outputs.container_instance_monitoring_fqdn.value // ""' > container_instance_monitoring_fqdn.txt - name: Upload terraform outputs for deploy job @@ -122,34 +124,35 @@ jobs: id: vars shell: bash run: | - echo "web_app_api_name=$(cat web_app_api_name.txt)" >> $GITHUB_ENV - echo "web_app_api_hostname=$(cat web_app_api_hostname.txt)" >> $GITHUB_ENV - echo "web_app_website_name=$(cat web_app_website_name.txt)" >> $GITHUB_ENV - echo "web_app_website_hostname=$(cat web_app_website_hostname.txt)" >> $GITHUB_ENV + echo "resource_group_name=$(cat resource_group_name.txt)" >> $GITHUB_ENV + echo "container_app_api_fqdn=$(cat container_app_api_fqdn.txt)" >> $GITHUB_ENV + echo "container_app_website_fqdn=$(cat container_app_website_fqdn.txt)" >> $GITHUB_ENV echo "container_instance_monitoring_fqdn=$(cat container_instance_monitoring_fqdn.txt)" >> $GITHUB_ENV - - name: Download API package - uses: actions/download-artifact@v3 - with: - name: api - path: ${{ github.workspace }}/api - - name: Download website package - uses: actions/download-artifact@v3 - with: - name: website - path: ${{ github.workspace }}/website - - name: Update website config - run: echo "`jq '.Api.BasePath="https://${{ env.web_app_api_hostname }}"' ${{ github.workspace }}/website/wwwroot/appsettings.json`" > ${{ github.workspace }}/website/wwwroot/appsettings.json - name: Login via Azure CLI uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Run Azure webapp deploy for API - uses: azure/webapps-deploy@v2 + - name: Deploy api + uses: azure/container-apps-deploy-action@v1 with: - app-name: ${{ env.web_app_api_name }} - package: ${{ github.workspace }}/api - - name: Run Azure webapp deploy for website - uses: azure/webapps-deploy@v2 + acrName: onlinestorecontainerregistry + acrUsername: ${{ secrets.ACR_USERNAME }} + acrPassword: ${{ secrets.ACR_TOKEN }} + containerAppName: onlinestore-api + imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-api:${{ github.sha }} + location: 'East US' + resourceGroup: ${{ env.resource_group_name }} + targetPort: 8080 + environmentVariables: "OTLPEXPORTER__ENDPOINT=http://${{ env.container_instance_monitoring_fqdn }}:4317" + - name: Deploy website + uses: azure/container-apps-deploy-action@v1 with: - app-name: ${{ env.web_app_website_name }} - package: ${{ github.workspace }}/website + acrName: onlinestorecontainerregistry + acrUsername: ${{ secrets.ACR_USERNAME }} + acrPassword: ${{ secrets.ACR_TOKEN }} + containerAppName: onlinestore-website + imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-website:${{ github.sha }} + location: 'East US' + resourceGroup: ${{ env.resource_group_name }} + targetPort: 80 + environmentVariables: "API__BASEPATH=https://${{ env.container_app_api_fqdn }}" diff --git a/.github/workflows/instance-deploy-test.yml b/.github/workflows/instance-deploy-test.yml index 44500b09..d6132f79 100644 --- a/.github/workflows/instance-deploy-test.yml +++ b/.github/workflows/instance-deploy-test.yml @@ -5,22 +5,24 @@ on: jobs: build-api: - uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main + uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@containerise-apps with: solution_file: "src/Api/Company.Api.sln" project_file: "src/Api/Company.Api/Company.Api.csproj" - dotnet_version: 7.0.302 - artifact_name: "api" - self_contained: false + dotnet_version: 8.0.203 + dockerfile_name: "src/Api/Company.Api/dockerfile" + image_name: "onlinestore-api" + secrets: inherit build-website: - uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main + uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@containerise-apps with: solution_file: "src/Website/Company.Website.sln" project_file: "src/Website/Company.Website/Company.Website.csproj" - dotnet_version: 7.0.302 - artifact_name: "website" - self_contained: true + dotnet_version: 8.0.203 + dockerfile_name: "src/Website/Company.Website/dockerfile" + image_name: "onlinestore-website" + secrets: inherit deploy-terraform-test: needs: [build-api, build-website] @@ -72,10 +74,10 @@ jobs: shell: bash run: | mkdir terraform-outputs - terraform -chdir=instance output -raw web_app_api_name > terraform-outputs/web_app_api_name.txt - terraform -chdir=instance output -raw web_app_api_hostname > terraform-outputs/web_app_api_hostname.txt - terraform -chdir=instance output -raw web_app_website_name > terraform-outputs/web_app_website_name.txt - terraform -chdir=instance output -raw web_app_website_hostname > terraform-outputs/web_app_website_hostname.txt + terraform -chdir=instance output -raw resource_group_name > terraform-outputs/resource_group_name.txt + terraform -chdir=instance output -raw container_app_api_fqdn > terraform-outputs/container_app_api_fqdn.txt + terraform -chdir=instance output -raw container_app_website_fqdn > terraform-outputs/container_app_website_fqdn.txt + terraform -chdir=instance output -raw container_instance_monitoring_fqdn > terraform-outputs/container_instance_monitoring_fqdn.txt # -raw cannot handle null values - https://github.com/hashicorp/terraform/issues/32384 terraform -chdir=instance show -json | jq -r '.values.outputs.container_instance_monitoring_fqdn.value // ""' > container_instance_monitoring_fqdn.txt - name: Upload terraform outputs for deploy job @@ -99,39 +101,38 @@ jobs: id: vars shell: bash run: | - echo "web_app_api_name=$(cat web_app_api_name.txt)" >> $GITHUB_ENV - echo "web_app_api_hostname=$(cat web_app_api_hostname.txt)" >> $GITHUB_ENV - echo "web_app_website_name=$(cat web_app_website_name.txt)" >> $GITHUB_ENV - echo "web_app_website_hostname=$(cat web_app_website_hostname.txt)" >> $GITHUB_ENV + echo "resource_group_name=$(cat resource_group_name.txt)" >> $GITHUB_ENV + echo "container_app_api_fqdn=$(cat container_app_api_fqdn.txt)" >> $GITHUB_ENV + echo "container_app_website_fqdn=$(cat container_app_website_fqdn.txt)" >> $GITHUB_ENV echo "container_instance_monitoring_fqdn=$(cat container_instance_monitoring_fqdn.txt)" >> $GITHUB_ENV - - name: Download API package - uses: actions/download-artifact@v3 - with: - name: api - path: ${{ github.workspace }}/api - - name: Download website package - uses: actions/download-artifact@v3 - with: - name: website - path: ${{ github.workspace }}/website - - name: Update website config - run: echo "`jq '.Api.BasePath="https://${{ env.web_app_api_hostname }}"' ${{ github.workspace }}/website/wwwroot/appsettings.json`" > ${{ github.workspace }}/website/wwwroot/appsettings.json - name: Login via Azure CLI uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Run Azure webapp deploy for API - uses: azure/webapps-deploy@v2 - id: apideploy + - name: Deploy api + uses: azure/container-apps-deploy-action@v1 with: - app-name: ${{ env.web_app_api_name }} - package: ${{ github.workspace }}/api - - name: Run Azure webapp deploy for website - uses: azure/webapps-deploy@v2 - id: websitedeploy + acrName: onlinestorecontainerregistry + acrUsername: ${{ secrets.ACR_USERNAME }} + acrPassword: ${{ secrets.ACR_TOKEN }} + containerAppName: onlinestore-api + imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-api:${{ github.sha }} + location: 'East US' + resourceGroup: ${{ env.resource_group_name }} + targetPort: 8080 + environmentVariables: "OTLPEXPORTER__ENDPOINT=http://${{ env.container_instance_monitoring_fqdn }}:4317" + - name: Deploy website + uses: azure/container-apps-deploy-action@v1 with: - app-name: ${{ env.web_app_website_name }} - package: ${{ github.workspace }}/website + acrName: onlinestorecontainerregistry + acrUsername: ${{ secrets.ACR_USERNAME }} + acrPassword: ${{ secrets.ACR_TOKEN }} + containerAppName: onlinestore-website + imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-website:${{ github.sha }} + location: 'East US' + resourceGroup: ${{ env.resource_group_name }} + targetPort: 80 + environmentVariables: "API__BASEPATH=https://${{ env.container_app_api_fqdn }}" - name: Post test environment information on PR uses: actions/github-script@0.9.0 if: github.event_name == 'pull_request' @@ -141,8 +142,8 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const output = `### Test environment information - #### 🔗[Visit website](https://${{ env.web_app_website_hostname }}/) - #### 🔗[Visit API](https://${{ env.web_app_api_hostname }}/swagger/) + #### 🔗[Visit website](https://${{ env.container_app_website_fqdn }}/) + #### 🔗[Visit API](https://${{ env.container_app_api_fqdn }}/swagger/) #### 🔗[Visit monitoring UI](http://${{ env.container_instance_monitoring_fqdn }}:16686) *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; diff --git a/.github/workflows/permanent-image-import.yml b/.github/workflows/permanent-image-import.yml index 80f8cafe..352b75a4 100644 --- a/.github/workflows/permanent-image-import.yml +++ b/.github/workflows/permanent-image-import.yml @@ -20,15 +20,15 @@ jobs: - name: Login to ACR uses: docker/login-action@v2 with: - registry: ${{ github.event.inputs.target_acr }} + registry: ${{ inputs.target_acr }} username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_TOKEN }} - name: Pull image run: | - docker pull docker.io/${{ github.event.inputs.image }} + docker pull docker.io/${{ inputs.image }} - name: Re-tag image run: | - docker tag docker.io/${{ github.event.inputs.image }} ${{ github.event.inputs.target_acr }}/${{ github.event.inputs.image }} + docker tag docker.io/${{ inputs.image }} ${{ inputs.target_acr }}/${{ inputs.image }} - name: Publish image run: | - docker push ${{ github.event.inputs.target_acr }}/${{ github.event.inputs.image }} \ No newline at end of file + docker push ${{ inputs.target_acr }}/${{ inputs.image }} \ No newline at end of file diff --git a/.github/workflows/workflow-build-test-publish-dotnet.yml b/.github/workflows/workflow-build-test-publish-dotnet.yml index 0e0e04a7..0bfaf3fe 100644 --- a/.github/workflows/workflow-build-test-publish-dotnet.yml +++ b/.github/workflows/workflow-build-test-publish-dotnet.yml @@ -13,8 +13,17 @@ on: type: string self_contained: type: boolean + default: true artifact_name: type: string + dockerfile_name: + type: string + default: . + image_name: + type: string + target_acr: + type: string + default: onlinestorecontainerregistry.azurecr.io jobs: build-test: @@ -32,7 +41,7 @@ jobs: run: dotnet build ${{ inputs.solution_file }} --configuration Release --no-restore - name: Test run: dotnet test ${{ inputs.solution_file }} --configuration Release --no-build --verbosity normal - - name: Publish + - name: Publish binaries if: ${{ inputs.artifact_name != null }} run: dotnet publish ${{ inputs.project_file }} --configuration Release --no-build --output publish/${{ inputs.artifact_name }} --self-contained ${{ inputs.self_contained }} - name: Publish artifact @@ -41,3 +50,13 @@ jobs: with: name: ${{ inputs.artifact_name }} path: publish/${{ inputs.artifact_name }} + - name: Build and push image + if: ${{ inputs.image_name != null }} + uses: docker/login-action@v2 + with: + registry: ${{ inputs.target_acr }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_TOKEN }} + - run: | + docker image build --file ${{ inputs.dockerfile_name }} --tag ${{ inputs.target_acr }}/${{ inputs.image_name }}:${{ github.sha }} . + docker push ${{ inputs.target_acr }}/${{ inputs.image_name }}:${{ github.sha }} diff --git a/.gitignore b/.gitignore index 3105f6a6..21c491a0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ bld/ # Visual Studio 2015/2017 cache/options directory .vs/ + +# Rider directiry +.idea/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ diff --git a/README.md b/README.md index 992df073..2df8d35b 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,10 @@ The GitHub runner needs to connect to Azure Storage (Terraform state file) and o 2. (powershell) Get your subscription id (`az account list`). 3. (powershell) Specify which subscription you want to use (`az account set --subscription="SUBSCRIPTION_ID"`). 4. (powershell) Create the service principal in the 'Online Store' subscription (`az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/SUBSCRIPTION_ID" --sdk-auth`). This will output some JSON that the runner will use to log into Azure (stored in repo secret `AZURE_CREDENTIALS`). In addition, the following repository secrets should be extracted from this JSON (which are needed for terraform steps): - * *appId* - `TF_VAR_AGENT_CLIENT_ID` - * *password* - `TF_VAR_AGENT_CLIENT_SECRET` - * *tenant* - `TF_VAR_TENANT_ID` + * *subscriptionId* + * *clientId* - `TF_VAR_AGENT_CLIENT_ID` + * *clientSecret* - `TF_VAR_AGENT_CLIENT_SECRET` + * *tenantId* - `TF_VAR_TENANT_ID` For more information, read ['Azure Provider: Authenticating using a Service Principal with a Client Secret'](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret). diff --git a/src/Api/Company.Api.Tests/Company - Backup.Api.Tests.csproj b/src/Api/Company.Api.Tests/Company - Backup.Api.Tests.csproj index 4f6e904f..7ea9d4f9 100644 --- a/src/Api/Company.Api.Tests/Company - Backup.Api.Tests.csproj +++ b/src/Api/Company.Api.Tests/Company - Backup.Api.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 false diff --git a/src/Api/Company.Api.Tests/Company.Api.Tests.csproj b/src/Api/Company.Api.Tests/Company.Api.Tests.csproj index 5c2d65cf..2cf9fee6 100644 --- a/src/Api/Company.Api.Tests/Company.Api.Tests.csproj +++ b/src/Api/Company.Api.Tests/Company.Api.Tests.csproj @@ -1,20 +1,20 @@  - net7.0 + net8.0 false - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Api/Company.Api/Company.Api.csproj b/src/Api/Company.Api/Company.Api.csproj index 40b07902..78f0ffac 100644 --- a/src/Api/Company.Api/Company.Api.csproj +++ b/src/Api/Company.Api/Company.Api.csproj @@ -1,22 +1,22 @@ - net7.0 + net8.0 0.0.1 - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + + diff --git a/src/Api/Company.Api/dockerfile b/src/Api/Company.Api/dockerfile new file mode 100644 index 00000000..60148a42 --- /dev/null +++ b/src/Api/Company.Api/dockerfile @@ -0,0 +1,17 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env +WORKDIR /app + +COPY . . + +WORKDIR "/app/src/Api/Company.Api" +RUN dotnet restore "Company.Api.csproj" +RUN dotnet publish "Company.Api.csproj" -c Release -o /app/out + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +WORKDIR /app + +COPY --from=build-env /app/out . + +EXPOSE 8080 + +ENTRYPOINT ["dotnet", "Company.Api.dll"] diff --git a/src/Shared/Company.Contract/Company.Contract.csproj b/src/Shared/Company.Contract/Company.Contract.csproj index cfadb03d..30402ac0 100644 --- a/src/Shared/Company.Contract/Company.Contract.csproj +++ b/src/Shared/Company.Contract/Company.Contract.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/src/Website/Company.Website.Components/Company.Website.Components.csproj b/src/Website/Company.Website.Components/Company.Website.Components.csproj index b9982641..16ea3c31 100644 --- a/src/Website/Company.Website.Components/Company.Website.Components.csproj +++ b/src/Website/Company.Website.Components/Company.Website.Components.csproj @@ -1,12 +1,12 @@ - net7.0 + net8.0 - - + + diff --git a/src/Website/Company.Website/Company.Website.csproj b/src/Website/Company.Website/Company.Website.csproj index 5bda4d6a..0e1802e3 100644 --- a/src/Website/Company.Website/Company.Website.csproj +++ b/src/Website/Company.Website/Company.Website.csproj @@ -1,18 +1,18 @@ - net7.0 + net8.0 service-worker-assets.js - - - - - - - + + + + + + + @@ -24,8 +24,4 @@ - - - - diff --git a/src/Website/Company.Website/dockerfile b/src/Website/Company.Website/dockerfile new file mode 100644 index 00000000..e011a6f1 --- /dev/null +++ b/src/Website/Company.Website/dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env +WORKDIR /app + +COPY . . + +WORKDIR "/app/src/Website/Company.Website" +RUN dotnet restore "Company.Website.csproj" +RUN dotnet publish "Company.Website.csproj" -c Release -o /app/out + +FROM nginx:alpine AS runtime +WORKDIR /var/www/web + +RUN apk add jq + +COPY --from=build-env /app/out/wwwroot . +COPY /src/Website/Company.Website/nginx.conf /etc/nginx/nginx.conf +COPY /src/Website/Company.Website/overwrite-config.sh /docker-entrypoint.d/overwrite-config.sh +RUN chmod +x /docker-entrypoint.d/overwrite-config.sh + +EXPOSE 80 diff --git a/src/Website/Company.Website/nginx.conf b/src/Website/Company.Website/nginx.conf new file mode 100644 index 00000000..afa559a6 --- /dev/null +++ b/src/Website/Company.Website/nginx.conf @@ -0,0 +1,15 @@ +events { } + http { + include mime.types; + types { + application/wasm wasm; + } + server { + listen 80; + index index.html; + location / { + root /var/www/web; + try_files $uri $uri/ /index.html =404; + } + } +} diff --git a/src/Website/Company.Website/overwrite-config.sh b/src/Website/Company.Website/overwrite-config.sh new file mode 100644 index 00000000..5baf07cb --- /dev/null +++ b/src/Website/Company.Website/overwrite-config.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "`jq --arg APIBASEPATH "$API__BASEPATH" '.Api.BasePath=$APIBASEPATH' /var/www/web/appsettings.json`" > /var/www/web/appsettings.json diff --git a/src/Website/Company.Website/wwwroot/appsettings.json b/src/Website/Company.Website/wwwroot/appsettings.json index cedfa352..c251455d 100644 --- a/src/Website/Company.Website/wwwroot/appsettings.json +++ b/src/Website/Company.Website/wwwroot/appsettings.json @@ -1,5 +1,5 @@ { "Api": { - "BasePath": "gha-replace-me" + "BasePath": "replace-me" } } diff --git a/terraform/instance/.terraform.lock.hcl b/terraform/instance/.terraform.lock.hcl index 6fba039b..ba46f512 100644 --- a/terraform/instance/.terraform.lock.hcl +++ b/terraform/instance/.terraform.lock.hcl @@ -2,21 +2,21 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/azurerm" { - version = "3.42.0" - constraints = "3.42.0" + version = "3.109.0" + constraints = "3.109.0" hashes = [ - "h1:HY0I9i8l11AhaAeKM/TDXneNAb4RIqrG4YPIC71fq30=", - "zh:15b1fb70cbcb43ea0f15985643c71ca167bca170448d3bfe9936f87ef6c9adca", - "zh:26a8b81031b7cb53625f6ac751ba93affbd87b7fc09d69b57f5d9264a8be9ec7", - "zh:3dbf6f6d4de8cf9333de371f7a2f7e9424b445ee5028eba6801fb370ae40de1f", - "zh:7344037970ce197004ba43cfa9b9008a9145f65ace4999e8b2634e347cab63da", - "zh:76715723eb6c0849f8b7b4ff7410a795bc718ef562e15abe6adc7929bc3ce166", - "zh:a4d22e8005932be9a4f1a8182f07bba78597141b0ba84bb3cdd8ba2235d95d32", - "zh:a5af12badf44d005b80bd78183b1d4826b553f41f37beb7a6640b931902a1dd8", - "zh:bd4a1b1bc040a40bafae4c61098dc71c5ca434b0fa48c53c4936e13be21d3a56", - "zh:ccc2a2ee68d1e20a731de145cea16d0c5887c9976d472c66ad1d7ecf1b16fa91", - "zh:edc0abb51f8815dccae847caa3a8f82ac02e6eef3e64960e98a5a657e34df9eb", - "zh:f3187788996d113ce9f926c7933cef2725b9a90399a5ce581760af34b477e930", + "h1:Fk7L51TM48PIqPlmSjja7iiEL0w5mmfOimWfMsthhLU=", + "zh:4324c3df26709c7e669b751259cc5e62c4694ab44370dfcdfe197dcd9261c365", + "zh:4e3e83649240cea7105cd2802d0ae64b143fb543c2f559173feae5a108bc4287", + "zh:74ebf6be1277e9bd357b011026b80fc5ec1c26b70ec7ddd5fcae5e977f9a66ef", + "zh:82cfd3c92035f834a05f4b91d813a059a29ff4157792e36a0b3a224cba8737ae", + "zh:93f05c8ae3555c885c84b82781b2e90774671c321138b7f3c38ecd498009e1d8", + "zh:9b445a9a1544b4b38db10fadbd9ffd5efdded0def54feb9ca593e1bec6fbec5f", + "zh:b21ccd2c1bc691cf2f9876482b6e226d8a37a48de951b168a10f96ba929ebefd", + "zh:b7b7e458eb3c22669e1d36e9ef1886272c10f310501001abce8ae76383014fa5", + "zh:bd3c0cf7caab0a989227934bc60a8ac27131efcf84dd77cb6e32e68374170aee", + "zh:f4b9ccbb28eadf3825f6d7d38a3519379de222f136235a2f21a96c0221d65fb8", "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:f8ef0b4a970ff5edeadfdeed77f9d0682befdca5df4e9b6d9dcfdf9903305b26", ] } diff --git a/terraform/instance/container_apps.tf b/terraform/instance/container_apps.tf new file mode 100644 index 00000000..952e1883 --- /dev/null +++ b/terraform/instance/container_apps.tf @@ -0,0 +1,75 @@ +resource "azurerm_container_app_environment" "apps" { + name = "${var.name}-containerapps" + resource_group_name = azurerm_resource_group.instance.name + location = azurerm_resource_group.instance.location +} + +resource "azurerm_container_app" "api" { + name = "${var.name}-api" + container_app_environment_id = azurerm_container_app_environment.apps.id + resource_group_name = azurerm_resource_group.instance.name + revision_mode = "Single" + + template { + container { + name = "onlinestore-api" + image = "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest" + cpu = 0.25 + memory = "0.5Gi" + } + max_replicas = 1 + } + + ingress { + external_enabled = true + transport = "http" + target_port = 8080 + traffic_weight { + latest_revision = true + percentage = 100 + } + } + + lifecycle { + ignore_changes = [ + template[0].container[0], + registry, + secret, + ] + } +} + +resource "azurerm_container_app" "website" { + name = "${var.name}-website" + container_app_environment_id = azurerm_container_app_environment.apps.id + resource_group_name = azurerm_resource_group.instance.name + revision_mode = "Single" + + template { + container { + name = "onlinestore-website" + image = "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest" + cpu = 0.25 + memory = "0.5Gi" + } + max_replicas = 1 + } + + ingress { + external_enabled = true + transport = "http" + target_port = 80 + traffic_weight { + latest_revision = true + percentage = 100 + } + } + + lifecycle { + ignore_changes = [ + template[0].container[0], + registry, + secret, + ] + } +} diff --git a/terraform/instance/main.tf b/terraform/instance/main.tf index 03830121..d8257b68 100644 --- a/terraform/instance/main.tf +++ b/terraform/instance/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "=3.42.0" + version = "=3.109.0" } } backend "azurerm" { @@ -24,23 +24,18 @@ resource "azurerm_resource_group" "instance" { location = var.location } -output "web_app_api_name" { - value = azurerm_windows_web_app.api.name +output "resource_group_name" { + value = azurerm_resource_group.instance.name sensitive = false } -output "web_app_api_hostname" { - value = azurerm_windows_web_app.api.default_hostname +output "container_app_api_fqdn" { + value = azurerm_container_app.api.ingress[0].fqdn sensitive = false } -output "web_app_website_name" { - value = azurerm_windows_web_app.website.name - sensitive = false -} - -output "web_app_website_hostname" { - value = azurerm_windows_web_app.website.default_hostname +output "container_app_website_fqdn" { + value = azurerm_container_app.website.ingress[0].fqdn sensitive = false } diff --git a/terraform/instance/web_apps.tf b/terraform/instance/web_apps.tf deleted file mode 100644 index f9f75425..00000000 --- a/terraform/instance/web_apps.tf +++ /dev/null @@ -1,58 +0,0 @@ -resource "azurerm_service_plan" "windows" { - name = "${var.name}-plan-windows" - resource_group_name = azurerm_resource_group.instance.name - location = azurerm_resource_group.instance.location - os_type = "Windows" - sku_name = var.plan_sku -} - -resource "azurerm_windows_web_app" "api" { - name = "${var.dns_prefix}-${var.name}-${var.environment}-api" - resource_group_name = azurerm_resource_group.instance.name - location = azurerm_resource_group.instance.location - service_plan_id = azurerm_service_plan.windows.id - - identity { - type = "SystemAssigned" - } - - site_config { - default_documents = ["index.html"] // swagger - always_on = false // free tier - application_stack { - current_stack = "dotnet" - dotnet_version = "v7.0" - } - } - - app_settings = { - OTLPEXPORTER__ENDPOINT = var.monitoring_enabled ? "http://${azurerm_container_group.monitoring[0].fqdn}:4317" : null - } -} - -resource "azurerm_windows_web_app" "website" { - name = "${var.dns_prefix}-${var.name}-${var.environment}-website" - resource_group_name = azurerm_resource_group.instance.name - location = azurerm_resource_group.instance.location - service_plan_id = azurerm_service_plan.windows.id - - # Should the app service send session affinity cookies? - client_affinity_enabled = false - - identity { - type = "SystemAssigned" - } - - site_config { - default_documents = ["index.html"] - always_on = false // free tier - application_stack { - current_stack = "dotnet" - dotnet_version = "v7.0" - } - } - - app_settings = { - // environment variables for service - } -}