Skip to content

Commit

Permalink
Merge pull request #648 from hngprojects/staging
Browse files Browse the repository at this point in the history
Merge branch "staging" into main
  • Loading branch information
Homoakin619 authored Aug 6, 2024
2 parents b031023 + 247586a commit 513aad0
Show file tree
Hide file tree
Showing 311 changed files with 28,614 additions and 3,277 deletions.
31 changes: 31 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
NODE_ENV=development
PROFILE=local
PORT=5000
HOST=
DB_SSL=true
DB_TYPE=
DB_USERNAME=
DB_PASSWORD=
DB_HOST=
DB_DATABASE=hng
DB_ENTITIES=dist/src/modules/**/entities/**/*.entity{.ts,.js}
DB_MIGRATIONS=dist/db/migrations/*{.ts,.js}
JWT_SECRET=gsgs
JWT_EXPIRY_TIMEFRAME=1500000
DB_SSL=false
JWT_REFRESH_SECRET=bbp
JWT_REFRESH_EXPIRY_TIMEFRAME=15
GOOGLE_REDIRECT_URI=
GOOGLE_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
OAUTH_LOGIN_REDIRECT=
SMTP_HOST=
SMTP_PORT=587
SERVER_NAME=Boilerplate
SMTP_USER=
SMTP_PASSWORD=
FRONTEND_URL=
ADMIN_SECRET=
SUPPORT_EMAIL=
AUTH_PASSWORD=
BASE_URL=
30 changes: 29 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,35 @@
# even if you have the "PROFILE" variable in your ".env.local" file.


# PROFILE=local
# NODE_ENV=development


PORT=3008
SMTP_HOST=
SMTP_PORT=587
SERVER_NAME=Boilerplate
SMTP_USER=
SMTP_PASSWORD=

PROFILE=local
NODE_ENV=development

PORT=3008
PORT=3000

DB_USERNAME=username
DB_PASSWORD=password
DB_TYPE=postgres
DB_DATABASE=database
DB_HOST=localhost
DB_PORT=5432
DB_ENTITIES=dist/src/modules/**/entities/**/*.entity{.ts,.js}

