-
Notifications
You must be signed in to change notification settings - Fork 16
[이지현] - Sprint8 #120
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
base: 이지현
Are you sure you want to change the base?
[이지현] - Sprint8 #120
Conversation
prod: validate, dev: update
하드 코딩된 dev 프로필의 데이터소스 정보 수정 gitignore에 .env 추가
설정 프로필 prod로 변경 compose 설정 파일에 volume 추가 schema 파일 위치 루트 폴더로 변경
JpaClockConfig 클래스 추가 각 Instant 타임 정보를 사용하는 Request 클래스의 JsonFormat의 timezone을 Asia/Seoul로 변경 Dockerfile, docker-compose에 타임존 설정 추가 application 디폴트 설정 파일에 타임존 설정 추가 AWS S3 관련 의존성 추가
AWSS3Test 서비스 클래스 생성 (S3 테스트용) - 업로드, 다운로드, 프리사인드 URL 생성 기능 설정 파일(application.yaml)에 AWS S3 관련 환경변수 설정 값 추가 docker-compose 설정 파일에 AWS S3 환경 변수 추가 BasicBinaryContentService에 S3를 사용해 파일을 생성,저장하는 로직 추가 BinaryContentController에 AWS S3용 create, donwolad API 메서드 추가 AWS S3 의존성 추가, Spring Boot 버전 변경(3.4.0 -> 3.5.5)
S3BinaryContentStorage 구현, S3Config 로직 내장(S3Client, S3Presigner 생성 로직) S3Config, AWSS3Test 제거
AWSS3Test 클래스 재생성, 외부 연동 테스트 코드 추가
application-prod 설정 파일의 ddl-auto를 validate로 변경 shcema.sql 오타 수정
.env 환경 변수 파일과 값이 겹치는 것에 의한 배포 오류 해결을 위함
8081:8081 -> 80:8081로 변경
Windows 환경에서 CRLF 개행으로 인한 docker buildx 실패 오류 해결
.gitattributes로 CRLF를 기본 LF로 변경 Dockerfile의 dos2unix 설치, 줄바꿈 변환 파트 제거
환경변수가 인식되지 않는 오류 수정
.gitignore에 CI/CD 워크플로우 폴더(.github) 대상 제외
테스트 코드에 환경 변수 주입용도 코드 추가
빌드 단계에 env로 추가
AWS 자격 증명 설정 추가로 로직 변경
다시 env 주입 로직으로 변경하고 gradle에서 test 환경에서 주입받도록 하는 코드 추가
GitHub Actions - Secrets에서 주입받도록 변경 AwsProperties 클래스 삭제 (로컬 env 주입 로직 삭제) @value를 통해 CI로 주입받은 환경변수 값을 application.yml로부터 직접 주입 CI 주입 방식 변경, 빌드 전에 주입
설정 파일을 통한 주입에서 System.getenve()로 변경
AWS 환경변수 받아오는 로직 변경 (Props -> System.getenv())
on: | ||
pull_request: | ||
branches: | ||
- "main" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test 브랜치는 main말고 다른걸로 잡는게 좋을것 같아요!
import java.util.TimeZone; | ||
|
||
@Configuration | ||
public class JpaClockConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 이런 컨피그 만들어두는 것 매우 좋습니다.
} | ||
|
||
@GetMapping("{binaryContentId}/get") | ||
public ResponseEntity<?> get(@PathVariable("binaryContentId") UUID binaryContentId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드 명이나 api url 명이 get인게 어색합니다. 다운로드라는 의미가 드러나도록하는게 좋을것 같아요!
file.getBytes() | ||
); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 익셉션도 커스텀하게 처리하시면 좋을것 같습니다.
} | ||
|
||
@Override | ||
public BinaryContentDto find(UUID binaryContentId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public List<BinaryContentDto> findAllByIdIn(List<UUID> binaryContentIds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public ReadStatusDto find(UUID readStatusId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public List<ReadStatusDto> findAllByUserId(UUID userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public UserDto find(UUID userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public List<UserDto> findAll() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public UserStatusDto find(UUID userStatusId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
} | ||
|
||
@Override | ||
public List<UserStatusDto> findAll() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly=true)
추가하시면 좋을것 같아요
import java.util.UUID; | ||
|
||
@Component | ||
public class AWSS3Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스명을 Test로 끝나지 않게 만들어주시면 좋을것 같아요!
컨플리트가 나는 부분이 있습니다. 확인 부탁드립니다. |
기본 요구사항
애플리케이션 컨테이너화
Dockerfile 작성
/app
).dockerignore
를 활용해 제외하세요.80
포트를 노출하도록 설정하세요.이미지 빌드 및 실행 테스트
local
)를 지정하세요.prod
프로필로 실행하세요.http://localhost:8081
로 접속 가능하도록 포트를 매핑하세요.schema.sql
이 자동으로 실행되도록 구성하세요.depends_on
).BinaryContentStorage 고도화 (AWS S3)
AWS S3 버킷 구성
discodeit-binary-content-storage-(사용자 이니셜)
형식으로 지정하세요.AWS S3 접근을 위한 IAM 구성
discodeit
)를 생성하세요.AmazonS3FullAccess
권한을 할당하고, 사용자 생성을 완료하세요..env
파일에 추가합니다.AWS S3 테스트
com.sprint.mission.discodeit.stoarge.s3
env
에 정의한 AWS 정보를 로드하세요.PresignedUrl
생성**AWS S3를 활용한
BinaryContentStorage
고도화`S3BinaryContentStorage
를 구현하세요.discodeit.storage.type
값이s3
인 경우에만 Bean으로 등록되어야 합니다.S3BinaryContentStorageTest
를 함께 작성하면서 구현하세요.BinaryContentStorage
설정을 유연하게 제어할 수 있도록application.yaml
을 수정하세요..env
파일에 작성된 값을 임포트하는 방식으로 설정하세요.download
메소드는PresignedUrl
을 활용해 리다이렉트하는 방식으로 구현하세요.Docker Compose 구성
AWS를 활용한 배포(AWS RDS, ECR, ECS)
AWS RDS 구성
AWS RDS PostgreSQL 인스턴스를 생성하세요.
과금이 발생할 수 있으니 다음 항목은 한번 더 확인해주세요.
프리티어
아니오
보존기간: 7일
모두 체크 해제
비활성화
SSH 터널링을 통해 개발 환경에서 접근할 수 있도록 EC2를 구성하세요.
SSH/SSL > Use SSH tunnel
설정을 활성화하세요. 이때 이전에 다운로드한.pem
파일을 활용하세요.rds-ssh
인스턴스는 완전히 삭제하여 과금에 유의하세요.AWS ECR 구성
이미지를 배포할 퍼블릭 레포지토리(
discodeit
)를 생성하세요.AWS CLI를 설치하세요.
aws configure
실행 후 앞서 생성한discodeit
IAM 사용자 정보를 입력하세요.discodeit
IAM 사용자가 ECR에 접근할 수 있도록 다음 권한을 부여하세요.AmazonElasticContainerRegistryPublicFullAccess
Docker 클라이언트를 배포할 레지스트리에 대해 인증합니다.
멀티플랫폼을 지원하도록 애플리케이션 이미지를 빌드하고,
discodeit
레포지토리에 push 하세요.latest
,1.2-M8
linux/amd64
,linux/arm64
AWS 콘솔에서 푸시된 이미지를 확인하세요.
AWS ECS 구성
discodeit.env
파일을 만들어 다음의 내용을 작성하세요.discodeit
클러스터 상세 화면에서 서비스를 생성하세요.HTTP
를 선택하세요.Anywhere-IPv4
를 선택하여 모든 IP를 허용하세요.심화 요구사항
이미지 최적화하기
빌드
,런타임
) 빌드를 활용해 이미지의 크기를 줄여보세요.GitHub Actions를 활용한 CI/CD 파이프라인 구축
.github/workflows/test.yml
파일을 생성하세요.main
브랜치에 PR이 생성되면 실행되도록 설정하세요..github/workflows/deploy.yml
파일을 생성하세요.release
브랜치에 코드가 푸시되면 실행되도록 설정하세요.AWS_ACCESS_KEY
: IAM 사용자의 액세스 키AWS_SECRET_KEY
: IAM 사용자의 시크릿 키latest
와 GitHub 커밋 해시를 사용하도록 설정하세요주요 변경사항
스크린샷
멘토에게