Skip to content

Commit

Permalink
Merge pull request #56 from SWM-FIRE/dev-https
Browse files Browse the repository at this point in the history
new feature: https without loadbalancer👍
  • Loading branch information
IamGroooooot authored Aug 15, 2023
2 parents 1df1d7c + 3884458 commit 8b0a929
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 44 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy using AWS Code Deploy

on:
push:
branches: ['main']
workflow_dispatch:

# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-22.04

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

- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Clean Install Dependencies
run: yarn ci

- name: Get Credentials
run: |
aws s3 cp --region ${{ secrets.AWS_REGION }} s3://${{ secrets.SERVER_SECRETS }} .
aws s3 cp --region ${{ secrets.AWS_REGION }} s3://${{ secrets.NEWRELIC_LICENSE }} ./src/
- name: Build
run: yarn build
env:
ENV: production

- name: Compress artifact
run: |
zip -r ./$GITHUB_SHA.zip . -x "node_modules/*" ".test.env" "src/*" "test/*" "README.md" "*.git*" "dockers/*" && rm -rf src/*
shell: bash

- name: Upload artifact
run: |
aws s3 cp --region ${{ secrets.AWS_REGION }} ./$GITHUB_SHA.zip s3://${{ secrets.BUCKET_NAME }}/${{ secrets.PROJECT_NAME }}/$GITHUB_SHA.zip
- name: Deploy
run: |
aws deploy create-deployment --application-name ${{ secrets.AWS_CODEDEPLOY_APPLICATION_NAME }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ secrets.AWS_CODEDEPLOY_DEPLOYMENT_GROUP_NAME }} --s3-location bucket=${{ secrets.BUCKET_NAME }},bundleType=zip,key=${{ secrets.PROJECT_NAME }}/$GITHUB_SHA.zip
35 changes: 0 additions & 35 deletions .github/workflows/sync-gitlab.yml

This file was deleted.

15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Modoco Backend

Modoco Backend Server
- `Socket.IO Server` with Redis Adapter
- `HTTP API Server` documented with Swagger


- `Socket.IO Server` with Redis Adapter
- `HTTP API Server` documented with Swagger

Issue is tracked with JIRA

## API Documentation
Expand All @@ -12,6 +13,13 @@ Issue is tracked with JIRA

## (Required) Project settings

### certificate

`/secrets`에 private key와 certificate 파일(`key.pem`, `cert.pem`)을 넣어줍니다.
필요 없으면 `main.ts`의 createServer 함수를 수정해주세요.

### .env

먼저 `.env`파일을 아래의 양식을 참고해서 만듭니다. 프로젝트 루트 디렉터리 아래에 넣어야 합니다.

별도로 서버를 띄우지 않더라도 간편하게 Docker로 띄워서 바로 modoco-backend를 실행할 수 있도록 스크립트를 구성해두었습니다.
Expand Down Expand Up @@ -194,6 +202,7 @@ yarn prisma generate
```

### Sponsor

</details>

<p align="center"><i>This Project is Sponsored by <b>Software Maestro</b></i></p>
Expand Down
13 changes: 13 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"apps": [
{
"name": "modoco-backend",
"script": "dist/main.js",
"instances": 1,
"exec_mode": "cluster",
"env": {
"ENV": "production"
}
}
]
}
15 changes: 15 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/modoco-backend
overwrite: true
hooks:
AfterInstall:
- location: scripts/start_server.sh
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server.sh
timeout: 300
runas: root
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:repl": "yarn start:dev --entryFile repl",
"pm2:deploy": "yarn ci && pm2 start app.json",
"pm2:start": "pm2 start app.json",
"pm2:stop": "pm2 stop app.json",
"pm2:destroy": "pm2 delete app.json",
"deploy": "yarn ci && yarn build && yarn start:prod",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
Expand Down
7 changes: 7 additions & 0 deletions scripts/start_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

REPOSITORY=/home/ubuntu/modoco-backend

cd $REPOSITORY

yarn pm2:deploy
7 changes: 7 additions & 0 deletions scripts/stop_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

REPOSITORY=/home/ubuntu/modoco-backend

cd $REPOSITORY

yarn pm2:stop
2 changes: 0 additions & 2 deletions src/config/environment-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export default () => ({
CORS_ALLOWLIST: [
'https://modocode.com',
/https:\/\/.+\.modocode\.com$/,
'https://xn--hq1br4kwqt.com',
/https:\/\/.+\.xn--hq1br4kwqt\.com$/,
/https:\/\/.+\.do65qrifiozf1\.amplifyapp\.com$/,
'http://localhost:3000',
'https://localhost:3000',
Expand Down
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import { AppModule } from './app.module';
import { Logger, ValidationPipe } from '@nestjs/common';
import { NewrelicInterceptor } from './interceptors/newrelic.interceptor';
import { ConfigService } from '@nestjs/config';
import helmet from 'helmet';
import { SwaggerModule } from '@nestjs/swagger';
import { AuthService } from './auth/auth.service';
import { ShutdownService } from './services/shutdown.service';
import { readFileSync } from 'fs';
import helmet from 'helmet';

/**
* bootstrap server
*/
async function bootstrap() {
// create express application
const app = await createServer();
const app = await createServer({
key: readFileSync(process.env.KEY_PATH),
cert: readFileSync(process.env.CERT_PATH),
ca: process.env.CA_PATH ? readFileSync(process.env.CA_PATH) : null,
});

// get config service
const configService = app.get(ConfigService);
Expand All @@ -35,8 +40,10 @@ async function bootstrap() {
* Create nestExpressApplication application
* @returns {Promise<NestExpressApplication>} NestExpressApplication app
*/
async function createServer(): Promise<NestExpressApplication> {
return await NestFactory.create<NestExpressApplication>(AppModule);
async function createServer(httpsOptions): Promise<NestExpressApplication> {
return await NestFactory.create<NestExpressApplication>(AppModule, {
httpsOptions,
});
}

/**
Expand Down

0 comments on commit 8b0a929

Please sign in to comment.