-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 운영서버 cd-prod.yml 작성 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sunghyun0610
wants to merge
5
commits into
main
Choose a base branch
from
feat/#159-CD-Main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| name: CD - Deploy to Production Server | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] # main 브랜치 푸시 시 실행 | ||
|
|
||
| # flow에서 사용할 변수 | ||
| env: | ||
| AWS_REGION: ap-northeast-2 | ||
| S3_BUCKET_NAME: meerket-s3-bucket | ||
| CODE_DEPLOY_APPLICATION_NAME: Meerket | ||
| CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: Meerket-deployment-group | ||
|
|
||
| permissions: write-all | ||
|
|
||
| #여기서부터 build job | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| environment: production | ||
|
|
||
| steps: | ||
| # 1) 기본 체크아웃 | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # 2) JDK 17 셋팅 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| 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 gradlew | ||
|
|
||
| # 4) gradle 빌드 | ||
| - name: Build with Gradle | ||
| run: ./gradlew clean build -x test -i | ||
|
|
||
| # 여기서부터 배포 job | ||
| deploy: | ||
| name: deploy | ||
| runs-on: ubuntu-latest | ||
| environment: production | ||
| needs: [ build ] # test와 build 작업이 성공적으로 완료된 경우에만 실행 | ||
|
|
||
| steps: | ||
| # 1) 기본 체크아웃 | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # 2) JDK 17 셋팅 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v3 | ||
| 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 | ||
|
|
||
|
|
||
| # 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 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 | ||
| run: ./gradlew clean build -x test -i | ||
| # 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_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
| # AWS S3에 업로드 | ||
| - name: Upload to AWS S3 | ||
| run: | | ||
| cd meerket | ||
| aws deploy push \ | ||
| --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
| --ignore-hidden-files \ | ||
| --s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | ||
| --source . | ||
|
|
||
| # AWS EC2에 Deploy | ||
| - name: Deploy to AWS EC2 from S3 | ||
| run: | | ||
| 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 | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| version: 0.0 | ||
| os: linux | ||
|
|
||
| files: | ||
| - source: / | ||
| destination: /home/ubuntu/project | ||
| overwrite: yes | ||
|
|
||
| permissions: | ||
| - object: / | ||
| pattern: "**" | ||
| owner: ubuntu | ||
| group: ubuntu | ||
|
|
||
| hooks: | ||
| AfterInstall: | ||
| - location: scripts/stop.sh | ||
| timeout: 60 | ||
| runas: ubuntu | ||
| ApplicationStart: | ||
| - location: scripts/start.sh | ||
| timeout: 60 | ||
| runas: ubuntu |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| PROJECT_ROOT="/home/ubuntu/project" | ||
| JAR_FILE="$PROJECT_ROOT/build/libs/org.j1p5-0.0.1.jar" | ||
|
|
||
| APP_LOG="$PROJECT_ROOT/application.log" | ||
| ERROR_LOG="$PROJECT_ROOT/error.log" | ||
| 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 | ||
|
|
||
| #jar 파일 실행 | ||
| echo "TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG | ||
| nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG & | ||
|
|
||
| CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
| echo "TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| PROJECT_ROOT="/home/ubuntu/project" | ||
| JAR_FILE="$PROJECT_ROOT/build/libs/org.j1p5-0.0.1.jar" | ||
|
|
||
| DEPLOY_LOG="$PROJECT_ROOT/deploy.log" | ||
|
|
||
| TIME_NOW=$(date +%c) | ||
|
|
||
| #현재 구동 중인 애플리케이션 pid 확인 | ||
| CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
|
|
||
| #프로세스가 켜져 있으면 종료 | ||
| if [ -z $CURRENT_PID ]; then | ||
| echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG | ||
| else | ||
| echo "TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG | ||
| kill -9 $CURRENT_PID | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌드와 배포가 단계가 겹치는데, ci / cd를 하나로 합치면 중복을 막을 수 있을 것 같아요