Skip to content

[강문구] sprint8 #227

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 30 commits into
base: 강문구
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a27a6c7
fix: sprint-7 BaseCode 반영
Kangmoongu Jun 18, 2025
d4f77f9
feat: logging 구현
Kangmoongu Jun 19, 2025
ddef170
feat: 커스텀 예외처리 구현 및 Schema.sql 수정
Kangmoongu Jun 19, 2025
89da012
feat: Validation 구현
Kangmoongu Jun 20, 2025
f142dbc
feat: Validation 의존성 추가
Kangmoongu Jun 20, 2025
f3aabd5
feat: 기본 Actuator 엔트포인트 설정 및 Actuator info를 위한 애플리케이션 정보를 추가
Kangmoongu Jun 20, 2025
0d49b95
feat: Service 레이어 단위 테스트 구현 및 userService 버그 수정
Kangmoongu Jun 23, 2025
4e9ef03
feat: Controller, Service, Repository 단위 테스트 구현
Kangmoongu Jun 23, 2025
4b1392a
feat: 통합테스트 구현
Kangmoongu Jun 24, 2025
ef6c64d
feat: 심화요구사항 MDC를 통한 로깅 고도화 구현
Kangmoongu Jun 24, 2025
e428ef3
feat: SpringBoot Admin 의존성을 추가하여 Admin 관리와 대시보드 구현
Kangmoongu Jun 24, 2025
242ae72
feat: Service Test 패키지에 대해서 60% 이상의 코드 커버리지를 달성
Kangmoongu Jun 27, 2025
9424642
feat: Sprint8 BaseCode 반영
Kangmoongu Jul 4, 2025
5358c92
feat: Sprint8 Basecode 반영
Kangmoongu Jul 4, 2025
1e0c303
feat: Dockerfile 작성
Kangmoongu Jul 4, 2025
deae7a3
feat: docker-compose.yml 작성 및 docker 실행
Kangmoongu Jul 4, 2025
f26cff8
feat: BinaryContentStorage 고도화 (AWS S3) 구현
Kangmoongu Jul 6, 2025
f48a257
feat: 배포 환경에서 컨테이너 실행 간 사용할 환경 변수정의 및 .gitignore추가
Kangmoongu Jul 7, 2025
37ad85e
fix: AWS S3 초기화 로직 오류수정
Kangmoongu Jul 7, 2025
03f7444
feat: 심화 요구사항 구현(이미지 최적화, GitHub Actions를 활용한 CI/CD 파이프라인 구축)
Kangmoongu Jul 8, 2025
04b76d5
fix: test.yml 수정
Kangmoongu Jul 8, 2025
7a1faa2
fix: deploy.yml 공백수정
Kangmoongu Jul 8, 2025
346d5f7
fix: 버그수정
Kangmoongu Jul 8, 2025
9ff2c70
fix: deploy.yml 오류 수정
Kangmoongu Jul 8, 2025
604993d
fix: deploy.yml 오류 수정
Kangmoongu Jul 8, 2025
318f355
fix: deploy.yml 오류 수정
Kangmoongu Jul 8, 2025
aec4ea6
fix: findByUserId_ExistingUserId_ReturnsUserStatus() 수정
Kangmoongu Jul 8, 2025
d6c2ed3
fix: test.yml에서 AWSS3Test는 사용하지 않는것으로 설정
Kangmoongu Jul 8, 2025
eed3a68
fix: 단위테스트만 테스트 수행하도록 변경
Kangmoongu Jul 8, 2025
4dbc64b
fix: 통합테스트와 S3테스트는 제외
Kangmoongu 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
50 changes: 50 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Git 관련
.git
.gitignore
.gitattributes
.github

# IDE 관련
.idea/
.vscode/
*.iml
*.ipr
*.iws

# 빌드 출력물
build/
out/
target/

# Gradle 관련
.gradle/
gradle-wrapper.jar

# 로그 파일
*.log
logs/

# 임시 파일
*.tmp
*.temp
.DS_Store
Thumbs.db

# 문서 파일
README.md
*.md
docs/

# Docker 관련
Dockerfile*
.dockerignore
docker-compose.yml

# 테스트 관련
**/test-results/
**/coverage/

# 백업 파일
*.bak
*.backup

3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

101 changes: 101 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CD - Deploy

on:
push:
branches: [ release ]

jobs:
build-and-push:
runs-on: ubuntu-latest

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

- name: Configure AWS credentials for ECR
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: us-east-1

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

- name: Build and push Docker iamge
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ vars.ECR_REPOSITORY_URI }}:latest
${{ vars.ECR_REPOSITORY_URI }}:${{ github.sha }}
platforms: linux/amd64

deploy:
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: Configure AWS credentials for ECS
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: ${{ vars.AWS_REGION }}


# 기존 태스크 정의 다운로드 및 새 이미지로 업데이트
- name: Update task definition with new image
run: |
# 기존 태스크 정의 다운로드
aws ecs describe-task-definition \
--task-definition ${{ vars.ECS_TASK_DEFINITION }} \
--query 'taskDefinition' > task-def.json

# 새 이미지 URI로 업데이트
NEW_IMAGE="${{ vars.ECR_REPOSITORY_URI }}:latest"

