스프링 부트와 AWS로 혼자 구현하는 웹 서비스 Chapter9 배포 자동화 구성을 위한 deploy.sh 추가 및 .travis.yml, appspec.yml 수정

This commit is contained in:
DESKTOP-FSO9NHB\User
2020-12-04 15:42:29 +09:00
parent aba017dc51
commit 3653b8537a
3 changed files with 60 additions and 7 deletions

View File

@@ -20,9 +20,13 @@ before_install:
script: "./gradlew clean build"
before_deploy:
- zip -r springboot2-webservice *
- mkdir -p deploy
- mv springboot2-webservice.zip deploy/springboot2-webservice.zip
- mkdir -p before-deploy # zip에 포함시킬 파일들을 담을 디렉토리 설정
- cp scripts/*.sh before-deploy/
- cp appspec.yml before-deploy/
- cp build/libs/*.jar before-deploy/
- cd before-deploy && zip -r before-deploy * # before-deploy로 이동 후 전체 압축
- cd ../ && mkdir -p deploy # 상위 디렉토리로 이동 후 deploy 디렉토리 생성
- mv before-deploy/before-deploy.zip deploy/sprinbboot2-webservice.zip # deploy로 zip파일 이동
deploy:
- provider: s3
@@ -37,9 +41,9 @@ deploy:
wait-until-deployed: true
- provider: codedeploy
access_key_id: $AWS_ACCESS_KEY # Travis repo settings에 설정된 값
secret_access_key: $AWS_SECRET_KEY # Travis repo settings에 설정된 값
bucket: banjjoknim-springboot2-webservice-build # S3 버킷
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_SECRET_KEY
bucket: banjjoknim-springboot2-webservice-build
key: springboot2-webservice.zip # 빌드 파일을 압축해서 전달
bundle_type: zip # 압축 확장자
application: springboot2-webservice # 웹 콘솔에서 등록한 CodeDeploy 애플리케이션

View File

@@ -3,4 +3,16 @@ os: linux
files:
- source: /
destination: /home/ec2-user/app/step2/zip/
overwrite: yes
overwrite: yes
permissions:
- object: /
pattern: "**"
owner: ec2-user
group: ec2-user
hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ec2-user

View File

@@ -0,0 +1,37 @@
#!/bin/bash
REPOSITORY=/home/ec2-user/app/step2
PROJECT_NAME=springboot2-webservice
echo "> Build 파일 복사"
cp $REPOSITORY/zip/*.jar $REPOSITORY/
echo "> 현재 구동 중인 애플리케이션 pid 확인"
CURRENT_PID=$(pgrep -fl springboot2-webservice | grep jar | awk '{print $1}')
echo "현재 구동 중인 애플리케이션 pid : $CURRENT_PID"
if [ -z "$CURRENT_PID"]; then
echo "> 현재 구동 중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi
echo "> 새 애플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tall -n 1)
echo "> JAR_NAME 에 실행권한 추가"
chmod +x $JAR_NAME
echo "> $JAR_NAME 실행"
nohup java -jar \
-Dspring.config.location=classpath:/application.properties,classpath:/application-real.properties,/home/ec2-user/app/application-oauth.properties,/home/ec2-user/app/application-real-db.properties \
-Dspring.profiles.active=real \
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &