diff --git a/.github/workflows/deploy-infra-and-apps.yml b/.github/workflows/deploy-infra-and-apps.yml new file mode 100644 index 00000000..6d1ea41d --- /dev/null +++ b/.github/workflows/deploy-infra-and-apps.yml @@ -0,0 +1,114 @@ +on: + push: + tags: + - 'v[0-9].[0-9].[0-9]' + workflow_dispatch: + +permissions: + # Require write permission to Fetch an OIDC token (required for federated credential) and write it + # It will be automatically used on actions / cli that needs it + id-token: write + +env: + AZURE_RG_NAME: rg-${{ vars.PROJECT_NAME }}-${{ vars.AZURE_RESOURCE_IDENTIFIER }} + +jobs: + deploy_infrastructure: + runs-on: ubuntu-latest + environment: production + + outputs: + appServiceName: ${{ steps.bicep_deploy.outputs.appServiceName }} + staticWebAppName: ${{ steps.bicep_deploy.outputs.staticWebAppName }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + + - name: Create resource group if not exists + run: | + az group show --name ${{ env.AZURE_RG_NAME }} || + az group create --name ${{ env.AZURE_RG_NAME }} --location ${{ secrets.AZURE_REGION }} + + - name: Deploy bicep + id: bicep_deploy + uses: azure/arm-deploy@v2 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }} + region: ${{ secrets.AZURE_REGION }} + template: ./infrastructure/main.bicep + parameters: project=${{ vars.PROJECT_NAME }} location=${{ secrets.AZURE_REGION }} swaLocation=${{ secrets.AZURE_SWA_REGION }} identifier=${{ vars.AZURE_RESOURCE_IDENTIFIER }} + resourceGroupName: ${{ env.AZURE_RG_NAME }} + + deploy_backend: + runs-on: ubuntu-latest + needs: deploy_infrastructure + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET SDK 9.0.x + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Publish the app + run: dotnet publish -c Release --property:PublishDir=publish # Publish the app to the API project publish folder + working-directory: ./backend # Specify where to find the solution file in repository + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Deploy backend to App Service + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ needs.deploy_infrastructure.outputs.appServiceName }} # Access to the previous job output to get the appServiceName deployed with bicep + package: ./backend/ParkNDeploy.Api/publish # Path to the previously published app + + deploy_frontend: + runs-on: ubuntu-latest + needs: deploy_infrastructure + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build the app + run: npm install && npm run build + working-directory: ./frontend + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Get Static Web App deployment token + run: | + SWA_DEPLOYMENT_TOKEN=$(az staticwebapp secrets list -n ${{ needs.deploy_infrastructure.outputs.staticWebAppName }} -o tsv --query properties.apiKey) + echo SWA_DEPLOYMENT_TOKEN=$SWA_DEPLOYMENT_TOKEN >> $GITHUB_ENV + + - name: Deploy frontend to Static Web App + uses: azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ env.SWA_DEPLOYMENT_TOKEN }} + app_location: frontend/dist + action: upload + skip_app_build: true + skip_api_build: true \ No newline at end of file diff --git a/.github/workflows/merge-request.yml b/.github/workflows/merge-request.yml new file mode 100644 index 00000000..8d069fe0 --- /dev/null +++ b/.github/workflows/merge-request.yml @@ -0,0 +1,41 @@ +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + id-token: write + +jobs: + build_react_app: + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build the app + run: npm install && npm run build + working-directory: ./frontend + + - name: linting script + run: npm run lint + working-directory: ./frontend + + + build_backend: + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET SDK 9.0.x + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Publish the app + run: dotnet publish -c Release --property:PublishDir=publish + working-directory: ./backend diff --git a/backend/Backup/ParkNDeploy.sln b/backend/Backup/ParkNDeploy.sln new file mode 100644 index 00000000..ad74ef9f --- /dev/null +++ b/backend/Backup/ParkNDeploy.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParkNDeploy.Api", "ParkNDeploy.Api\ParkNDeploy.Api.csproj", "{20032B6D-23C2-4CE2-A4F7-0D1E8C477FBD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {20032B6D-23C2-4CE2-A4F7-0D1E8C477FBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20032B6D-23C2-4CE2-A4F7-0D1E8C477FBD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20032B6D-23C2-4CE2-A4F7-0D1E8C477FBD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20032B6D-23C2-4CE2-A4F7-0D1E8C477FBD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {456BA43D-278C-4316-ADEC-FD2A2C8C5A75} + EndGlobalSection +EndGlobal diff --git a/backend/UpgradeLog.htm b/backend/UpgradeLog.htm new file mode 100644 index 00000000..0db19cf1 --- /dev/null +++ b/backend/UpgradeLog.htm @@ -0,0 +1,275 @@ + + + + Rapport de migration +

+ Rapport de migration - ParkNDeploy

Vue d'ensemble

ProjetChemin d'accèsErreursAvertissementsMessages
SolutionParkNDeploy.sln012
ParkNDeploy.ApiParkNDeploy.Api\ParkNDeploy.Api.csproj000

Solution et projets

Solution

