-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (91 loc) · 4.32 KB
/
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Docker React App
on:
push:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get public IP address
id: get_ip
run: |
PUBLIC_IP=$(curl -s https://api.ipify.org)
echo "PUBLIC_IP=$PUBLIC_IP" >> $GITHUB_ENV
- name: Get Hash
id: get_hash
run: |
COMMIT_HASH=$(git rev-parse --short HEAD)
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build Next.js app
run: pnpm build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker registry
uses: docker/login-action@v1
with:
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.NAVER_ACESSKEY }}
password: ${{ secrets.NAVER_SECRETKEY }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ secrets.REGISTRY_URL }}/joseonpaldo-react:${{ env.COMMIT_HASH }}
- name: Set up Naver CLI
run: |
cd ~
curl -L https://www.ncloud.com/api/support/download/files/cli/CLI_1.1.20_20240620.zip -o CLI_1.1.20_20240620.zip
unzip CLI_1.1.20_20240620.zip
cd ./CLI_1.1.20_20240620/cli_linux
chmod +x ncloud
echo "${{ secrets.NAVER_ACESSKEY }}" > input.txt
echo "${{ secrets.NAVER_SECRETKEY }}" >> input.txt
echo "" >> input.txt
cat input.txt | ./ncloud configure
- name: Add ACG rule for deploy server
run: |
cd ~/CLI_1.1.20_20240620/cli_linux
./ncloud vserver addAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NAVER_VPC }} --accessControlGroupNo ${{ secrets.NAVER_ACG_NO }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ env.PUBLIC_IP }}/32', portRange='22'"
- name: SSH and deploy 001
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP_001 }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
docker login -u ${{ secrets.NAVER_ACESSKEY }} -p ${{ secrets.NAVER_SECRETKEY }} ${{ secrets.REGISTRY_URL }}
docker pull ${{ secrets.REGISTRY_URL }}/joseonpaldo-react:${{ env.COMMIT_HASH }}
docker stop joseonpaldo-front || true
docker rm joseonpaldo-front || true
docker run -d -p 3000:3000 --name joseonpaldo-front ${{ secrets.REGISTRY_URL }}/joseonpaldo-react:${{ env.COMMIT_HASH }}
docker images --format '{{.Repository}}:{{.Tag}}' | grep joseonpaldo-react | grep -v "${{ env.COMMIT_HASH }}" | xargs -r docker rmi || true
# - name: Wait for 90sec
# run: sleep 90
- name: SSH and deploy 002
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP_002 }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
docker login -u ${{ secrets.NAVER_ACESSKEY }} -p ${{ secrets.NAVER_SECRETKEY }} ${{ secrets.REGISTRY_URL }}
docker pull ${{ secrets.REGISTRY_URL }}/joseonpaldo-react:${{ env.COMMIT_HASH }}
docker stop joseonpaldo-front || true
docker rm joseonpaldo-front || true
docker run -d -p 3000:3000 --name joseonpaldo-front ${{ secrets.REGISTRY_URL }}/joseonpaldo-react:${{ env.COMMIT_HASH }}
docker images --format '{{.Repository}}:{{.Tag}}' | grep joseonpaldo-react | grep -v "${{ env.COMMIT_HASH }}" | xargs -r docker rmi || true
- name: Remove ACG inbound rule created
run: |
cd ~/CLI_1.1.20_20240620/cli_linux
./ncloud vserver removeAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NAVER_VPC }} --accessControlGroupNo ${{ secrets.NAVER_ACG_NO }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ env.PUBLIC_IP }}/32', portRange='22'"