Skip to content

Commit

Permalink
added azure workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ahnaf committed Sep 4, 2024
1 parent dfeab88 commit 300e974
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 4 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy to Azure App Service

on:
push:
branches:
- main
paths-ignore:
- 'README.md'

env:
AZURE_WEBAPP_NAME: bookify
NODE_VERSION: '20.x'

jobs:
build:
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: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Create .env file
run: |
echo "SQLITE_DB=${{ secrets.SQLITE_DB }}" >> .env
echo "TYPEORM_CLI=${{ secrets.TYPEORM_CLI }}" >> .env
echo "APP_PORT=${{ secrets.APP_PORT }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env
echo "OAUTH_REDIRECT_URL=${{ secrets.OAUTH_REDIRECT_URL }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "${{ secrets.ROOMS }}" > ./src/config/rooms.ts
- name: Install Dependencies
run: |
npm install
npm run build --if-present
- name: Run database migrations
run: npm run migration:run

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: .

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@v4
with:
name: node-app

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

*.sqlite

# dotenv environment variable files
.env
.env.development
Expand Down
Binary file removed bookify_db.sqlite
Binary file not shown.
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "bookify",
"version": "0.0.1",
"version": "1.0.0",
"description": "",
"author": "Ali Ahnaf",
"private": true,
"license": "MIT",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start": "node dist/main",
"start:prod": "node dist/main",
"start:dev": "cross-env NODE_ENV=development nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:client": "cd client && npx http-server -p 8000 -a localhost",
"typeorm": "ts-node ./node_modules/typeorm/cli",
"migration:run": "npm run build && (npm run typeorm migration:run -- -d ./src/config/orm.config.ts)",
Expand All @@ -26,6 +26,7 @@
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/throttler": "^6.2.1",
"@nestjs/typeorm": "^10.0.2",
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppService } from './app.service';
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@Get('/hello')
getHello(): string {
return this.appService.getHello();
}
Expand Down
5 changes: 5 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import appConfig from './config/env/app.config';
import dbConfig from './config/env/db.config';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
import { APP_GUARD } from '@nestjs/core';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';

@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'client'),
}),
TypeOrmModule.forRoot(typeOrmConfig),
ConfigModule.forRoot({
isGlobal: true,
Expand Down

0 comments on commit 300e974

Please sign in to comment.