-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] CI/CD 파이프라인 구축 #5
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
Merged
Changes from 5 commits
Commits
Show all changes
6 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 |
|---|---|---|
| @@ -1 +1,59 @@ | ||
|
|
||
| name: CI/CD process | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| - "cicd" | ||
| pull_request: | ||
| branches: "main" | ||
|
|
||
| # 환경변수 설정 | ||
| env: | ||
| S3_BUCKET_NAME: enwise-bucket | ||
| AWS_REGION: ap-northeast-2 | ||
| CODEDEPLOY_NAME: plz-CodeDeploy | ||
| CODEDEPLOY_GROUP: plz-CodeDeploy-group | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방) | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Grant execute permission for gradlew | ||
| run: chmod +x ./gradlew | ||
| shell: bash | ||
|
|
||
| - name: Build with Gradle | ||
| run: ./gradlew build | ||
| shell: bash | ||
|
|
||
| # S3 설정 | ||
| - name: Make zip file | ||
| run: zip -r ./$GITHUB_SHA.zip . | ||
| shell: bash | ||
|
|
||
| - 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 }} | ||
|
|
||
| - name: Upload to S3 | ||
| run: aws s3 cp --region $AWS_REGION ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip | ||
|
|
||
| # CodeDeploy 설정 | ||
| - name: Code Deploy | ||
| run: aws deploy create-deployment --application-name $CODEDEPLOY_NAME --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name $CODEDEPLOY_GROUP --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.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,19 @@ | ||
| version: 0.0 | ||
| os: linux | ||
| files: | ||
| # 서버의 destination 에 source 파일 배포 | ||
| - source: / | ||
| destination: /home/ec2-user/plz/ | ||
| overwrite: yes | ||
| runas: ec2-user | ||
|
|
||
| permissions: | ||
| - object: /home/ec2-user/plz/ | ||
| pattern: "**" | ||
| owner: ec2-user | ||
| group: ec2-user | ||
|
|
||
| hooks: | ||
| # 배포 후 실행될 스크립트(start.sh) | ||
| ApplicationStart: | ||
| - location: ./scripts/start.sh |
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
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,32 @@ | ||
| #!/bin/bash | ||
|
|
||
| # JAR 파일명을 deploy.log에 기록. | ||
| JAR_DIR_PATH=/home/ec2-user/plz/build/libs/ | ||
| BUILD_JAR=$(ls $JAR_DIR_PATH*.jar | grep -nv 'plain') | ||
| JAR_NAME=$(basename $BUILD_JAR) | ||
| echo "> build 경로: $BUILD_JAR" >> /home/ec2-user/plz/deploy.log | ||
| echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/plz/deploy.log | ||
|
|
||
| # 빌드된 JAR 파일을 /home/ec2-user/ 디렉토리로 복사 | ||
| echo "> build 파일 복사" >> /home/ec2-user/plz/deploy.log | ||
| DEPLOY_PATH=/home/ec2-user/plz/ | ||
| #cp $BUILD_JAR $DEPLOY_PATH | ||
| cp $JAR_DIR_PATH$JAR_NAME $DEPLOY_PATH | ||
|
|
||
| echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/plz/deploy.log | ||
| CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
|
|
||
| # 현재 실행 중인 애플리케이션 종료 | ||
| if [ -z $CURRENT_PID ] | ||
| then | ||
| echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/plz/deploy.log | ||
| else | ||
| echo "> kill -15 $CURRENT_PID" | ||
| kill -15 $CURRENT_PID | ||
| sleep 5 | ||
| fi | ||
|
|
||
| # 새로운 JAR 파일 배포 및 실행 | ||
| DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
| echo "> DEPLOY_JAR 배포" >> /home/ec2-user/plz/deploy.log | ||
| nohup java -jar $DEPLOY_JAR >> /home/ec2-user/plz/deploy.log 2>/home/ec2-user/plz/deploy_err.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
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.
Uh oh!
There was an error while loading. Please reload this page.