-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12361ce
commit 14a4e3b
Showing
1 changed file
with
49 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,70 @@ | ||
name: Deploy Spring Project | ||
name: Deploy to AWS CodeDeploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- deploy # 배포를 원하는 브랜치 이름 | ||
- deploy | ||
|
||
env: | ||
S3_BUCKET_NAME: sursim-img | ||
APPLICATION_NAME: boomerang | ||
DEPLOYMENT_GROUP_NAME: boomerang-deploy-group | ||
REGION: ap-northeast-2 | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v2 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' # JDK 버전 | ||
distribution: 'temurin' # 또는 'zulu' | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
- name: Create application.properties from Secrets | ||
working-directory: ./boomerang | ||
run: | | ||
echo "Current directory: $(pwd)" | ||
mkdir -p src/main/resources | ||
echo "${{ secrets.APPLICATION }}" > src/main/resources/application.properties | ||
cat src/main/resources/application.properties | ||
- name: Create application properties file | ||
run: echo "${{ secrets.APPLICATION }}" > application.properties # GitHub Secrets에 저장된 프로퍼티 작성 | ||
- name: Grant execute permission for gradlew | ||
working-directory: ./boomerang | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build with Gradle | ||
run: | | ||
cd boomerang # boomerang 디렉터리로 이동 | ||
./gradlew build -x test # Gradle 빌드 | ||
working-directory: ./boomerang | ||
run: ./gradlew build -x test | ||
|
||
- name: Copy files to server | ||
- name: Make zip file including appspec.yml | ||
run: | | ||
echo "${{ secrets.SSH_KEY }}" > kwy-root.pem # SSH 키를 파일로 저장 | ||
chmod 600 kwy-root.pem # 파일 권한 설정 | ||
ssh -o StrictHostKeyChecking=no -i kwy-root.pem ubuntu@ec2-52-79-80-3.ap-northeast-2.compute.amazonaws.com << EOF | ||
# 서버에서 실행할 명령어 | ||
cd ~/Team11_BE # 프로젝트 디렉터리로 이동 | ||
git pull origin deploy # 배포 브랜치에서 업데이트 | ||
ps -ef | grep java | awk '{print $2}' | xargs kill -9 # 이전 Java 프로세스 종료 | ||
# Make sure appspec.yml is included in the zip | ||
cp appspec.yml ./boomerang/ | ||
cd ./boomerang | ||
zip -r ../application.zip . | ||
cd .. | ||
# 작성된 프로퍼티 파일 이동 | ||
cp ~/path/to/application.properties ~/Team11_BE/boomerang/ # 프로퍼티 파일 이동 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.REGION }} | ||
|
||
nohup java -jar -Dspring.config.location=boomerang/application.properties build/libs/boomerang-0.0.1-SNAPSHOT.jar > log.txt 2>&1 & # 애플리케이션 실행 | ||
EOF | ||
- name: Upload to S3 | ||
run: aws s3 cp application.zip s3://$S3_BUCKET_NAME/application.zip | ||
|
||
- name: Check log file | ||
- name: Deploy with CodeDeploy | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i kwy-root.pem ubuntu@ec2-52-79-80-3.ap-northeast-2.compute.amazonaws.com "tail -f ~/Team11_BE/log.txt" # 로그 파일 확인 | ||
aws deploy create-deployment \ | ||
--application-name $APPLICATION_NAME \ | ||
--deployment-config-name CodeDeployDefault.AllAtOnce \ | ||
--deployment-group-name $DEPLOYMENT_GROUP_NAME \ | ||
--file-exists-behavior OVERWRITE \ | ||
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=application.zip \ | ||
--region $REGION |