-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (46 loc) · 1.69 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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