Skip to content

Commit

Permalink
deploy dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryKwon committed Nov 29, 2024
1 parent 6b6e922 commit 8fd6c23
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 24 deletions.
33 changes: 12 additions & 21 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
name: dev branch auto ci process script
name: Deploy to Development

on: # 아래 job을 실행시킬 상황
on:
push:
branches: [dev]
branches:
- dev

jobs:
deploy:
name: deploy
runs-on: ubuntu-latest # 실행될 인스턴스 OS와 버전

runs-on: ubuntu-latest
steps:
- name: excuting remote ssh commands
uses: appleboy/ssh-action@v0.1.6 # ssh 접속하는 오픈소스
with:
host: ${{ secrets.REMOTE_IP_DEV }} # 인스턴스 IP
username: ${{ secrets.REMOTE_USER_DEV }} # 우분투 아이디
key: ${{ secrets.REMOTE_PRIVATE_KEY_DEV }} # ec2 instance pem key
port: ${{ secrets.REMOTE_SSH_PORT_DEV }} # 접속포트
passphrase: ${{ secrets.REMOTE_PASSPHRASE_DEV }}
script: | # 실행할 스크립트
cd otlplus-nest-server
git pull origin dev
sudo docker stop otlplus-server-nest-dev
sudo docker rm otlplus-server-nest-dev
sudo docker rmi otlplus-server-nest-dev
sudo ./deploy.sh -e dev
- name: Send Deployment Webhook
env:
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
run: |
curl -X POST \
-H "X-Hub-Signature-256: sha256=$(echo -n '{}' | openssl dgst -sha256 -hmac $WEBHOOK_SECRET)" \
http://webhook.otl.dev.sparcs.org/server-webhook
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#
/env/*
.venv

# Logs
logs
Expand Down
Binary file added __pycache__/server_webhook.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ while getopts "e:" opt; do
exit 1
fi

docker-compose -f "$COMPOSE_FILE" up -d
docker compose -f "$COMPOSE_FILE" up -d
;;
\?)
echo "Invalid option: -$OPTARG" 1>&2
Expand Down
5 changes: 4 additions & 1 deletion docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ services:
restart: always
tty: true
ports:
- '8080:8000'
- '58000:8000'
expose:
- '8000'
volumes:
- '/etc/timezone:/etc/timezone:ro'
network_mode: 'host'
working_dir: /var/www/otlplus-server
command: node dist/src/bootstrap/bootstrap.js
37 changes: 37 additions & 0 deletions server_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python3

from flask import *
from werkzeug.middleware.proxy_fix import ProxyFix
import os
from dotenv import load_dotenv
import hmac
import hashlib

FLASK_ENV = os.getenv("FLASK_ENV", "development")
load_dotenv(f".env.{FLASK_ENV}")

app = Flask(__name__)

app.wsgi_app = ProxyFix(
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
)

@app.route('/server-webhook', methods=["POST"])
def otlplus_redeploy():
webhook_secret = os.getenv("WEBHOOK_SECRET").encode()
signature = 'sha256=' + hmac.new(webhook_secret, request.data, hashlib.sha256).hexdigest()
if 'X-Hub-Signature-256' not in request.headers or not hmac.compare_digest(
signature, request.headers['X-Hub-Signature-256']
):
abort(403)

os.spawnl(os.P_NOWAIT, "/bin/bash", "/bin/bash", "/home/otlplus/server/deploy.sh -e dev")
return "Done", 200

@app.route('/server-webhook-status', methods=["GET"])
def clubs_stage_redeploy():
# os.spawnl(os.P_NOWAIT, "/bin/bash", "/bin/bash", "/home/otlplus/server/deploy.sh -e dev")
return "Done", 200

if __name__ == '__main__':
app.run(host="127.0.0.1", threaded=True, port=5000)
2 changes: 2 additions & 0 deletions src/modules/auth/utils/sparcs-sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export class Client {
const allowedPreferredUris: { [key: string]: string } = {
'otl.sparcs.org': 'https://otl.sparcs.org/session/login/callback/',
'otl.kaist.ac.kr': 'https://otl.kaist.ac.kr/session/login/callback/',
'api.otl.dev.sparcs.org':
'https://api.otl.dev.sparcs.org/session/login/callback/',
'otl-stage.sparcsandbox.com':
'https://otl-stage.sparcsandbox.com/session/login/callback/',
};
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getCorsConfig = () => {
};
} else if (NODE_ENV === 'dev') {
return {
origin: 'http://3.37.146.183',
origin: ['https://otl.dev.sparcs.org', 'http://localhost:5173'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
preflightContinue: false,
Expand Down

0 comments on commit 8fd6c23

Please sign in to comment.