-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (64 loc) · 2.3 KB
/
Delivery.yaml
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
name: Continuous Delivery
on:
pull_request:
branches: develop
types:
- opened
- synchronize
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.14.x]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: 노드 ${{ matrix.node-version }}버젼으로 실행
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: pnpm 설치
run: npm install -g [email protected]
- name: 의존성 패키지 설치
run: pnpm install --frozen-lockfile
- name: 테스트 실행
run: pnpm test
continous-delivery:
needs: test
runs-on: ubuntu-latest
steps:
- name: 브랜치 확인 및 컨텍스트 확인
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
runs: |
echo " 브랜치 확인, ${{ github.event.pull_request.head.ref }}"
echo " 컨텍스트 확인 , ${{ github }}"
- name: 노드 ${{ matrix.node-version }} 버젼으로 실행
uses: actions/setup-node@v3
with:
node-version: 16.14.x
- name: EC2에서 CD 프로세스 실행
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_REMOTE_SSH_KEY }}" > ~/.ssh/hipspot_server.pem
chmod 600 ~/.ssh/hipspot_server.pem
echo "스크립트 생성"
cat > deploy.sh << 'EOF'
source ~/.zshrc;
cd ~/$(echo "${{github.repository}}" | awk -F '/' '{print $2}');
pwd;
git checkout ${{ github.event.pull_request.head.ref }};
git pull origin ${{ github.event.pull_request.head.ref }};
pnpm i;
pnpm build;
pm2 delete prod-server;
pm2 start pnpm --name prod-server -- start:prod;
EOF
echo "스크립트 전송"
scp -i "~/.ssh/hipspot_server.pem" -o StrictHostKeyChecking=no deploy.sh ${{secrets.EC2_USER}}@${{secrets.EC2_KNOWN_HOST}}:~/deploy.sh
echo "스크립트 실행"
ssh -i "~/.ssh/hipspot_server.pem" -o StrictHostKeyChecking=no ${{secrets.EC2_USER}}@${{secrets.EC2_KNOWN_HOST}} "zsh ~/deploy.sh; rm -rf ~/deploy.sh"
rm -f ~/.ssh/hipspot_server.pem