Skip to content
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

[#3] Setting: CI/CD 파이프라인 및 Slack 환경 구축 #4

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ebextensions/00-set-timezone.config
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
6 changes: 6 additions & 0 deletions .ebextensions/01-rabbitmq.config
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'"
133 changes: 133 additions & 0 deletions .github/workflows/deploy.yml
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
44 changes: 44 additions & 0 deletions .github/workflows/slack-pr-open.yml
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
43 changes: 43 additions & 0 deletions .github/workflows/slack-pr-review.yml
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
5 changes: 5 additions & 0 deletions Dockerfile
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"]
13 changes: 13 additions & 0 deletions Dockerrun.aws.json
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
}
]
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

// WebSocket & Stomp
// implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-websocket'

// rabbitMQ
// implementation 'org.springframework.boot:spring-boot-starter-amqp'
// implementation 'org.springframework.boot:spring-boot-starter-reactor-netty:3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation 'org.springframework.boot:spring-boot-starter-reactor-netty:3.0.0'

// AWS S3
// implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Expand Down
Loading