# 새 태스크 정의 생성 (읽기 전용 필드들 제거)
jq --arg img "$NEW_IMAGE" '
del(.taskDefinitionArn, .revision, .status, .registeredAt, .registeredBy, .placementConstraints, .compatibilities, .requiresAttributes) |
.containerDefinitions[0].image = $img
' task-def.json > new-task-def.json

# 새 태스크 정의 등록
NEW_TASK_DEF=$(aws ecs register-task-definition \
--cli-input-json file://new-task-def.json \
--query 'taskDefinition.taskDefinitionArn' \
--output text)

echo "NEW_TASK_DEF_ARN=$NEW_TASK_DEF" >> $GITHUB_ENV

# 프리티어 고려: 기존 서비스 중단 후 새 서비스 시작
- name: Deploy to ECS (Free tier safe)
run: |
# 1. 기존 서비스 중단 (리소스 절약)
echo "Stopping existing service..."
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }} \
--desired-count 0

# 2. 서비스 중단 대기
aws ecs wait services-stable \
--cluster ${{ vars.ECS_CLUSTER }} \
--services ${{ vars.ECS_SERVICE }}

# 3. 새 태스크 정의로 서비스 업데이트 및 시작
echo "Starting service with new task definition..."
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }} \
--task-definition $NEW_TASK_DEF_ARN \
--desired-count 1

# 4. 배포 완료 대기
aws ecs wait services-stable \
--cluster ${{ vars.ECS_CLUSTER }} \
--services ${{ vars.ECS_SERVICE }}
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI - Test

on:
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

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

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run unit tests only
run: ./gradlew test jacocoTestReport
env:
SPRING_PROFILES_ACTIVE: test

- name: Upload coverage to Codecov
if: success() || failure()
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./build/reports/jacoco/test/jacocoTestReport.xml
flags: unittests
name: codecov-java-17
fail_ci_if_error: false
33 changes: 22 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
Expand All @@ -17,15 +25,6 @@ bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
Expand All @@ -35,3 +34,15 @@ out/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store

### Discodeit ###
.discodeit

### 숨김 파일 ###
.logs
!.gitignore
.env
discodeit.env
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Multi-stage build를 사용하여 이미지 크기 최적화
# Stage 1: 빌드 스테이지
FROM amazoncorretto:17 AS build

# 작업 디렉토리를 설정하세요. (/app)
WORKDIR /app

# Gradle 관련 파일들을 먼저 복사 (레이어 캐싱 최적화)
COPY gradlew gradlew.bat ./
COPY gradle/ gradle/
COPY build.gradle settings.gradle ./

# Gradle wrapper에 실행 권한 부여
RUN chmod +x gradlew


# 소스 코드 복사
COPY src/ src/

# 애플리케이션 빌드 (테스트 건너뛰기, 데몬 비활성화로 메모리 절약)
RUN ./gradlew build -x test --no-daemon

# Stage 2: 실행 스테이지 (경량 이미지)
FROM amazoncorretto:17-alpine

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

# 프로젝트 정보를 환경 변수로 설정
ENV PROJECT_NAME=discodeit
ENV PROJECT_VERSION=1.2-M8
ENV JVM_OPTS=""

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

# 80 포트 노출
EXPOSE 80

# 애플리케이션 실행
# 시작 스크립트 생성 (따옴표 제거 처리 포함)
RUN echo '#!/bin/sh' > /start.sh && \
echo 'echo "=== Environment Variables ==="' >> /start.sh && \
echo 'env | grep -E "(JVM_OPTS|JAVA_OPTS)"' >> /start.sh && \
echo 'echo "============================="' >> /start.sh && \
echo '' >> /start.sh && \
echo '# JVM_OPTS에서 따옴표 제거' >> /start.sh && \
echo 'if [ -n "$JVM_OPTS" ]; then' >> /start.sh && \
echo ' # 앞뒤 따옴표 제거' >> /start.sh && \
echo ' JVM_OPTS=$(echo "$JVM_OPTS" | sed "s/^\"\(.*\)\"$/\1/")' >> /start.sh && \
echo ' echo "Cleaned JVM_OPTS: $JVM_OPTS"' >> /start.sh && \
echo 'else' >> /start.sh && \
echo ' JVM_OPTS="-Xmx512m -Xms256m"' >> /start.sh && \
echo ' echo "Using default JVM_OPTS: $JVM_OPTS"' >> /start.sh && \
echo 'fi' >> /start.sh && \
echo '' >> /start.sh && \
echo 'echo "Final command: java $JVM_OPTS -jar /app/app.jar"' >> /start.sh && \
echo 'exec java $JVM_OPTS -jar /app/app.jar' >> /start.sh && \
chmod +x /start.sh

ENTRYPOINT ["/start.sh"]
22 changes: 22 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.0/gradle-plugin)
* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.0/gradle-plugin/packaging-oci-image.html)
* [Spring Web](https://docs.spring.io/spring-boot/3.4.0/reference/web/servlet.html)

### Guides
The following guides illustrate how to use some features concretely:

* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)

### Additional Links
These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 0-spring-mission
스프린트 미션 모범 답안 리포지토리입니다.
Loading