Skip to content

Commit a2d4055

Browse files
committed
[FEAT] CI/CD 파일 수정
1 parent 7bd0366 commit a2d4055

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,28 @@ jobs:
3333
3434
- name: Deploy to EC2
3535
run: |
36-
max_retries=3
37-
retry_count=0
38-
39-
while [ $retry_count -lt $max_retries ]; do
40-
if scp -i private_key.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
41-
build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app.jar; then
42-
break
36+
# EC2에서 기존 파일 정리
37+
ssh -i private_key.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
38+
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
39+
# app.jar가 디렉토리면 삭제, 파일이면 백업
40+
if [ -d /home/ubuntu/app.jar ]; then
41+
sudo rm -rf /home/ubuntu/app.jar
42+
elif [ -f /home/ubuntu/app.jar ]; then
43+
sudo mv /home/ubuntu/app.jar /home/ubuntu/app.jar.backup
4344
fi
44-
retry_count=$((retry_count + 1))
45-
echo "SCP failed. Retrying ($retry_count/$max_retries)..."
46-
sleep 5
47-
done
45+
EOF
4846
49-
if [ $retry_count -eq $max_retries ]; then
50-
echo "SCP failed after $max_retries attempts"
51-
exit 1
52-
fi
47+
# JAR 파일 전송
48+
scp -i private_key.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
49+
build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app-new.jar
5350
51+
# 서비스 중지 후 파일 교체 및 재시작
5452
ssh -i private_key.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
5553
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
56-
sudo systemctl restart studylink
54+
sudo systemctl stop studylink
55+
sudo mv /home/ubuntu/app-new.jar /home/ubuntu/app.jar
56+
sudo chown ubuntu:ubuntu /home/ubuntu/app.jar
57+
sudo systemctl start studylink
5758
sudo systemctl status studylink
5859
EOF
5960

0 commit comments

Comments
 (0)