From 7c2be91fa0773e4b7ad7b1292119c8fcc0455188 Mon Sep 17 00:00:00 2001 From: Andrew Curtis <80860310+meisZWFLZ@users.noreply.github.com> Date: Sat, 9 Dec 2023 21:37:04 -0800 Subject: [PATCH] Get azure to work (#1) * build: add docker * Add or update the Azure App Service build and deployment workflow config * build: :wrench: add web.config and dynamic ports? * build: docker is no longer necessary * build: make workflow faster? * build: :pencil2: fix workflow syntax * build: experiment with workflow * build: :alembic: hey you also have to zip it! * build: :alembic: prevent startup error * build: :alembic: npm ci then start * build: :alembic: try kuduscript * build: :alembic: add npx? * build: :alembic: forever.js * build: :alembic: simplify workflow + other stuff * build: :alembic: just do nest start * revert: :wastebasket: clean up before merge * ci: :hammer: fix ci modifiers * style: :art: format workflow * build: :zap: try to move package installation to deployment * build: :hammer: only run husky prepare in dev environment * build: :heavy_plus_sign: add nestjs cli as a dep rather than dev dep --- .github/workflows/main_meiszwflz-test-v2.yml | 62 ++++++++++++++++++++ .husky/commit-msg | 0 .husky/pre-commit | 0 package.json | 7 ++- prepare.sh | 4 ++ src/main.ts | 4 +- web.config | 57 ++++++++++++++++++ 7 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/main_meiszwflz-test-v2.yml mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/pre-commit create mode 100755 prepare.sh create mode 100644 web.config diff --git a/.github/workflows/main_meiszwflz-test-v2.yml b/.github/workflows/main_meiszwflz-test-v2.yml new file mode 100644 index 0000000..b02a80f --- /dev/null +++ b/.github/workflows/main_meiszwflz-test-v2.yml @@ -0,0 +1,62 @@ +# 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 - meiszwflz-test-v2 + +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: '18.x' + + - 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 + + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm run test --if-present + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: node-app + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'meiszwflz-test-v2' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_291038A7A98943A8AA7C81155066199E }} + package: release.zip + + - name: Delete zip file + run: rm release.zip diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 3b5d138..b95651b 100644 --- a/package.json +++ b/package.json @@ -22,20 +22,20 @@ "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", - "prepare": "husky install", + "prepare": "./prepare.sh", "prepack": "npm run check-lint && npm run check-format" }, "dependencies": { "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nestjs/cli": "^10.0.0", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" }, "devDependencies": { "@commitlint/cli": "^18.4.3", "@commitlint/config-conventional": "^18.4.3", - "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", "@types/express": "^4.17.17", @@ -74,5 +74,8 @@ ], "coverageDirectory": "../coverage", "testEnvironment": "node" + }, + "config": { + "environment": "development" } } diff --git a/prepare.sh b/prepare.sh new file mode 100755 index 0000000..e5fa3db --- /dev/null +++ b/prepare.sh @@ -0,0 +1,4 @@ +#!/bin/sh +if [ -d './node_modules/husky' ]; then + npx husky install +fi \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 13cad38..cbaad69 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,10 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; +const port = process.env.PORT || 3000; + async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(3000); + await app.listen(port); } bootstrap(); diff --git a/web.config b/web.config new file mode 100644 index 0000000..8987fcf --- /dev/null +++ b/web.config @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file