Skip to content

[한동우] sprint8 #222

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
wants to merge 35 commits into
base: 한동우
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
13a5d92
feat: 개발, 운영 환경에 대한 프로파일 구성
Dw-real Jun 18, 2025
e9ccaef
feat: 로그 관리 기능 추가
Dw-real Jun 19, 2025
72a497f
feat: 커스텀 예외 클래스 생성 및 ErrorResponse 추가
Dw-real Jun 19, 2025
70e3e1b
feat: Spring validation 적용 및 MethodArgumentNotValidException 처리 기능 추가
Dw-real Jun 19, 2025
84dacea
feat: Actuator 추가
Dw-real Jun 20, 2025
1b9d931
feat: User, Channel, Message 서비스 테스트 코드 추가
Dw-real Jun 23, 2025
df7cb61
feat: User, Channel, Message Repository 슬라이스 테스트 추가
Dw-real Jun 23, 2025
933479e
feat: User, Channel, Message Controller 슬라이스 테스트 추가
Dw-real Jun 23, 2025
f1c2f88
feat: User, Channel, Message Service 통합 테스트 추가
Dw-real Jun 24, 2025
67d2495
feat: MDC 인터셉터 기능 구현
Dw-real Jun 24, 2025
6c2fb05
feat: Spring Boot Admin 추가
Dw-real Jun 24, 2025
1dab248
feat: 테스트 커버리지 관리를 위한 jacoco 플러그인 추가
Dw-real Jun 27, 2025
90bfb1b
refactor: .idea/ 파일 추적 제거
Dw-real Jun 27, 2025
0fd8850
fix: Spring Boot Admin 관련 코드 삭제
Dw-real Jun 30, 2025
4ae6e02
feat: Dockerfile 추가
Dw-real Jul 1, 2025
b430fef
add: Docker Compose 구성
Dw-real Jul 1, 2025
3cc92f5
feat: AWS S3를 활용하여 BinaryContentStorage 구현
Dw-real Jul 1, 2025
5b41111
refactor: 멀티 스테이지 빌드를 통한 이미지 최적화
Dw-real Jul 4, 2025
cb459ec
add: CI를 위한 워크플로우 설정
Dw-real Jul 4, 2025
d5cbde7
fix: 설정 파일 변경
Dw-real Jul 4, 2025
e9c4fd7
fix: github-actions 실패 하는 부분 해결
Dw-real Jul 4, 2025
32f3085
add: Codecov 테스트 커버리지 뱃지 추가
Dw-real Jul 4, 2025
807ee7b
feat: CD를 위한 워크플로우 deploy.yml 추가
Dw-real Jul 7, 2025
1f85c15
fix: deploy.yml 수정
Dw-real Jul 7, 2025
418b364
fix: github actions fail 오류 수정
Dw-real Jul 7, 2025
e39a677
fix: deploy.yml 수정
Dw-real Jul 7, 2025
dc3d744
feat: CD를 위한 워크플로우 deploy.yml 추가
Dw-real Jul 7, 2025
4bc2b5f
fix: deploy.yml 수정
Dw-real Jul 7, 2025
a5573f1
fix: github actions fail 오류 수정
Dw-real Jul 7, 2025
c379913
fix: deploy.yml 수정
Dw-real Jul 7, 2025
d1fbdd2
refactor: dockerignore 수정 및 logback 파일 크기 정책 추가
Dw-real Jul 8, 2025
0600f5b
Merge remote-tracking branch 'origin/한동우-sprint8' into release
Dw-real Jul 8, 2025
edfa5d9
fix: SizeAndTimeBasedRollingPollicy 사용을 위해 파일 이름 패턴 %i 추가
Dw-real Jul 8, 2025
78a739b
test: AuthController 테스트 코드 추가 및 기존 테스트 코드 when then 명확히 구분
Dw-real Jul 8, 2025
096f616
refactor: aws 관련 gitignore 추가
Dw-real Jul 8, 2025
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
Binary file removed .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/.gradle
/build
/target

# IntelliJ IDEA
*.iml
.idea
*.iws
*.ipr
out/
.vscode/

# OS
.DS_Store

# 로그 파일
*.log

.gitignore
.git
README.md
Dockerfile
.dockerignore

# 환경 설정 파일
.env
discodeit.env

# 임시 파일
*.tmp
*.swp
137 changes: 137 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: CD Test

on:
push:
branches: [ "release" ]

env:
AWS_REGION_PUBLIC: us-east-1
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REPOSITORY_URI: ${{ secrets.ECR_REPOSITORY_URI }}
ECR_REPOSITORY: discodeit
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
CONTAINER_NAME: discodeit-app
IMAGE_TAG: ${{ github.sha }}

