Skip to content
Open
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
87 changes: 87 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: 배포

on:
push:
branches:
- release

jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ github.sha }}

steps:
- uses: actions/checkout@v4

- name: AWS CLI 설정
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: ECR 로그인
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Docker 이미지 빌드 및 푸시
run: |
docker buildx build \
-t ${{ vars.ECR_REPOSITORY_URI }}:${{ github.sha }} \
-t ${{ vars.ECR_REPOSITORY_URI }}:latest \
--push \
.
deploy:
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: AWS CLI 설정
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: ECS 태스크 정의 업데이트
run: |
TASK_DEFINITION=$(
aws ecs describe-task-definition \
--task-definition ${{ vars.ECS_TASK_DEFINITION }}
)

NEW_TASK_DEFINITION=$(
echo $TASK_DEFINITION | jq \
--arg IMAGE "${{ vars.ECR_REPOSITORY_URI }}:latest" \
'.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)'
)

# 새로운 태스크 정의 등록
NEW_TASK_DEF_ARN=$(
aws ecs register-task-definition \
--cli-input-json "$NEW_TASK_DEFINITION" | \
jq -r '.taskDefinition.taskDefinitionArn'
)

# 환경 파일에 변수 저장 (다음 단계에서 사용 가능)
echo "NEW_TASK_DEF_ARN=$NEW_TASK_DEF_ARN" >> $GITHUB_ENV

- name: ECS 서비스 중지(프리티어 환경 고려)
run: |
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }} \
--desired-count 0

- name: ECS 서비스 업데이트
run: |
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }} \
--task-definition $NEW_TASK_DEF_ARN \
--desired-count 1 \
--force-new-deployment

30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 테스트

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: JDK 17 설정
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
cache: gradle

- name: 테스트 실행
run: ./gradlew test

- name: Codecov 테스트 커버리지 업로드
uses: codecov/codecov-action@v3
with:
files: build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.CODECOV_TOKEN }} # 퍼블릭 저장소라면 생략 가능
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ bin/
.DS_Store

### Discodeit ###
.discodeit
.discodeit

### 숨김 파일 ###
.*
!.gitignore


### Github Actions ###
!.github/
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 빌드 스테이지
FROM amazoncorretto:17 AS builder

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

# Gradle Wrapper 파일 먼저 복사
COPY gradle ./gradle
COPY gradlew ./gradlew

# Gradle 캐시를 위한 의존성 파일 복사
COPY build.gradle settings.gradle ./

# 의존성 다운로드
RUN ./gradlew dependencies

# 소스 코드 복사 및 빌드
COPY src ./src
RUN ./gradlew build -x test


# 런타임 스테이지
FROM amazoncorretto:17-alpine3.21

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

# 프로젝트 정보를 ENV로 설정
ENV PROJECT_NAME=discodeit \
PROJECT_VERSION=1.2-M8 \
JVM_OPTS=""

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

# 80 포트 노출
EXPOSE 80

# jar 파일 실행
ENTRYPOINT ["sh", "-c", "java ${JVM_OPTS} -jar ${PROJECT_NAME}-${PROJECT_VERSION}.jar"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 0-spring-mission

스프린트 미션 모범 답안 리포지토리입니다.

[![codecov](https://codecov.io/gh/codeit-bootcamp-spring/0-sprint-mission/branch/s8%2Fadvanced/graph/badge.svg?token=XRIA1GENAM)](https://codecov.io/gh/codeit-bootcamp-spring/0-sprint-mission)
40 changes: 38 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
}

group = 'com.sprint.mission'
version = '0.0.1-SNAPSHOT'
version = '2.2-M11'

java {
toolchain {
Expand All @@ -17,6 +18,9 @@ configurations {
compileOnly {
extendsFrom annotationProcessor
}
testCompileOnly {
extendsFrom testAnnotationProcessor
}
}

repositories {
Expand All @@ -25,13 +29,45 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.4'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'software.amazon.awssdk:s3:2.31.7'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'com.nimbusds:nimbus-jose-jwt:10.3'

runtimeOnly 'org.postgresql:postgresql'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.mapstruct:mapstruct:1.6.3'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.retry:spring-retry'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'com.github.ben-manes.caffeine:caffeine'
}

tasks.named('test') {
useJUnitPlatform()
}

test {
finalizedBy jacocoTestReport
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
}
}
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.8'

services:
app:
image: discodeit:local
build:
context: .
dockerfile: Dockerfile
container_name: discodeit
ports:
- "8081:80"
environment:
- SPRING_PROFILES_ACTIVE=prod
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/discodeit
- SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME}
- SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}
- STORAGE_TYPE=s3
- STORAGE_LOCAL_ROOT_PATH=.discodeit/storage
- AWS_S3_ACCESS_KEY=${AWS_S3_ACCESS_KEY}
- AWS_S3_SECRET_KEY=${AWS_S3_SECRET_KEY}
- AWS_S3_REGION=${AWS_S3_REGION}
- AWS_S3_BUCKET=${AWS_S3_BUCKET}
- AWS_S3_PRESIGNED_URL_EXPIRATION=600
depends_on:
- db
volumes:
- binary-content-storage:/app/.discodeit/storage
networks:
- discodeit-network

db:
image: postgres:16-alpine
container_name: discodeit-db
environment:
- POSTGRES_DB=discodeit
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
- ./src/main/resources/schema.sql:/docker-entrypoint-initdb.d/schema.sql
networks:
- discodeit-network

volumes:
postgres-data:
binary-content-storage:

networks:
discodeit-network:
driver: bridge
14 changes: 14 additions & 0 deletions src/main/java/com/sprint/mission/discodeit/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sprint.mission.discodeit.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableJpaAuditing
@EnableScheduling
@EnableRetry
public class AppConfig {

}
31 changes: 31 additions & 0 deletions src/main/java/com/sprint/mission/discodeit/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sprint.mission.discodeit.config;

import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {

@Bean(name = "customTaskExecutor")
public TaskExecutor taskExecutor() {

ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

executor.setCorePoolSize(4);
executor.setMaxPoolSize(8);
executor.setQueueCapacity(50);
executor.setKeepAliveSeconds(30);
executor.setThreadNamePrefix("CustomExecutor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setTaskDecorator(new MDCTaskDecorator());

executor.initialize();

return executor;
}
}
Loading