-
Notifications
You must be signed in to change notification settings - Fork 0
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
254d3a6
commit 0251322
Showing
1 changed file
with
32 additions
and
58 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 |
---|---|---|
|
@@ -2,9 +2,8 @@ name: CD - Deploy to Production Server | |
|
||
on: | ||
push: | ||
branches: [ "dev" ] # main 브랜치 푸시 시 실행 | ||
branches: [ "dev" ] | ||
|
||
# flow에서 사용할 변수 | ||
env: | ||
AWS_REGION: ap-northeast-2 | ||
S3_BUCKET_NAME: meerket-bucket | ||
|
@@ -13,7 +12,6 @@ env: | |
|
||
permissions: write-all | ||
|
||
#여기서부터 build job | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -30,33 +28,35 @@ jobs: | |
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# 2.5) secret설정한 env 등록 | ||
- name: Create .env file from Secret | ||
run: | | ||
echo "${{ secrets.ENV_FILE_BASE64 }}" | base64 --decode > .env | ||
# # 4) gradle 테스트 빌드 | ||
# - name: Build Test with Gradle | ||
# run: ./gradlew test -i | ||
# # run: ./gradlew clean build -i | ||
# # working-directory: ${{ env.working-directory }} | ||
|
||
# 3) gradlew 권한 설정 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./meerket/gradlew # gradlew에 실행 권한 부여 | ||
run: chmod +x ./meerket/gradlew | ||
|
||
# 4) gradle 빌드 | ||
- name: Build with Gradle | ||
working-directory: ./meerket | ||
run: ./gradlew clean build -x test --no-daemon --info | ||
|
||
# 여기서부터 배포 job | ||
|
||
# 5) 빌드 결과 확인 | ||
- name: Verify JAR file | ||
run: | | ||
echo "Checking build directory..." | ||
ls -al ./meerket/meerket-application/build/libs | ||
echo "Verifying Spring Boot loader in JAR file..." | ||
jar tf ./meerket/meerket-application/build/libs/*.jar | grep "org/springframework/boot/loader" || echo "Spring Boot loader not found" | ||
# 6) JAR 파일 크기 확인 | ||
- name: Check JAR File Size | ||
run: | | ||
echo "JAR file size:" | ||
du -h ./meerket/meerket-application/build/libs/*.jar || echo "JAR file not found" | ||
deploy: | ||
name: deploy | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
needs: [ build ] # test와 build 작업이 성공적으로 완료된 경우에만 실행 | ||
needs: [ build ] | ||
|
||
steps: | ||
# 1) 기본 체크아웃 | ||
|
@@ -70,60 +70,34 @@ jobs: | |
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# 2.5) secret설정한 env 등록 | ||
- name: Create .env file from Secret | ||
run: | | ||
echo "${{ secrets.ENV_FILE_BASE64 }}" | base64 --decode > .env | ||
# 2.5) secret 설정한 firesbase json key 등록 | ||
|
||
- name: create-json | ||
uses: jsdaniell/[email protected] | ||
with: | ||
name: "meerket-83e38-firebase-adminsdk-gyt9i-d2df62fdf4.json" | ||
json: ${{secrets.FIREBASE_SERVICE_KEY }} | ||
dir: './meerket/meerket-application/src/main/resources' | ||
|
||
# 3) gradlew 권한 설정 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./meerket/gradlew # gradlew에 실행 권한 부여 | ||
|
||
# # 4) gradle 테스트 빌드 | ||
# - name: Build Test with Gradle | ||
# run: ./gradlew test -i | ||
# # run: ./gradlew clean build -i | ||
# # working-directory: ${{ env.working-directory }} | ||
|
||
# 4) gradle 빌드 | ||
- name: Build with Gradle | ||
working-directory: ./meerket | ||
run: ./gradlew clean build -x test --no-daemon --info | ||
# working-directory: ${{ env.working-directory }} | ||
|
||
# AWS 인증 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
run: chmod +x ./meerket/gradlew | ||
|
||
# AWS S3에 업로드 | ||
# 4) S3 업로드 확인 | ||
- name: Upload to AWS S3 | ||
run: | | ||
cd meerket | ||
echo "Navigating to build directory..." | ||
cd meerket/meerket-application/build/libs | ||
ls -al | ||
echo "Uploading to S3..." | ||
aws deploy push \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--ignore-hidden-files \ | ||
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | ||
--source . | ||
echo "Verifying S3 bucket contents..." | ||
aws s3 ls s3://${{ env.S3_BUCKET_NAME }}/ | ||
# AWS EC2에 Deploy | ||
# 5) AWS EC2에 Deploy | ||
- name: Deploy to AWS EC2 from S3 | ||
run: | | ||
echo "Starting deployment to EC2..." | ||
aws deploy create-deployment \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--deployment-config-name CodeDeployDefault.AllAtOnce \ | ||
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | ||
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip | ||
echo "Checking deployment status..." | ||
aws deploy list-deployments --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} --query 'deployments' --output json |