Skip to content

[조현아] sprint8 #228

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 39 commits into
base: 조현아
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3b7c13a
처음 커밋
hyohyo-zz Apr 7, 2025
ac14b60
2
hyohyo-zz Apr 7, 2025
d0fd938
refactor: sprint7 베이스 코드 참고하여 로직개선
hyohyo-zz Jun 19, 2025
fecd2b0
feat: 환경별 프로파일 설정 및 로깅 기능 구성
hyohyo-zz Jun 19, 2025
86f4c10
chore: AOP, 서비스 메서드 로깅 추가
hyohyo-zz Jun 19, 2025
cd448f2
docs: update README
hyohyo-zz Jun 19, 2025
bd47c13
merge sprint7
hyohyo-zz Jun 19, 2025
196b1e4
Create README.md
hyohyo-zz Jun 19, 2025
afebc79
feat: 커스텀예외처리 생성, 적용/yaml,logback 수정
hyohyo-zz Jun 20, 2025
541c835
chore: .gitignore에 로그 및 저장소 폴더 추가, Git 추적에서 제거
hyohyo-zz Jun 20, 2025
9180153
feat: spring validation을 이용한 유효성 검사
hyohyo-zz Jun 22, 2025
17781f4
feat: actuator 설정
hyohyo-zz Jun 22, 2025
d08d5e1
feat: dto 유효성 수정
hyohyo-zz Jun 24, 2025
7963332
test: 단위 테스트 작성
hyohyo-zz Jun 24, 2025
bb15449
refactor: 서비스코드 수정
hyohyo-zz Jun 24, 2025
1f89565
feat: dto에 제약 조건 추가, Controller에 @Valid 추가
hyohyo-zz Jun 26, 2025
5fe1aa3
test: 슬라이스 테스트 작성
hyohyo-zz Jun 26, 2025
adb9a74
test: 통합테스트 작성
hyohyo-zz Jun 29, 2025
6c83246
test: 통합테스트 수정, 유효성검증 수정
hyohyo-zz Jun 29, 2025
6eae093
sprint7 모범답안 반영
hyohyo-zz Jul 1, 2025
c444966
feat: 애플리케이션 컨테이너화
hyohyo-zz Jul 1, 2025
b265105
test: AWSS3 Test
hyohyo-zz Jul 2, 2025
4057ad7
feat: S3BinaryContentStorage 고도화
hyohyo-zz Jul 3, 2025
563b855
test: 3BinaryContentStorageTest
hyohyo-zz Jul 3, 2025
7192811
feat: s3 버킷 폴더 지정, yaml 파일 수정
hyohyo-zz Jul 6, 2025
52a45e9
feat: s3 테스트 확인을 위해 test2 파일 추가, 변경
hyohyo-zz Jul 6, 2025
1e08abc
chore: 형상관리를 위한 파일 추가
hyohyo-zz Jul 6, 2025
9ac0465
refactor: sprint7 리뷰반영
hyohyo-zz Jul 6, 2025
299bf0d
chore: .dockerignore 수정
hyohyo-zz Jul 6, 2025
b4d4885
feat: Add GitHub Actions CI/CD workflows and test coverage
hyohyo-zz Jul 7, 2025
8346934
resolve: Fix merge conflicts and add GitHub Actions CI/CD workflows
hyohyo-zz Jul 7, 2025
7e4ca0a
feat: ECS 자동 배포 스크립트 및 테스트 환경 정리
hyohyo-zz Jul 7, 2025
60898bd
feat: CI 테스트 및 커버리지 설정
hyohyo-zz Jul 7, 2025
a87dd83
Merge branch 'main' into 조현아-sprint8
hyohyo-zz Jul 7, 2025
d32c29e
fix: s3 test env 주입 변경
hyohyo-zz Jul 7, 2025
b86b680
Merge pull request #17 from hyohyo-zz/조현아-sprint8
hyohyo-zz Jul 7, 2025
c224e7d
Update README.md
hyohyo-zz Jul 7, 2025
99f9916
chore: s3 로그 추가
hyohyo-zz Jul 8, 2025
dd6b851
chore: import 제거
hyohyo-zz 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
57 changes: 57 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# .dockerignore - 이미지 최적화를 위한 설정

# Build artifacts
build/
target/
*.jar
*.war

.gradle/

# IDE files
.idea/
*.iml
.vscode/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Git
.git/
.gitignore

