diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 000000000..12bd8c32a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,26 @@ + +name: Deploy to Azure App Service + +on: + push: + branches: + - app-service-deployment + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v3 + - name: Setup Node.js version + uses: actions/setup-node@v4 + with: + node-version: '18.x' + - name: Install Dependencies + run: npm install + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: integrationninjas + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . diff --git a/.github/workflows/main_helloworldnodejs01.yml b/.github/workflows/main_helloworldnodejs01.yml new file mode 100644 index 000000000..4dc4c6126 --- /dev/null +++ b/.github/workflows/main_helloworldnodejs01.yml @@ -0,0 +1,71 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy Node.js app to Azure Web App - helloworldnodejs01 + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js version + uses: actions/setup-node@v3 + with: + node-version: '20.x' + + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm run test --if-present + + - name: Zip artifact for deployment + run: zip release.zip ./* -r + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: node-app + path: release.zip + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + permissions: + id-token: write #This is required for requesting the JWT + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: node-app + + - name: Unzip artifact for deployment + run: unzip release.zip + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_7D5828D583E240DDADB39EA1E63FAE7C }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_7305912C3B0F4BAF87FE92FD0D24C600 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_F2ADF88FBB1240CE8C250F1ED419DB22 }} + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'helloworldnodejs01' + slot-name: 'Production' + package: . + \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..f4076bbab --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,78 @@ +# Node.js Express Web App to Linux on Azure +# Build a Node.js Express app and deploy it to Azure as a Linux web app. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript + +trigger: +- main + +variables: + + # Azure Resource Manager connection created during pipeline creation + azureSubscription: 'b933efc4-b9ee-4833-a867-f148ac1cc5bb' + + # Web app name + webAppName: 'helloworldnodejs01' + + # Environment name + environmentName: 'helloworldnodejs01' + + # Agent VM image name + vmImageName: 'ubuntu-latest' + +stages: +- stage: Build + displayName: Build stage + jobs: + - job: Build + displayName: Build + pool: + vmImage: $(vmImageName) + + steps: + - task: NodeTool@0 + inputs: + versionSpec: '10.x' + displayName: 'Install Node.js' + + - script: | + npm install + npm run build --if-present + npm run test --if-present + displayName: 'npm install, build and test' + + - 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 + artifact: drop + +- stage: Deploy + displayName: Deploy stage + dependsOn: Build + condition: succeeded() + jobs: + - deployment: Deploy + displayName: Deploy + environment: $(environmentName) + pool: + vmImage: $(vmImageName) + strategy: + runOnce: + deploy: + steps: + - task: AzureWebApp@1 + displayName: 'Azure Web App Deploy: helloworldnodejs01' + inputs: + azureSubscription: $(azureSubscription) + appType: webAppLinux + appName: $(webAppName) + runtimeStack: 'NODE|10.10' + package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip + startUpCommand: 'npm run start' \ No newline at end of file