jobs:
build-and-push:
name: Build and Docker image push
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ env.AWS_REGION_PUBLIC }}

- name: Login to Amazon ECR public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build Docker image
id: build-image
run: |
chmod +x ./gradlew
./gradlew bootJar
docker build -t ${{ env.ECR_REPOSITORY_URI }}:latest -t ${{ env.ECR_REPOSITORY_URI}}:${IMAGE_TAG} .

- name: Delete old images (latest + dangling)
run: |
echo "Deleting 'latest' tagged image..."
aws ecr-public batch-delete-image \
--repository-name ${{ env.ECR_REPOSITORY }} \
--image-ids imageTag=latest || true

echo "Finding dangling images (no tags)..."
dangling=$(aws ecr-public describe-images \
--repository-name ${{ env.ECR_REPOSITORY }} \
--query 'imageDetails[?imageTags==`null` || length(imageTags)==`0`].imageDigest' \
--output json)

echo "Dangling images: $dangling"

if [ "$dangling" != "[]" ]; then
echo "$dangling" | jq -r '.[]' | while read digest; do
echo "Deleting image digest: $digest"
aws ecr-public batch-delete-image \
--repository-name ${{ env.ECR_REPOSITORY }} \
--image-ids imageDigest=$digest || true
done
else
echo "No dangling images to delete."
fi

- name: Push Docker images
run: |
docker push $ECR_REPOSITORY_URI:latest
docker push $ECR_REPOSITORY_URI:${IMAGE_TAG}

deploy:
name: Update ECS Service
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Update Task Definition
id: task-def
run: |
NEW_IMAGE="$ECR_REPOSITORY_URI:$IMAGE_TAG"

# 현재 태스크 정의 JSON을 받아와서 새 이미지로 교체
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} \
--query "taskDefinition" > taskdef.json

# 새 이미지 태그로 교체
jq --arg IMAGE "$NEW_IMAGE" '.containerDefinitions[0].image=$IMAGE' \
taskdef.json > new-taskdef.json

# 불필요한 필드 제거
jq 'del(.status, .revision, .taskDefinitionArn, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)' \
new-taskdef.json > final-taskdef.json

# 새 태스크 정의 등록
TASK_DEF_ARN=$(aws ecs register-task-definition --cli-input-json file://final-taskdef.json \
--query "taskDefinition.taskDefinitionArn" --output text)
echo "TASK_DEF_ARN=$TASK_DEF_ARN" >> $GITHUB_ENV

- name: Scale down ECS service (프리티어 리소스 고려)
run: |
echo "Scaling down ECS service to 0 tasks..."
aws ecs update-service \
--cluster ${{ env.ECS_CLUSTER }} \
--service ${{ env.ECS_SERVICE }} \
--desired-count 0
sleep 10

- name: Start ECS service
run: |
echo "Updating ECS service to new task definition..."
aws ecs update-service \
--cluster ${{ env.ECS_CLUSTER }} \
--service ${{ env.ECS_SERVICE }} \
--task-definition $TASK_DEF_ARN \
--desired-count 1
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI Test

on:
push:
branches: [ "한동우-sprint8" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17

- name: Install dependencies & run tests
run: ./gradlew clean test jacocoTestReport

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

## log 파일
.logs/

## 로컬 바이너리 파일
binaries/

## 환경 설정 파일
discodeit.env
.env

## AWS 관련 민감 파일들
*.pem
*.key
aws-credentials.txt
.aws/
credentials
config
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/compiler.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/gradle.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 1. 빌드
FROM amazoncorretto:17-alpine-jdk AS builder

ENV PROJECT_NAME=3-sprint-mission
ENV PROJECT_VERSION=1.2-M8

WORKDIR /app

# .dockerignore를 활용해 불필요한 파일 제외하고 복사
COPY . .

# 애플케이션 빌드
RUN chmod +x gradlew
RUN ./gradlew bootJar

# 2. 런타임
# 환경 변수 설정
FROM amazoncorretto:17-alpine

ENV PROJECT_NAME=3-sprint-mission
ENV PROJECT_VERSION=1.2-M8
ENV JVM_OPTS=""

# 작업 디렉토리 설정
WORKDIR /app

# 빌드 스테이지에서 JAR 파일만 복사
COPY --from=builder /app/build/libs/${PROJECT_NAME}-${PROJECT_VERSION}.jar app.jar

# 80 포트 노출
EXPOSE 80

# 애플리케이션 실행
ENTRYPOINT ["sh", "-c", "java $JVM_OPTS -jar app.jar"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![codecov](https://codecov.io/gh/dw-real/3-sprint-mission/branch/한동우-sprint8/graph/badge.svg)](https://codecov.io/gh/dw-real/3-sprint-mission)
Loading