# Docker files
Dockerfile*
docker-compose*.yml
.dockerignore

# Documentation
README.md
*.md
docs/

# Logs
*.logs
*.logs.*

# Temporary files
tmp/
temp/

# Node modules (if any)
node_modules/

# Environment files
.env*

# Test files (빌드 시에만 필요)
src/test/

# Gradle wrapper jar는 포함 (빌드에 필요)
!gradle/wrapper/gradle-wrapper.jar

.discodeit/storage/
/binary-contents/
9 changes: 7 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@

## 요구사항

### 기본

- 작성한 .env 파일은 리뷰를 위해 PR에 별도로 첨부해주세요. 단, 엑세스 키와 시크릿 키는 제외하세요.
- [x] 기본 항목 1
- [ ] 기본 항목 2

### 심화

- [ ] 심화 항목 1
- [ ] 심화 항목 2

## 주요 변경사항
-
-

-

## 스크린샷

![image](이미지url)

## 멘토에게

- 셀프 코드 리뷰를 통해 질문 이어가겠습니다.
-
172 changes: 172 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
name: CD - Deploy to AWS ECS

on:
push:
branches: [ release ]

env:
AWS_REGION: ${{ vars.AWS_REGION }}
ECR_REPOSITORY_URI: ${{ vars.ECR_REPOSITORY_URI }}
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }}
ECS_SERVICE: ${{ vars.ECS_SERVICE }}
ECS_TASK_DEFINITION: ${{ vars.ECS_TASK_DEFINITION }}

jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
image-uri: ${{ steps.build.outputs.image-uri }}
commit-sha: ${{ steps.meta.outputs.commit-sha }}

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 # Public ECR은 us-east-1에서만 사용 가능

- name: Login to Amazon ECR Public
id: login-ecr-public
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws

- name: Extract metadata and prepare tags
id: meta
run: |
COMMIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "commit-sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "image-latest=${{ env.ECR_REPOSITORY_URI }}:latest" >> $GITHUB_OUTPUT
echo "image-commit=${{ env.ECR_REPOSITORY_URI }}:${COMMIT_SHA}" >> $GITHUB_OUTPUT

- name: Build and push Docker image
id: build
run: |
# Docker 이미지 빌드 (단일 플랫폼: linux/amd64)
docker build -t ${{ steps.meta.outputs.image-latest }} .
docker tag ${{ steps.meta.outputs.image-latest }} ${{ steps.meta.outputs.image-commit }}

# ECR에 푸시
docker push ${{ steps.meta.outputs.image-latest }}
docker push ${{ steps.meta.outputs.image-commit }}

# 출력 설정
echo "image-uri=${{ steps.meta.outputs.image-latest }}" >> $GITHUB_OUTPUT

echo "이미지 빌드 및 푸시 완료:"
echo " - ${{ steps.meta.outputs.image-latest }}"
echo " - ${{ steps.meta.outputs.image-commit }}"

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

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: ${{ env.AWS_REGION }} # ECS 클러스터 접근용 리전

- name: Download current task definition
run: |
aws ecs describe-task-definition \
--task-definition ${{ env.ECS_TASK_DEFINITION }} \
> task-definition.json

echo "현재 태스크 정의 다운로드 완료"

- name: Update task definition with new image
run: |
echo "태스크 정의에 새 이미지 적용..."

# 새 이미지 URI로 태스크 정의 업데이트
NEW_IMAGE_URI="${{ needs.build-and-push.outputs.image-uri }}"

# 기존 태스크 정의를 가져오되, 꼭 필요한 필드만 추출
jq \
--arg IMAGE "$NEW_IMAGE_URI" \
'.taskDefinition
| {
family,
taskRoleArn,
executionRoleArn,
networkMode,
containerDefinitions,
volumes,
placementConstraints,
requiresCompatibilities,
cpu,
memory
}
| .containerDefinitions[0].image = $IMAGE' \
task-definition.json > updated-task-definition.json

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

echo "NEW_TASK_DEFINITION_ARN=${NEW_TASK_DEF_ARN}" >> $GITHUB_ENV
echo "새 태스크 정의 등록 완료: ${NEW_TASK_DEF_ARN}"

- name: Stop current ECS service (프리티어 고려)
run: |
echo "⏹현재 ECS 서비스 중단 (프리티어 리소스 고려)..."