Message
ParkNDeploy.sln: + Visual Studio doit apporter des changements non fonctionnels à ce projet pour lui permettre de s'ouvrir dans les versions Release de Visual Studio postérieures à Visual Studio 2010 SP1 sans affecter le comportement du projet.
+ Afficher 2 messages supplémentaires +
ParkNDeploy.sln: + Fichier sauvegardé en tant que C:\Users\theop\Documents\THEO\POLYTECH\5A\gestion_projet\TP_devops\parkndeploy\backend\Backup\ParkNDeploy.sln
ParkNDeploy.sln: + Solution migrée
+ Masquer 2 messages supplémentaires +

ParkNDeploy.Api

Message
ParkNDeploy.Api n'a consigné aucun message dans le journal. +
\ No newline at end of file diff --git a/infrastructure/main.bicep b/infrastructure/main.bicep new file mode 100644 index 00000000..1ccbd9d3 --- /dev/null +++ b/infrastructure/main.bicep @@ -0,0 +1,54 @@ +targetScope = 'resourceGroup' // We'll deploy the resources in the provided resource group + +// Parameters to easily construct resource names +param location string +param project string +param swaLocation string + +// Here we'll add an identifier to create a unique name for the App Service Plan, for example your trigram, so that everyone could deploy his own parkndeploy instance +param identifier string + +// Create the AppServicePlan through the AppServicePlan module +module appServicePlan 'modules/appServicePlan.bicep' = { + name: 'appServicePlan' + params: { + location: location + project: project + identifier: identifier + } +} + +// Create the AppService through the AppService module +module appService 'modules/appService.bicep' = { + name: 'appService' + params: { + location: location + project: project + identifier: identifier + planId: appServicePlan.outputs.planId // Use the appServicePlan output to get its id back => an App Service needs to reference its App Service Plan + } +} + +module staticWebApp 'modules/staticWebApp.bicep' = { + name: 'staticWebApp' + params: { + location: swaLocation + project: project + identifier: identifier + } +} + +module staticWebAppBackend 'modules/staticWebAppBackend.bicep' = { + name: 'staticWebAppBackend' + params: { + backendBindedResourceId: appService.outputs.appServiceId + swaName: staticWebApp.outputs.swaName + location: location + } +} + + +// Export App Service Name +output appServiceName string = appService.outputs.appServiceName +output staticWebAppName string = staticWebApp.outputs.swaName + diff --git a/infrastructure/modules/appService.bicep b/infrastructure/modules/appService.bicep new file mode 100644 index 00000000..dbe7a75b --- /dev/null +++ b/infrastructure/modules/appService.bicep @@ -0,0 +1,23 @@ +param location string +param project string +param identifier string + +// App Service Plan identifier that will host our App Service +param planId string + +resource app 'Microsoft.Web/sites@2022-03-01' = { + name: '${project}-app-${identifier}' + location: location + + properties: { + serverFarmId: planId + reserved: true + + siteConfig: { + linuxFxVersion: 'DOTNETCORE|9.0' // Specify to setup the .NET Core 9.0 runtime (used by our backend API) on the Linux machine under the hood + } + } +} + +output appServiceName string = app.name // Export the App Service name for deployment +output appServiceId string = app.id diff --git a/infrastructure/modules/appServicePlan.bicep b/infrastructure/modules/appServicePlan.bicep new file mode 100644 index 00000000..c9b43403 --- /dev/null +++ b/infrastructure/modules/appServicePlan.bicep @@ -0,0 +1,20 @@ +param location string +param project string +param identifier string + +resource plan 'Microsoft.Web/serverfarms@2022-09-01' = { + name: '${project}-plan-${identifier}' + location: location + + sku: { + name: 'F1' // We use F1 pricing plan (free one) as we don't need specific features + } + + kind: 'app,linux' // Allow to deploy on an App Service using Linux OS + + properties: { + reserved: true // Specifity of App Service with Linux OS + } +} + +output planId string = plan.id // Export the App Service identifier diff --git a/infrastructure/modules/staticWebApp.bicep b/infrastructure/modules/staticWebApp.bicep new file mode 100644 index 00000000..0925f696 --- /dev/null +++ b/infrastructure/modules/staticWebApp.bicep @@ -0,0 +1,17 @@ +param location string +param project string +param identifier string + +resource swa 'Microsoft.Web/staticSites@2024-04-01' = { + name: '${project}-swa-${identifier}' + location: location + + sku: { + name: 'Standard' + tier: 'Standard' +} + + properties: {} // Even empty, it's mandatory ... +} + +output swaName string = swa.name // Expose Static Web App name as we did for App Service for deployment purpose diff --git a/infrastructure/modules/staticWebAppBackend.bicep b/infrastructure/modules/staticWebAppBackend.bicep new file mode 100644 index 00000000..4e902770 --- /dev/null +++ b/infrastructure/modules/staticWebAppBackend.bicep @@ -0,0 +1,11 @@ +param backendBindedResourceId string +param swaName string +param location string + +resource staticWebAppBackend 'Microsoft.Web/staticSites/linkedBackends@2022-03-01' = { + name: '${swaName}/backend' + properties: { + backendResourceId: backendBindedResourceId + region: location + } +}