모각코_6주차

Haegyeong Kim·2024년 8월 16일

모각코_2024

목록 보기
6/6

AWS에 프로젝트 빌드 및 배포
AWS 환경에서 배포를 진행
EC2를 생성

AWS

🚧AWS Setting

Ubuntu 의 OS만 깔려있는 상태

자바를 다운 받기 위한 설정은 아래와 같다.

wget -O- https://apt.corretto.aws/corretto.key | sudo apt-key add -
sudo add-apt-repository 'deb https://apt.corretto.aws stable main'
sudo apt-get update; sudo apt-get install -y java-21-amazon-corretto-jdk

nohup으로 실행했으나 중단 하고 싶은 경우 아래와 같이 수행!
프로세스 확인 후 삭제

lsof -i :8080

kill {PID}
netstat -ano | findstr :{포트번호}

taskkill /f /pid {PID번호}

테스트코드 디비 같은 것 때문에 빌드 안되는 경우가 많은데, build.gradle 맨아래 있는 이 부분 주석 처리 후 빌드.

tasks.named('test') {
    useJUnitPlatform()
}

bash shell 스크립트 작성 하여 빌드 및 배포를 자동화한다.

#!/bin/bash

# 프로젝트 클론 및 브랜치 체크아웃
git clone https://github.com/HaegyeongKim01/spring-gift-point.git /home/ubuntu/project
cd /home/ubuntu/project
git checkout step2

# 빌드 
./gradlew build

# 빌드 파일 경로 설정
BUILD_PATH=$(ls /home/ubuntu/project/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_PATH)

# 현재 실행 중인 애플리케이션 PID 확인
CURRENT_PID=$(pgrep -f $JAR_NAME)

# 애플리케이션이 실행 중이면 종료
if [ -z $CURRENT_PID ]
then
  echo "No application running."
else
  echo "Stopping current application with PID: $CURRENT_PID"
  kill -15 $CURRENT_PID
  sleep 5
fi

# 새 버전 애플리케이션 배포
DEPLOY_PATH=/home/ubuntu/
cp $BUILD_PATH $DEPLOY_PATH
cd $DEPLOY_PATH

DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo "Starting new application: $DEPLOY_JAR"
nohup java -jar $DEPLOY_JAR > /dev/null 2>&1 &
profile
Computer Science & Engineering

0개의 댓글