-
Notifications
You must be signed in to change notification settings - Fork 4
97 lines (85 loc) ยท 4.21 KB
/
github-actions-front.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: React CI/CD with Docker
# event trigger
on:
# ํด๋น ๋ธ๋์น๋ก push ๋ ๋ ์คํ๋ฉ๋๋ค.
push:
branches:
- main
- develop
# ํด๋น ๋ธ๋์น๋ก PR ๋ ๋ ์คํ๋ฉ๋๋ค.
pull_request:
branches:
permissions:
contents: read
jobs:
build:
if: github.repository == 'Team-Coverflow/CoverFlow-FE'
runs-on: ubuntu-latest
steps:
## Repo checkout
- name: Checkout source code.
uses: actions/checkout@v3
## Node version ํ์ธ
- name: Check Node v
run: node -v
## ์์กด ํ์ผ ์ค์น
- name: Install dependencies
run: yarn
## React Build
- name: Generate build
run: CI='false' yarn build
######### CD(Continuous Delivery) ##########
## docker hub์ ๋ก๊ทธ์ธํ๊ณ cofl-front-dev ์ด๋ฏธ์ง๋ฅผ ๋น๋ & push ํฉ๋๋ค.
- name: Docker build & push to dev repo
if: contains(github.ref, 'develop')
run: |
docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}"
docker build -f Dockerfile-front-dev -t "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev .
docker push "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
## docker hub์ ๋ก๊ทธ์ธํ๊ณ cofl-front-prod์ ์ด๋ฏธ์ง๋ฅผ ๋น๋ & push ํฉ๋๋ค.
- name: Docker build & push to prod repo
if: contains(github.ref, 'main')
run: |
docker login -u "${{ secrets.DOCKER_USERNAME_PROD }}" -p "${{ secrets.DOCKER_PASSWORD_PROD }}"
docker build -f Dockerfile-front-prod -t "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod .
docker push "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
## AWS EC2์ ์ ์ํ๊ณ develop์ ๋ฐฐํฌํฉ๋๋ค.
- name: Deploy to Dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.HOST_DEV }} # EC2 ์ธ์คํด์ค ํผ๋ธ๋ฆญ DNS
username: ${{ secrets.USERNAME }} # ์ธ์คํด์ค๋ฅผ ์์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ AMI์ ์ ์๋ ์ฌ์ฉ์ ์ด๋ฆ์ ์
๋ ฅํฉ๋๋ค.
key: ${{ secrets.PRIVATE_KEY }} # ํค ํ์ด์ pem ํค
# sudo docker-compose up -d
script: |
sudo docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}"
sudo docker stop cofl_react_dev
sudo docker rm -f $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker pull "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
sudo docker run --name cofl_react_dev -d --log-driver=syslog -p 3001:3001 "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
sudo docker image prune -a -f
## AWS EC2์ ์ ์ํ๊ณ production์ ๋ฐฐํฌํฉ๋๋ค.
- name: Deploy to Prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST_PROD }} # EC2 ์ธ์คํด์ค ํผ๋ธ๋ฆญ DNS
username: ${{ secrets.USERNAME }} # ์ธ์คํด์ค๋ฅผ ์์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ AMI์ ์ ์๋ ์ฌ์ฉ์ ์ด๋ฆ์ ์
๋ ฅํฉ๋๋ค.
key: ${{ secrets.PRIVATE_KEY }} # ํค ํ์ด์ pem ํค
# sudo docker-compose up -d
script: |
sudo docker login -u "${{ secrets.DOCKER_USERNAME_PROD }}" -p "${{ secrets.DOCKER_PASSWORD_PROD }}"
sudo docker stop cofl_react_prod
sudo docker rm -f $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker pull "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
sudo docker run --name cofl_react_prod -d --log-driver=syslog -p 3001:3001 "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
sudo docker image prune -a -f