DB_MIGRATIONS=dist/**/migrations/*{.ts,.js}
DB_TYPE=postgres
DB_SSL=true

JWT_SECRET=someSecrets
JWT_EXPIRY_TIMEFRAME=3600


32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ci

on:
pull_request:
branches:
- dev
push:
branches:
- dev

jobs:
test-and-build-dev:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install --include=dev

- name: Build project
run: npm run build

- name: Run tests
run: npm run test
60 changes: 54 additions & 6 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
name: CI/CD--Dev

on:
pull_request:
pull_request_target:
branches:
- dev
push:
branches:
- dev

env:
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENTITIES: ${{ secrets.DB_ENTITIES }}
DB_MIGRATIONS: ${{ secrets.DB_MIGRATIONS }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}
DB_TYPE: 'postgres'
PROFILE: 'staging'
NODE_ENV: 'development'
PORT: 3000

jobs:
test-and-build-dev:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

# environment: pr_environment
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -25,11 +42,43 @@ jobs:
- name: Install dependencies
run: npm install --include=dev

- name: Run tests
run: npm run test

- name: Build project
run: npm run build

- name: Run tests
run: npm run test
- name: Generate migrations
run: npm run migration:generate

- name: Run migrations
run: npm run migration:run

- name: Start application
run: |
npm run start:prod > app.log 2>&1 &
APP_PID=$!
echo $APP_PID
echo "Application started with PID $APP_PID"
sleep 30 # Wait for the application to start
tail -f app.log &
# Check application status with curl
if curl --retry 5 --retry-delay 5 --max-time 10 http://localhost:3000/health; then
echo "Application is up and running."
else
echo "Application failed to start. Logs:"
cat app.log
echo "Exiting workflow due to application failure."
kill $APP_PID
exit 1
fi
kill $APP_PID
echo "Application terminated Successfully."
- name: Revert Migrations
run: npm run migration:revert
if: always()

deploy-push:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,7 +107,6 @@ jobs:
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
# key: ${{ secrets.SERVER_PRIVATE_KEY }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
script: |
Expand Down
46 changes: 45 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ on:
branches:
- main

env:
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENTITIES: ${{ secrets.DB_ENTITIES }}
DB_MIGRATIONS: ${{ secrets.DB_MIGRATIONS }}
DB_TYPE: 'postgres'
PROFILE: 'staging'
NODE_ENV: 'development'
PORT: 3000

jobs:
test-and-build-main:
runs-on: ubuntu-latest
Expand All @@ -31,9 +44,40 @@ jobs:
- name: Run tests
run: npm run test

- name: Generate migrations
run: npm run migration:generate

- name: Run migrations
run: npm run migration:run

- name: Start application
run: |
npm run start:prod > app.log 2>&1 &
APP_PID=$!
echo $APP_PID
echo "Application started with PID $APP_PID"
sleep 30 # Wait for the application to start
tail -f app.log &
# Check application status with curl
if curl --retry 5 --retry-delay 5 --max-time 10 http://localhost:3000/health; then
echo "Application is up and running."
else
echo "Application failed to start. Logs:"
cat app.log
echo "Exiting workflow due to application failure."
kill $APP_PID
exit 1
fi
kill $APP_PID
echo "Application terminated Successfully."
- name: Revert Migrations
run: npm run migration:revert
if: always()

deploy-main:
runs-on: ubuntu-latest
# needs: test-and-build-main
if: github.event_name == 'push'

steps:
Expand Down
46 changes: 45 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ on:
branches:
- staging

env:
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENTITIES: ${{ secrets.DB_ENTITIES }}
DB_MIGRATIONS: ${{ secrets.DB_MIGRATIONS }}
DB_TYPE: 'postgres'
PROFILE: 'staging'
NODE_ENV: 'development'
PORT: 3000

jobs:
test-and-build-staging:
runs-on: ubuntu-latest
Expand All @@ -31,9 +44,40 @@ jobs:
- name: Run tests
run: npm run test

- name: Generate migrations
run: npm run migration:generate

- name: Run migrations
run: npm run migration:run

- name: Start application
run: |
npm run start:prod > app.log 2>&1 &
APP_PID=$!
echo $APP_PID
echo "Application started with PID $APP_PID"
sleep 30 # Wait for the application to start
tail -f app.log &
# Check application status with curl
if curl --retry 5 --retry-delay 5 --max-time 10 http://localhost:3000/health; then
echo "Application is up and running."
else
echo "Application failed to start. Logs:"
cat app.log
echo "Exiting workflow due to application failure."
kill $APP_PID
exit 1
fi
kill $APP_PID
echo "Application terminated Successfully."
- name: Revert Migrations
run: npm run migration:revert
if: always()

deploy-staging:
runs-on: ubuntu-latest
# needs: test-and-build-main
if: github.event_name == 'push'

steps:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,7 @@ dist
/.env
/.env.*.local
*._local.ts

# Migrations
/db/migrations/*-migration.ts
/db
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"type": "node-terminal"
}
]
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Before you begin, ensure you have the following installed on your machine:
- [NestJs](https://docs.nestjs.com) (NestJS' Documentation)
- [Git](https://git-scm.com/)

## Setup Guide

#### Detailed guide on setting and starting the Application

- [Setup Guide](setup-guide.md)

## Contribution Guide

## Getting Started
Expand Down
12 changes: 12 additions & 0 deletions config/auth.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { registerAs } from '@nestjs/config';
export default registerAs('auth', () => ({
jwtSecret: process.env.JWT_SECRET,
jwtRefreshSecret: process.env.JWT_REFRESH_SECRET,
jwtExpiry: process.env.JWT_EXPIRY_TIMEFRAME,
jwtRefreshExpiry: process.env.JWT_REFRESH_EXPIRY_TIMEFRAME,
google: {
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
clientID: process.env.GOOGLE_CLIENT_ID,
callbackURL: process.env.GOOGLE_REDIRECT_URI,
},
}));
20 changes: 10 additions & 10 deletions dev-ecosystem-config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"apps": [
{
"name": "team-alpha-dev",
"script": "npm run dev",
"log_file": "~/.pm2/logs/team-alpha-dev-out.log",
"combine_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm:ss Z"
}
]
}
"apps": [
{
"name": "team-alpha-dev",
"script": "npm run start:prod",
"log_file": "~/.pm2/logs/team-alpha-dev-out.log",
"combine_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm:ss Z"
}
]
}
Loading

0 comments on commit 513aad0

Please sign in to comment.