Skip to content

Commit

Permalink
chore: deploy action setting 수정 (#54)
Browse files Browse the repository at this point in the history
* fix: nginx.conf 주석 스타일 변경

CHZZ-105

* docs: Pull Request Template 수정

CHZZ-105

* chore: P6spy prod 비활성화

CHZZ-105

* chore: deploy action 최적화

CHZZ-105

* chore: PR title, branch name 검사하는 action 추가

CHZZ-105

* chore: 배포시 브랜치에서 버전 정보를 가져오는 것으로 수정

CHZZ-105

* chore: 배포시 릴리즈 태그와 노트를 자동화하는 설정 추가

CHZZ-105

* refactor: 브랜치 이름에서 버전 추출하는 로직 수정

CHZZ-105

* chore: main에 머지될때 자동으로 태그와 릴리즈 노트를 작성하는 설정 추가

CHZZ-105

* chore: PR 제목 검사하는 action 수정

CHZZ-105

* chore: PR types에 synchronize 추가

CHZZ-105
  • Loading branch information
junest66 authored Sep 25, 2024
1 parent d5e5f41 commit 33aba00
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## #️⃣연관된 이슈

[CHZZ-이슈번호] #done
[CHZZ-이슈번호]

## 📝작업 내용

<!-- 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능) -->

여기에 내용을 입력하세요.
- 여기에 내용을 입력하세요.

## ✅테스트 결과

Expand All @@ -20,4 +20,4 @@
<!-- 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 -->
<!-- 만약 없다면 이 부분을 삭제해주세요 -->

