Skip to content

chore: main.yml - 파이썬 설치 수동으로 인한 설치 자동화 제거 #10

chore: main.yml - 파이썬 설치 수동으로 인한 설치 자동화 제거

chore: main.yml - 파이썬 설치 수동으로 인한 설치 자동화 제거 #10

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: |
npm install
npm ci
- name: Create .env file
run: |
echo "PROD_DB=${{ secrets.PROD_DB }}" >> .env
echo "DEVELOP_DB=${{ secrets.DEVELOP_DB }}" >> .env
echo "ENVIRONMENT=${{ secrets.ENVIRONMENT }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
echo "KIS_APP_KEY=${{ secrets.KIS_APP_KEY}}" >> .env
echo "KIS_SECRECT_KEY=${{ secrets.KIS_SECRECT_KEY }}" >> .env
echo "PORT=${{ secrets.PORT }}" >> .env
echo "INSTA_UID_KEY=${{ secrets.INSTA_UID_KEY }}" >> .env
echo "INSTA_KEY=${{ secrets.INSTA_KEY }}" >> .env
echo "NAVER_ID=${{ secrets.NAVER_ID }}" >> .env
echo "NAVER_SECRET=${{ secrets.NAVER_SECRET }}" >> .env
echo "YOUTUBE_KEY=${{ secrets.YOUTUBE_KEY }}" >> .env
echo "INSTA_IP=${{ secrets.INSTA_IP }}" >> .env
# Build step removed since there is no build script
- name: Copy files via SSH
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
port: 22
source: "."
target: "/home/ubuntu/CheatSOL-BE"
- name: Execute remote commands via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
port: 22
script: |
# Install Node.js and pm2 on Amazon Linux
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get update -y
sudo apt-get install -y nodejs
sudo apt-get install -g pm2
# Navigate to the application directory
cd /home/ubuntu/CheatSOL-BE
# Install project dependencies
npm install
pip install -r requirements.txt
# Restart or start the application with pm2
pm2 stop all
pm2 delete all
pm2 start bin/www