From 75f9db38f1fb5674aca0820c16e816515719d1ce Mon Sep 17 00:00:00 2001 From: mkhalid-7 <130910009+mkhalid-7@users.noreply.github.com> Date: Thu, 2 May 2024 17:56:28 +0300 Subject: [PATCH 1/5] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..42b036c --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,21 @@ +# Node.js with React +# Build a Node.js project that uses React. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript + +trigger: +- main + +pool: + vmImage: ubuntu-latest + +steps: +- task: NodeTool@0 + inputs: + versionSpec: '10.x' + displayName: 'Install Node.js' + +- script: | + npm install + npm run build + displayName: 'npm install and build' From 1a457f2a9202789ec6cb6d65a363c81f320d5903 Mon Sep 17 00:00:00 2001 From: mkhalid-7 <130910009+mkhalid-7@users.noreply.github.com> Date: Thu, 2 May 2024 17:59:19 +0300 Subject: [PATCH 2/5] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 42b036c..1edf613 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -18,4 +18,5 @@ steps: - script: | npm install npm run build + npm start displayName: 'npm install and build' From 2849055ae9dbdd3ae0cfaaec452f9c0de9eda485 Mon Sep 17 00:00:00 2001 From: mkhalid-7 <130910009+mkhalid-7@users.noreply.github.com> Date: Thu, 2 May 2024 18:02:04 +0300 Subject: [PATCH 3/5] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 128 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1edf613..b6d9f6f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,17 +6,123 @@ trigger: - main +variables: + Group: "variable" + subscriptionId: "eeb9dfdd-9c17-44c3-a4a0-7529399ce200" + azureServiceConnection: "mkhalidServicePrincipal" + location: "eastus" + resourcegroup: "mkhalid-rg" + webAppName: "mkhalid-react-222" + runtimeStack: 'node|20-LTS' + + pool: vmImage: ubuntu-latest -steps: -- task: NodeTool@0 - inputs: - versionSpec: '10.x' - displayName: 'Install Node.js' - -- script: | - npm install - npm run build - npm start - displayName: 'npm install and build' +stages: +- stage: WebApplication + displayName: Create web application in azure + jobs: + - job: webApp + + steps: + - task: AzureResourceManagerTemplateDeployment@3 + inputs: + deploymentScope: 'Subscription' + azureResourceManagerConnection: '$(azureServiceConnection)' + subscriptionId: '$(subscriptionId)' + location: 'East US' + templateLocation: 'Linked artifact' + csmFile: '.azure/main.bicep' + overrideParameters: '-webAppName $(webAppName) -location $(location) -runtimeStack $(runtimeStack)' + deploymentMode: 'Incremental' + deploymentName: 'bicepDeployment' + # deploymentOutputs: 'bicepOutputs' + +- stage: Build + displayName: Build stage + jobs: + - job: Build + displayName: Build + + steps: + - task: NodeTool@0 + inputs: + versionSpec: '20.x' + displayName: 'Install Node.js' + - script: | + npm install + npm update + # npm install express + # npm start + # npm run build + displayName: 'npm install and build' + + - task: ArchiveFiles@2 + displayName: 'Archive files' + inputs: + rootFolderOrFile: '$(System.DefaultWorkingDirectory)' + includeRootFolder: false + archiveType: zip + archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' + replaceExistingArchive: true + # - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + # - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + # artifact: drop + + - task: PublishBuildArtifacts@1 + displayName: 'Publish artifact' + inputs: + pathToPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' + artifactName: 'drop' + publishLocation: 'Container' + + +- stage: Deploy + displayName: Deploy stage + dependsOn: Build + condition: succeeded() + jobs: + - deployment: Deploy + displayName: Deploy + environment: 'webapp' + + strategy: + runOnce: + deploy: + steps: + - task: AzureWebApp@1 + displayName: 'Azure Web App Deployment' + inputs: + azureSubscription: '$(azureServiceConnection)' + appType: 'webAppLinux' + appName: '$(webAppName)' + package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' + runtimeStack: '$(runtimeStack)' + startUpCommand: 'npm start' + # startUpCommand: 'npm run start' + + + +####################################################33 +####################################33 +######################################################## + +# steps: +# - task: NodeTool@0 +# inputs: +# versionSpec: '20.x' +# displayName: 'Install Node.js' + +# - script: | +# npm install +# npm update +# npm start +# # npm run build +# displayName: 'npm install and build' + # workingDirectory: 'simple-react-app' + + +# - publish: 'build' +# artifact: 'react-app' +# displayName: 'Publish React App' From f16aab167d6918870e9afa8047506ef15575cdf5 Mon Sep 17 00:00:00 2001 From: mkhalid-7 <130910009+mkhalid-7@users.noreply.github.com> Date: Thu, 2 May 2024 18:07:03 +0300 Subject: [PATCH 4/5] Add files via upload --- appservice.bicep | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ main.bicep | 22 +++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 appservice.bicep create mode 100644 main.bicep diff --git a/appservice.bicep b/appservice.bicep new file mode 100644 index 0000000..e5e1438 --- /dev/null +++ b/appservice.bicep @@ -0,0 +1,62 @@ +// param location string +// param AppName string +// param runtimeStack string + +// var unique = substring('${uniqueString(resourceGroup().id)}', 0 , 3 ) + +// @description('App Service') +// var webAppName = 'mkhalid-${AppName}${unique}' +// var appServicePlanName = 'mkhalid-${AppName}-plan-${unique}' +// var linuxFxVersion = runtimeStack + +param location string +param webAppName string +param runtimeStack string + +// +@description('App Service') +var appServicePlanName = '${webAppName}-plan' +var linuxFxVersion = runtimeStack + +@description('App Service Plan') +resource AppServicePlan 'Microsoft.Web/serverfarms@2023-01-01' = { + name: appServicePlanName + location: location + kind: 'app' + sku: { + name: 'B1' + tier: 'Basic' + size: 'B1' + family: 'B' + capacity: 1 + } + properties: { + reserved: true + } +} + +// + + +@description('App Service') +resource appService 'Microsoft.Web/sites@2023-01-01' = { + name: webAppName + location: location + kind: 'app' + properties: { + serverFarmId: AppServicePlan.id + siteConfig: { + linuxFxVersion: linuxFxVersion + } + + } +} + + + + + + + + + diff --git a/main.bicep b/main.bicep new file mode 100644 index 0000000..899b492 --- /dev/null +++ b/main.bicep @@ -0,0 +1,22 @@ +targetScope = 'subscription' +param location string +param webAppName string +param runtimeStack string + +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: 'mkhalid-rg' + location: location +} + + +module AppService 'appservice.bicep' = { + scope: resourceGroup + name: 'appservice_Module' + params: { + location: location + webAppName: webAppName + runtimeStack: runtimeStack + } +} + + From b9ac09b3dd037b0d67b24054d9cab5b9ebfe4e92 Mon Sep 17 00:00:00 2001 From: mkhalid-7 <130910009+mkhalid-7@users.noreply.github.com> Date: Thu, 2 May 2024 18:08:03 +0300 Subject: [PATCH 5/5] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b6d9f6f..dc8ef79 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,7 +33,7 @@ stages: subscriptionId: '$(subscriptionId)' location: 'East US' templateLocation: 'Linked artifact' - csmFile: '.azure/main.bicep' + csmFile: 'main.bicep' overrideParameters: '-webAppName $(webAppName) -location $(location) -runtimeStack $(runtimeStack)' deploymentMode: 'Incremental' deploymentName: 'bicepDeployment'