aws ecs update-service \
--cluster ${{ env.ECS_CLUSTER }} \
--service ${{ env.ECS_SERVICE }} \
--desired-count 0

echo "태스크 완전 중단 대기 중..."
aws ecs wait services-stable \
--cluster ${{ env.ECS_CLUSTER }} \
--services ${{ env.ECS_SERVICE }}

echo "기존 서비스 중단 완료"

- name: Deploy updated task definition to ECS
run: |
echo "새 태스크 정의로 ECS 서비스 업데이트..."

aws ecs update-service \
--cluster ${{ env.ECS_CLUSTER }} \
--service ${{ env.ECS_SERVICE }} \
--task-definition ${{ env.NEW_TASK_DEFINITION_ARN }} \
--desired-count 1

echo "서비스 안정화 대기 중..."
aws ecs wait services-stable \
--cluster ${{ env.ECS_CLUSTER }} \
--services ${{ env.ECS_SERVICE }}

echo "ECS 서비스 업데이트 완료"

- name: Deployment notification
if: success()
run: |
echo "배포가 성공적으로 완료되었습니다!"
echo ""
echo "배포된 이미지:"
echo " - URI: ${{ needs.build-and-push.outputs.image-uri }}"
echo " - Commit: ${{ needs.build-and-push.outputs.commit-sha }}"
echo ""
echo "AWS 리소스:"
echo " - ECS 클러스터: ${{ env.ECS_CLUSTER }}"
echo " - ECS 서비스: ${{ env.ECS_SERVICE }}"
echo " - 태스크 정의: ${{ env.NEW_TASK_DEFINITION_ARN }}"
echo ""
echo "🔗 AWS 콘솔에서 확인:"
echo " - https://console.aws.amazon.com/ecs/home?region=${{ env.AWS_REGION }}#/clusters/${{ env.ECS_CLUSTER }}/services"

- name: Deployment failure notification
if: failure()
run: |
echo "배포 중 오류가 발생했습니다."
echo "AWS 콘솔에서 ECS 서비스 상태를 확인해주세요."
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI Test

on:
pull_request:
branches: [ main ]
workflow_dispatch:

env:
AWS_S3_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_S3_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
AWS_S3_REGION: ${{ vars.AWS_REGION }}
AWS_S3_BUCKET: ${{ vars.AWS_BUCKET }}
AWS_S3_PRESIGNED_URL_EXPIRATION: ${{ vars.AWS_EXPIRATION }}

jobs:
build:
runs-on: ubuntu-latest

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

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

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

- name: Run tests and generate coverage
run: ./gradlew test
env:
SPRING_PROFILES_ACTIVE: test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ out/
### VS Code ###
.vscode/

# 파일 저장소 (사용자가 업로드한 파일들)
.discodeit/storage/
/binary-contents/

# 로그 파일들
*.logs
*.logs.*

# 기타
*.ser

.env

discodeit.env
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 1. 빌드 이미지
FROM amazoncorretto:17 AS builder

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

# Gradle Wrapper와 빌드 스크립트 복사 (레이어 캐시 최적화)
COPY gradlew .
COPY gradle/ gradle/
COPY build.gradle .
COPY settings.gradle .

# 의존성 다운로드 (별도 레이어로 캐시 최적화)
# Gradle 실행 권한 부여
RUN chmod +x ./gradlew
RUN ./gradlew dependencies --no-daemon

# 파일 복사
COPY . .

# Gradle Wrapper를 사용한 애플리케이션 빌드
RUN ./gradlew clean build -x test --no-daemon

# ========================================
# 런타임 이미지
# ========================================
FROM amazoncorretto:17-alpine AS runtime

WORKDIR /app

# 빌드 결과물 경로 설정
ARG PROJECT_NAME=discodeit
ARG PROJECT_VERSION=1.2-M8

# JAR 복사
COPY --from=builder /app/build/libs/${PROJECT_NAME}-${PROJECT_VERSION}.jar app.jar

# 환경 변수 설정
ENV JVM_OPTS=""

# 80 포트 노출
EXPOSE 80

# 애플리케이션 실행
CMD ["sh", "-c", "java $JVM_OPTS -jar app.jar --spring.profiles.active=prod --server.port=80"]
3 changes: 3 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Getting Started

### Reference Documentation

For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.org)
Expand All @@ -9,13 +10,15 @@ For further reference, please consider the following sections:
* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/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)
Expand Down
Loading