여기에 내용을 입력하세요.
- 여기에 내용을 입력하세요.
83 changes: 38 additions & 45 deletions .github/workflows/deployment-config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: CICD
name: CD
run-name: Running
on:
push:
branches:
- release
pull_request:
branches:
- release
- release/*
- hotfix/*

env:
AWS_REGION: ap-northeast-2
Expand All @@ -22,6 +20,25 @@ jobs:
with:
fetch-depth: 0

- name: Extract version from branch name
id: extract-version
run: |
BRANCH_NAME="${{ github.ref }}" # Full ref name, e.g., refs/heads/release/5.5.6
BRANCH_NAME=${BRANCH_NAME#refs/heads/} # Remove 'refs/heads/' prefix to get 'release/5.5.6'
# Display the extracted branch name for debugging
echo "Extracted branch name: $BRANCH_NAME"
# Check if the branch name matches the expected pattern
if [[ "$BRANCH_NAME" =~ ^(release|hotfix)/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[2]}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
else
echo "❌ Branch name does not match release/x.x.x or hotfix/x.x.x format."
exit 1
fi
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -48,54 +65,26 @@ jobs:
run: chmod +x ./gradlew

- name: gradle 빌드
run: ./gradlew build -x test -i
run: ./gradlew build -x test

- name: Docker 이미지 빌드 및 ECR 배포
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
IMAGE_TAG: ${{ env.VERSION }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: 기존 `compose.yaml` 파일 삭제
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
rm -f /home/ec2-user/compose.yaml
- name: EC2로 `docker-compose.yml` 파일 복사
- name: EC2로 파일 복사 (compose.yaml 및 nginx.conf 포함)
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: './compose.yaml'
target: '/home/ec2-user'

- name: EC2로 `nginx.conf` 파일 복사
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: './nginx.conf'
target: '/home/ec2-user'

- name: EC2에서 .env 파일 생성
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
touch /home/ec2-user/.env
echo ECR_IMAGE=${{ steps.build-image.outputs.image }} >> /home/ec2-user/.env
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: './compose.yaml,./nginx.conf'
target: '/home/ec2-user'

- name: EC2에서 Docker Compose를 통한 애플리케이션 실행
uses: appleboy/ssh-action@master
Expand All @@ -107,14 +96,18 @@ jobs:
export AWS_REGION=${{ env.AWS_REGION }}
export ECR_URI=${{ secrets.ECR_URI }}
# .env 파일 생성 및 ECR_IMAGE 변수 추가
touch /home/ec2-user/.env
echo ECR_IMAGE=${{ steps.build-image.outputs.image }} >> /home/ec2-user/.env
# ECR 레지스트리에 로그인
aws ecr get-login-password --region $AWS_REGION | sudo docker login --username AWS --password-stdin $ECR_URI/chzz-rep
# 기존 컨테이너 정지 및 삭제
sudo docker compose down
# 최신 이미지를 가져와서 환경 변수로 전달
sudo docker compose --env-file /home/ec2-user/.env pull
# 최신 이미지를 pull
sudo docker compose pull
# Docker Compose로 애플리케이션 실행
sudo docker compose --env-file /home/ec2-user/.env up -d
sudo docker compose up -d
52 changes: 52 additions & 0 deletions .github/workflows/pr-title-and-branch-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: PR Title and Branch Name Validation

on:
pull_request:
types: [ opened, edited, reopened, synchronize]
branches:
- main
- develop
- release/*
- hotfix/*

jobs:
validate-title-and-branch:
runs-on: ubuntu-latest
if: ${{ !(github.head_ref == 'main' && github.base_ref == 'develop') }} # main -> develop일 때는 실행하지 않음
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Validate PR Title
uses: Slashgear/[email protected]
with:
regexp: '^(feat|fix|docs|refactor|style|test|chore|design|move):\s.+$|^(release|hotfix):\s\d+\.\d+\.\d+$'
helpMessage: |
❌ PR 제목이 규칙을 따르지 않습니다.
제목은 다음 형식 중 하나여야 합니다:
- `<type>: <description>` (Allowed types: feat, fix, docs, refactor, style, test, chore, design, move)
- `release: x.x.x` (Semantic Versioning format)
- `hotfix: x.x.x` (Semantic Versioning format)
- name: Validate Branch Name
run: |
BRANCH_NAME="${{ github.head_ref }}"
# PR 브랜치 이름 검사
if [[ "$BRANCH_NAME" =~ ^(feat|fix|docs|refactor|style|test|chore|design|move)/.+$ ]]; then
echo "✅ Branch name follows the feature branch convention!"
elif [[ "$BRANCH_NAME" =~ ^(release|hotfix)/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "✅ Branch name follows the release or hotfix versioning convention!"
else
echo "❌ Branch name does not follow the conventional pattern."
echo "Ensure your branch name follows one of these formats:"
echo "- feat/*, fix/*, docs/*, refactor/*, style/*, test/*, chore/*, design/*, move/*"
echo "- release/x.x.x (Semantic Versioning format)"
echo "- hotfix/x.x.x (Semantic Versioning format)"
exit 1
fi
shell: bash

- name: PR Title and Branch Validation Success
if: success()
run: echo "✅ PR title and branch name follow the conventions!"
28 changes: 28 additions & 0 deletions .github/workflows/release-drafter-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🎁 새로운 기능이 추가되었어요'
label: '✨feature'
- title: '🐞 버그를 수정했어요'
label: '🐛bug'
- title: '🐬 코드를 개선했어요'
label: '🪄refactor'
- title: '⚙️ 설정 파일을 변경했어요'
label: '⚙️chore'
change-template: '- $TITLE #$NUMBER @$AUTHOR '
template: |
## 이번 버전의 변경사항은 아래와 같아요
---
$CHANGES
no-changes-template: '변경사항이 없어요'
version-resolver:
major:
labels:
- '✨ major'
minor:
labels:
- '✨ minor'
patch:
labels:
- '✨ patch'
default: patch
37 changes: 37 additions & 0 deletions .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Create Tag on PR Merge

on:
pull_request:
types: [closed]
branches:
- main
jobs:
tag:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create Tag
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
# 'release/' 또는 'hotfix/' 접두사를 제거
TAG_NAME="${BRANCH_NAME#release/}"
TAG_NAME="${TAG_NAME#hotfix/}"
# 태그 이름이 비어있을 경우 처리
if [ -z "$TAG_NAME" ]; then
echo "Error: TAG_NAME is empty. Please check the branch name."
exit 1
fi
git tag $TAG_NAME
git push origin $TAG_NAME
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update Release
uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
proxy_set_header Connection '';
proxy_set_header Cache_Control 'no-cache';
chunked_transfer_encoding on;
proxy_read_timeout 1920s; // Nginx가 백엔드 서버로부터 데이터를 받지 못하는 동안 대기할 최대 시간, 이 시간 동안 데이터가 안오면 연결 끊음 (클라이언트에서 재연결 요청)
proxy_read_timeout 1920s; # Nginx가 백엔드 서버로부터 데이터를 받지 못하는 동안 대기할 최대 시간, 이 시간 동안 데이터가 안오면 연결 끊음 (클라이언트에서 재연결 요청)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.p6spy.engine.spy.P6SpyOptions;
import jakarta.annotation.PostConstruct;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("!prod")
@Configuration
public class P6spyLogMessageFormatConfiguration {

Expand Down

0 comments on commit 33aba00

Please sign in to comment.