Skip to content

Update main.yml

Update main.yml #35

Workflow file for this run

name: Deploy React App
on:
push:
branches:
- main # main 브랜치에 푸시될 때 실행
jobs:
deploy:
runs-on: ubuntu-latest # 최신 Ubuntu 버전에서 실행
steps:
# Git 체크아웃
- name: Checkout code
uses: actions/checkout@v2
# Node.js 버전 설정
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
# node_modules 캐시
- name: Cache node_modules
uses: actions/cache@v2
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
# 의존성 설치 및 빌드
- name: Install dependencies and build
run: |
npm install
npm run build
- name: Install sshpass
run: sudo apt-get install -y sshpass # sshpass 설치
- name: Deploy to Server
env:
SSH_PASSWORD: ${{ secrets.PASSWORD }}
SERVER_IP: ${{ secrets.HOST }}
run: |
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -p 16122 rayoen@$HOST "mkdir -p /var/www/html/dist"
sshpass -p "$PASSWORD" scp -o StrictHostKeyChecking=no -P 16122 -r dist/* rayoen@$HOST:/var/www/html/dist/
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -p 16122 rayoen@$HOST "chmod -R 755 /var/www/html/dist"
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -p 16122 rayoen@$HOST "sudo systemctl restart nginx"