Skip to content

[김창우] sprint8 #391

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

Conversation

qwertyuiop4m
Copy link
Collaborator

@qwertyuiop4m qwertyuiop4m commented Apr 14, 2025

요구사항

기본

  • 애플리케이션 컨테이너화
  • BinaryContentStorage 고도화 (AWS S3)
  • AWS를 활용한 배포 (AWS RDS, ECR, ECS)

심화

  • 이미지 최적화하기
    image
  • GitHub Actions를 활용한 CI/CD 파이프라인 구축
  • CI
    image
    image
  • CD
    image

스크린샷

env 파일

제출용.txt

RDS

image
image

ECR

image
image

ECS

image
image

VPC

image

IAM

image

배포

image

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@qwertyuiop4m qwertyuiop4m requested a review from youngxpepp April 14, 2025 09:11
@qwertyuiop4m qwertyuiop4m added the 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. label Apr 14, 2025
Copy link
Collaborator

@youngxpepp youngxpepp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

창우님 고생하셨습니다!

CI/CD 전반적으로 잘해주셔서 크게 고쳐야 될건 없다고 생각해요.
피드백 드린 부분도 사실 정보성 리뷰라 과제 채점에 큰 영향을 주진 않았어요ㅎㅎ
과제 양이 많았는데 요구사항 대부분 다 지켜주셨네요👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gitignore에 .idea가 있는데도 불구하고 제외가 안되나 보네요!
아래 글 보시겠어요?
https://coding-groot.tistory.com/59

Comment on lines +7 to +9
# 필요한 거 먼저 복사
COPY build.gradle settings.gradle gradlew /app/
COPY gradle /app/gradle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dockerfile을 작성할 땐 잘 안 바뀌는 파일을 먼저 COPY 해주시는게 좋습니다.
build.gradle, settings.gradle, gradlew, gradle
위 4개 파일을 잘 안 바뀔거 같은 순서대로 나열해보세요ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미지 레이어에 대해선 아래 도커 공식문서 글 보시면 좋습니다!

https://docs.docker.com/get-started/docker-concepts/building-images/understanding-image-layers/

Comment on lines +11 to +12
# 의존성 미리 다운(캐시)
RUN chmod +x gradlew && ./gradlew dependencies --no-daemon
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradlew는 내부적으로 gradle을 다운로드 합니다.
builder 스테이지의 베이스 이미지가 gradle:8.10-jdk17-alpine 네요.

두 가지중 하나를 선택하는게 어떨까요?

  1. 베이스 이미지 gradle
  2. 베이스 이미지 amazoncorretto + gradlew

Comment on lines +14 to +15
# 전체 프로젝트 복사 (.dockerignore로 불필요 파일 제외)
COPY . /app
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 전체 프로젝트 복사 (.dockerignore로 불필요 파일 제외)
COPY . /app
# 전체 프로젝트 복사 (.dockerignore로 불필요 파일 제외)
COPY . .

WORKDIR /app 으로 설정해두셨기 때문에 경로 지정을 하지 않아도 되겠네요ㅎㅎ

Comment on lines +38 to +39
# jar 파일 실행 (환경변수 활용)
CMD ["sh", "-c", "java $JVM_OPTS -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app/app.jar"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 실행한다면 1번 프로세스가 쉘이 되겠네요.
컨테이너가 종료될 때 1번 프로세스에 종료 시그널이 전달됩니다.
자바 어플리케이션에 종료 시그널이 전달 되지 않으면 graceful shutdown 을 하기가 어려워요.

정말 중요한 내용이라 아래 글을 번역해서라도 읽어보셨으면 좋겠습니다.

https://engineering.pipefy.com/2021/07/30/1-docker-bits-shell-vs-exec/

Comment on lines +18 to +39
@Slf4j
@Configuration
public class StorageConfig {

@Bean
@ConditionalOnProperty(name = "discodeit.storage.type", havingValue = "S3")
public S3Client s3Client(
@Value("${discodeit.storage.s3.access-key}") String accessKey,
@Value("${discodeit.storage.s3.secret-key}") String secretKey,
@Value("${discodeit.storage.s3.region}") String region
) {
return S3Client.builder()
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
)).build();
}

@Bean
@ConditionalOnProperty(name = "discodeit.storage.type", havingValue = "s3")
public S3Presigner s3Presigner(
@Value("${discodeit.storage.s3.access-key}") String accessKey,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Slf4j
@Configuration
public class StorageConfig {
@Bean
@ConditionalOnProperty(name = "discodeit.storage.type", havingValue = "S3")
public S3Client s3Client(
@Value("${discodeit.storage.s3.access-key}") String accessKey,
@Value("${discodeit.storage.s3.secret-key}") String secretKey,
@Value("${discodeit.storage.s3.region}") String region
) {
return S3Client.builder()
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
)).build();
}
@Bean
@ConditionalOnProperty(name = "discodeit.storage.type", havingValue = "s3")
public S3Presigner s3Presigner(
@Value("${discodeit.storage.s3.access-key}") String accessKey,
@Slf4j
@Configuration
@ConditionalOnProperty(name = "discodeit.storage.type", havingValue = "local", matchIfMissing = true)
public class StorageConfig {
@Bean
public S3Client s3Client(
@Value("${discodeit.storage.s3.access-key}") String accessKey,
@Value("${discodeit.storage.s3.secret-key}") String secretKey,
@Value("${discodeit.storage.s3.region}") String region
) {
return S3Client.builder()
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
)).build();
}
@Bean
public S3Presigner s3Presigner(
@Value("${discodeit.storage.s3.access-key}") String accessKey,

이건 어때요?

Comment on lines +3 to +11
type: ${STORAGE_TYPE:local}
local:
root-path: /path/to/storage
root-path: ${STORAGE_LOCAL_ROOT_PATH:.discodeit/storage}
s3:
access-key: ${AWS_S3_ACCESS_KEY}
secret-key: ${AWS_S3_SECRET_KEY}
region: ${AWS_S3_REGION}
bucket: ${AWS_S3_BUCKET}
presigned-url-expiration: ${AWS_S3_PRESIGNED_URL_EXPIRATION:600}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring boot에서는 환경변수를 properties로 바꿔주는 기능을 제공해요!
DISCODEIT_STORAGE_S3_ACCESSKEY -> discodeit.storage.s3.access-key

https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables

Comment on lines +8 to +14
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USER}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USER}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 20
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USER}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 20

들여쓰기가 빠져있네요!

@youngxpepp youngxpepp merged commit 65716b3 into codeit-bootcamp-spring:part3-김창우 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants