-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (69 loc) · 2.91 KB
/
dev_deploy.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
name: dev_deploy
on:
push:
branches: [develop]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js and npm
uses: actions/setup-node@v2
with:
node-version: '20'
cache: 'npm'
- name: npm install
run: |
npm install --legacy-peer-deps
- name: Build apps
run: |
npm run build:web
npm run build:server
- name: Create .env file
run: |
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" > .env
echo "KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }}" >> .env
echo "KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}" >> .env
echo "TOKEN_SECRET=${{ secrets.TOKEN_SECRET }}" >> .env
echo "ACCESS_KEY_ID=${{ secrets.ACCESS_KEY_ID }}" >> .env
echo "SECRET_ACCESS_KEY=${{ secrets.SECRET_ACCESS_KEY }}" >> .env
echo "REGION=${{ secrets.REGION }}" >> .env
echo "LOCAL_ENDPOINT=${{ secrets.LOCAL_ENDPOINT }}" >> .env
echo "BUCKET_NAME=${{secrets.BUCKET_NAME}}" >> .env
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: |
docker-compose up -d --build
- name: Push Docker Image to Docker hub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/web
docker push ${{ secrets.DOCKERHUB_USERNAME }}/server
docker push ${{ secrets.DOCKERHUB_USERNAME }}/nginx
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }} # aws ip 주소
username: ${{ secrets.EC2_USERNAME }} # ec2 접속 유저네임
key: ${{ secrets.KEY }} # ssh 공개키
port: 22
source: './docker-compose.yml,./.env'
target: './'
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.KEY }}
port: 22
script: |
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose up -d
sudo docker image prune -f