-
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.
Browse files
Browse the repository at this point in the history
[#3] Setting: CI/CD 파이프라인 및 Slack 환경 구축
- Loading branch information
Showing
8 changed files
with
250 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
commands: | ||
set_time_zone: | ||
command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
commands: | ||
01_run_rabbitmq: | ||
command: "docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 -p 61613:61613 --restart=unless-stopped rabbitmq:management" | ||
test: "[[ ! $(docker ps -q -f name=rabbitmq) ]]" | ||
02_enable_rabbitmq: | ||
command: "docker exec rabbitmq bash -c 'rabbitmq-plugins enable rabbitmq_stomp && rabbitmq-plugins enable rabbitmq_management'" |
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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
name: Project CI/CD | ||
|
||
on: | ||
pull_request: | ||
types: [ closed ] # Pull Request가 닫힐 때만 트리거됨 | ||
workflow_dispatch: # GitHub UI 수동 실행도 가능 | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
# 닫힌 Pull Request가 실제로 merge 되었을때 && Pull Request가 develop 브랜치로 merge 되는 방향일때 | ||
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' | ||
steps: | ||
|
||
### Set Up ### | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'adopt' | ||
|
||
### Gradle ### | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
### Docker ### | ||
- name: Docker build | ||
run: | | ||
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | ||
docker build -t devrace-image . | ||
docker tag devrace-image sahyunjin/devrace-image:latest | ||
docker push sahyunjin/devrace-image:latest | ||
### Time ### | ||
- name: Get Current Time | ||
uses: 1466587594/get-current-time@v2 | ||
id: current-ksttime | ||
with: | ||
format: YYYY-MM-DDTHH:mm:ss | ||
utcOffset: "+09:00" # KST time = UTC time + 9hour | ||
|
||
### ZIP file ### | ||
- name: Generate deployment package | ||
run: | | ||
mkdir -p deploy | ||
cp -r .ebextensions deploy/.ebextensions | ||
cp Dockerrun.aws.json deploy/Dockerrun.aws.json | ||
cd deploy && zip -r deploy.zip . | ||
### AWS Elastic Beanstalk ### | ||
- name: Beanstalk Deploy | ||
uses: einaregilsson/beanstalk-deploy@v20 | ||
with: | ||
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
application_name: devrace-app | ||
environment_name: Devrace-env | ||
version_label: "github-action--${{ steps.current-ksttime.outputs.formattedTime }}" | ||
region: ap-northeast-2 | ||
deployment_package: deploy/deploy.zip | ||
wait_for_deployment: false | ||
|
||
### Slack Alarm for success deploy ### | ||
- name: Notify Slack on Success | ||
if: success() | ||
id: slack-success | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"channel": "C06FGQEQ1CP", | ||
"attachments": [ | ||
{ | ||
"color": "#36a64f", | ||
"title": ":white_check_mark: Success CI/CD", | ||
"title_link": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", | ||
"text": "'${{ github.event.pull_request.user.login }}'의 배포가 성공했습니다.", | ||
"fields": [ | ||
{ | ||
"title": "Repository", | ||
"value": "${{ github.repository }}", | ||
"short": true | ||
}, | ||
{ | ||
"title": "Branch", | ||
"value": "${{ github.event.pull_request.head.ref }}", | ||
"short": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | ||
|
||
### Slack Alarm for fail deploy ### | ||
- name: Notify Slack on Failure | ||
if: failure() | ||
id: slack-failure | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"channel": "C06FGQEQ1CP", | ||
"attachments": [ | ||
{ | ||
"color": "#ff0000", | ||
"title": ":x: Fail CI/CD", | ||
"title_link": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", | ||
"text": "'${{ github.event.pull_request.user.login }}'의 배포가 실패했습니다.", | ||
"fields": [ | ||
{ | ||
"title": "Repository", | ||
"value": "${{ github.repository }}", | ||
"short": true | ||
}, | ||
{ | ||
"title": "Branch", | ||
"value": "${{ github.event.pull_request.head.ref }}", | ||
"short": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Slack Alarm for PR open | ||
|
||
on: | ||
pull_request: | ||
types: [opened] # Pull Request가 새로 열렸을때 | ||
branches: [ develop ] # 다른 브랜치에서 develop 브랜치를 향하는 경우 | ||
|
||
jobs: | ||
notify-slack: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
### Slack Alarm for new PR ### | ||
- name: Notify Slack on PR open | ||
id: slack-success | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"channel": "C06FGQEQ1CP", | ||
"attachments": [ | ||
{ | ||
"color": "#f6f703", | ||
"title": ":bulb: New Pull-Request", | ||
"title_link": "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}", | ||
"text": "'${{ github.event.pull_request.user.login }}'의 PR이 오픈되었습니다.", | ||
"fields": [ | ||
{ | ||
"title": "Repository", | ||
"value": "${{ github.repository }}", | ||
"short": true | ||
}, | ||
{ | ||
"title": "PR_Branch", | ||
"value": "${{ github.event.pull_request.head.ref }}", | ||
"short": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Slack Alarm for PR review | ||
|
||
on: | ||
pull_request_review: | ||
types: [submitted] # Pull Request에 대한 리뷰가 제출되었을때 | ||
|
||
jobs: | ||
notify-slack: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
### Slack Alarm for PR review ### | ||
- name: Notify Slack on PR review | ||
if: ${{ github.event_name == 'pull_request_review' }} | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"channel": "C06FGQEQ1CP", | ||
"attachments": [ | ||
{ | ||
"color": "#0e5fd5", | ||
"title": ":speech_balloon: PR Review", | ||
"title_link": "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}", | ||
"text": "'${{ github.event.pull_request.user.login }}'의 PR에 '${{ github.event.review.user.login }}'가 리뷰를 남겼습니다.", | ||
"fields": [ | ||
{ | ||
"title": "Repository", | ||
"value": "${{ github.repository }}", | ||
"short": true | ||
}, | ||
{ | ||
"title": "PR Number", | ||
"value": "${{ github.event.pull_request.number }}", | ||
"short": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM openjdk:17-alpine | ||
CMD ["./gradlew", "clean", "build"] | ||
ARG JAR_FILE_PATH=build/libs/devrace-backend-0.0.1-SNAPSHOT.jar | ||
COPY ${JAR_FILE_PATH} app.jar | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"AWSEBDockerrunVersion": "1", | ||
"Image": { | ||
"Name": "sahyunjin/devrace-image:latest", | ||
"Update": "true" | ||
}, | ||
"Ports": [ | ||
{ | ||
"ContainerPort": 8080, | ||
"HostPort": 5000 | ||
} | ||
] | ||
} |
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