Skip to content

Update README.md

Update README.md #24

Workflow file for this run

name: CI/CD for Frontend
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: yarn install
- name: Build the project
env:
VITE_API_URI: ${{ secrets.VITE_API_URI }}
run: yarn build
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/hana_piece_front .
- name: Log in to Docker Hub
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/hana_piece_front
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: |
# Docker 이미지 풀링
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hana_piece_front
# 기존 컨테이너 중지 및 삭제
existing_container=$(sudo docker ps -q --filter "name=hana_piece_front")
if [ ! -z "$existing_container" ]; then
sudo docker stop $existing_container
sudo docker rm $existing_container
fi
# 새로운 컨테이너 실행 (포트 5173에서 접속)
sudo docker run -d -p 5173:80 --name hana_piece_front ${{ secrets.DOCKER_USERNAME }}/hana_piece_front
sudo docker image prune -f