Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy to Amazon EC2
on:
push:
branches:
- main
- push-only-jar-file-to-s3
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main 브랜치와 구분하기 위해 현재 브랜치를 기준으로 Github Actions 수행


env:
AWS_REGION: ap-northeast-2
Expand Down Expand Up @@ -38,6 +38,10 @@ jobs:
with:
arguments: clean build -x test

# (3.5) 빌드한 JAR 파일 복사
- name: Copy Jar file
run: cp ./build/libs/*.jar ./deploy/spring-webapp.jar
Comment on lines +41 to +43
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github Actions 에서 build 파일을 미리 복사합니다.
deploy 디렉터리를 압축해서 S3 에 푸시할 예정이라 해당 path 에 복사합니다.


# (4) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용)
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -53,7 +57,7 @@ jobs:
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
--source ./deploy
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws deploy push 명령어에서 --source 를 사용하면 압축할 path 를 지정할 수 있습니다.
deploy 디렉터리만 압축해서 보내도록 지정해줍니다.


# (6) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행
- name: Deploy to AWS EC2 from S3
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions scripts/start.sh → deploy/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE

Comment on lines -12 to -15
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github Actions 워크플로우에서 JAR 파일을 복사했습니다.
AWS EC2 에는 프로젝트 전체가 있는게 아니라서 스크립트에서 해당 내용을 제외합니다.

# jar 파일 실행
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &
Expand Down
File renamed without changes.