Skip to content

Conversation

@ParkJiwoon
Copy link
Owner

@ParkJiwoon ParkJiwoon commented May 5, 2022

Description

프로젝트 전체 코드를 올리는 대신 빌드 파일만 올리는 방법입니다.

기존 방식은 전체 프로젝트를 서버에 올린 후 빌드 파일을 복사해서 실행하는 거라면 새로운 방식은 Github Actions 에서 미리 빌드 파일을 복사해서 해당 파일만 올립니다.

AWS EC2

서버에 들어가서 확인해보면 jar 파일만 올라가있는 것을 확인할 수 있습니다

로그는 스크립트를 실행하면서 생긴겁니다.

image

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 수행

Comment on lines +41 to +43
# (3.5) 빌드한 JAR 파일 복사
- name: Copy Jar file
run: cp ./build/libs/*.jar ./deploy/spring-webapp.jar
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 에 복사합니다.

--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 디렉터리만 압축해서 보내도록 지정해줍니다.

Comment on lines -12 to -15
# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE

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 에는 프로젝트 전체가 있는게 아니라서 스크립트에서 해당 내용을 제외합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants