Skip to content

Commit

Permalink
Get azure to work (#1)
Browse files Browse the repository at this point in the history
* build: add docker

* Add or update the Azure App Service build and deployment workflow config

* build: 🔧 add web.config and dynamic ports?

* build: docker is no longer necessary

* build: make workflow faster?

* build: ✏️ fix workflow syntax

* build: experiment with workflow

* build: ⚗️ hey you also have to zip it!

* build: ⚗️ prevent startup error

* build: ⚗️ npm ci then start

* build: ⚗️ try kuduscript

* build: ⚗️ add npx?

* build: ⚗️ forever.js

* build: ⚗️ simplify workflow + other stuff

* build: ⚗️ just do nest start

* revert: 🗑️ clean up before merge

* ci: 🔨 fix ci modifiers

* style: 🎨 format workflow

* build: ⚡ try to move package installation to deployment

* build: 🔨 only run husky prepare in dev environment

* build: ➕ add nestjs cli as a dep rather than dev dep
  • Loading branch information
meisZWFLZ authored Dec 10, 2023
1 parent e408bc5 commit 7c2be91
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 3 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/main_meiszwflz-test-v2.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -74,5 +74,8 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"config": {
"environment": "development"
}
}
4 changes: 4 additions & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
if [ -d './node_modules/husky' ]; then
npx husky install
fi
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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();
57 changes: 57 additions & 0 deletions web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the dist/main.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="dist/main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^dist/main.js\/debug[\/]?" />
</rule>

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}" />
</rule>

<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="dist/main.js" />
</rule>
</rules>
</rewrite>

<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>

<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>

0 comments on commit 7c2be91

Please sign in to comment.