# KOREA-RESEARCH ``` ┬─┐┌─┐┌─┐┬ ┬┌─┐┬ ┌─┐ ├┬┘├┤ │ └┬┘│ │ ├┤ ┴└─└─┘└─┘ ┴ └─┘┴─┘└─┘ - framework for spring developers exploring JPA _____\ _______ / \ | /\ /_______/ |_____/ \ | \ / / / \ \ \/ / \ / \__/_ \/ ____ /\ / \ / \ /\ \ / / \ \/ / \___\__/ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. ``` ## Prerequisites * JDK 17+ * Maven * PostgreSQL ## Structure recycle 은 `core` 모듈을 기반으로 한 `admin`, `front`, `api` 어플리케이션으로 구성되어 있다. ```shell . |-- README.md |-- admin # 관리자 어플리케이션 | |-- pom.xml | |-- src | `-- target |-- api # API 모듈 (JWT 토큰 기반 인증) | |-- pom.xml | |-- src | `-- target |-- aws # AWS 서비스 전략(strategy) 모듈 | |-- pom.xml | |-- src | `-- target |-- core # 공통 모듈 | |-- pom.xml | |-- src | `-- target |-- front # 프론트 어플리케이션 | |-- pom.xml | |-- src | `-- target `-- pom.xml ``` ⚡ AWS S3 업로드를 이용하지 않는다면, pom.xml 에서 `aws`모듈 관련 내용을 삭제하면 된다. ⚡ `admin`, `front`, `api` 중 실제 프로젝트에서 사용할 모듈만 남기고 삭제해주세요. ✔️ Dockerfile 과 .gitlab-ci.yml 은 삭제해주세요 : ) recycle demo 용이기에 여려분의 프로젝트에서는 의미가 없습니다. recycle 의 demo 가 궁금하다면 아래 URL 에서 확인 해주세요. - `recycle-admin` - https://recycle-admin.etribe.co.kr 계정정보 (recycle-super/recycle1@#$) - `recycle-api` - https://recycle-api.etribe.co.kr/swagger-ui/index.html - `recycle-front` - https://recycle-front.etribe.co.kr/ 계정정보 (generalUser/generalUser1@#$) ## VM Options 프레임워크 실행 시 필요한 자바 VM 옵션은 아래와 같다. | VM 변수 | 설명 | 설정 값 | 필수여부 | |-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------|------| | -Dspring.profiles.active | Spring active 프로파일 | local, dev, prod | Y | | -Dapp.initData.core | 어플리케이션 초기 구동에 필요한 필수 데이터 생성여부 | true, false | N | | -Dpath.upload.public | 파일 업로드 경로 | 기본값 (~/upload/public) | N | | -Dpath.upload.tmpdir | 임시 파일 업로드 경로 | 기본값 (~/upload/tmpdir) | N | | -Dlogging.file.path | 로그 파일 생성 경로 | 기본값 (~/logs) | N | | -Dfile.encoding | JVM 속성 | `UTF-8` | Y | | -Djava.net.preferIPv4Stack | JVM 속성. 클라이언트 IP체크시 IPv4 형식을 사용하기 위함. | true | Y | | -Dcom.amazonaws.sdk.disableEc2Metadata | aws 모듈의 ec2 metadata 전송 끄기 | true | N | | **-Dserver.port** (2023-03-25 추가) | 서버 포트 (없다면 기본 8080) | 원하는 port | N | | **-Dserver.forward-headers-strategy** (2023-03-25 추가) | 프록시 서버(nginx, apache)에 정의된 `X-Forward-For`, `X-Forwarded-Proto` 설정값을 이용하려면 `native` 로 설정해주면 된다. (내장 컨테이너를 사용하는 경우에만 유효) | `native` | N | | **-Dspring.datasource.driver-class-name** (2023-03-25 추가) | JDBC Driver. 없다면 JDBC URL을 기준으로 JPA가 판단한다. | jdbc 드라이버 | Y | | **-Dspring.datasource.url** (2023-03-25 추가) | JDBC URL | jdbc url | N | | **-Dspring.datasource.username** (2023-03-25 추가) | DB Username | DB 사용자 | Y | | **-Dspring.datasource.password** (2023-03-25 추가) | DB Password | DB 패스워드 | Y | ### VM Options 예시 #### `admin`, `front`, `api` 모두 사용가능합니다. ``` -Dspring.profiles.active=local -Dapp.initData.core=false -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Dcom.amazonaws.sdk.disableEc2Metadata=true -Dserver.port=8080 -Dserver.forward-headers-strategy=native -Dlogging.level.org.springframework.security=DEBUG -Dspring.datasource.driver-class-name=org.postgresql.Driver -Dspring.datasource.url=jdbc:postgresql://15.165.180.203:5432/korea_research -Dspring.datasource.username=ko_research -Dspring.datasource.password=koresearch1@#4 ``` ## JDBC 및 데이터 핸들링 구성 옵션 ### app.initData.core ```shell -Dapp.initData.core=true # true | false ``` 어플리케이션 초기 구동에 필요한 필수 데이터 생성여부. 공통코드, 메뉴 정보 및 개발에 필요한 기반 데이터 등이 여기에 해당한다. InitAdminData, InitUriFrontData 등 *ApplicationRunner* 구현체에서 내용을 확인할 수 있다. ## LOG 생성 옵션 ### logging.file.path ```shell -Dlogging.file.path=~/logs # 기본값 ${user.home}/logs ``` 로그 파일 생성 경로를 지정한다. 지정된 경로에 아래와 같은 로그 파일이 생성된다. ```shell admin-app.log # 어드민 전체 로그 admin-app-ERROR.log # 어드민 로그 중 ERROR 부분 필터링 front-app.log # 프론트 전체 로그 front-app-ERROR.log # 프론트 로그 중 ERROR 부분 필터링 ``` ## File 구성 옵션 ### 파일 업로드 ```shell -Dpath.upload.public=~/upload/public # 파일 업로드 경로 -Dpath.upload.tmpdir=~/upload/tmpdir # tmp 디렉토리 경로 ``` 파일 업로드 경로가 지정되면 사용자가 업로드한 파일은 이 경로를 기준으로 `주제`/`년월일` 폴더 아래에 저장됩니다. tmpdir 은 서블릿 컨테이너가 multipart 파일 업로드 시 대용량 처리를 위해 임시파일을 저장하는 공간입니다. 파일 시스템 외에 AWS S3 로도 업로드해야 한다면, 아래 AWS CLI 를 이용하기 위한 정보를 제공해주어야 합니다. ```shell -Dapp.aws.s3.accessKey=AKIAZF27HETWNITZBZOF # AMI 에서 발급한 사용자 엑세스 키 -Dapp.aws.s3.secretKey=IhnTG0X7Wav8ak3cbYR1l8UAjL+gbnXdWJRM11cx # AMI 에서 발급한 사용자 시크릿 키 -Dapp.aws.s3.bucketName=etribe # S3 버킷 이름 -Dapp.aws.s3.bucketFolder=/recycle/upload # S3 버킷 디렉토리 -Dapp.aws.s3.domain=dixjkmptx5pkm.cloudfront.net # S3 혹은 cloudfront 도메인 ``` 🔑 위 accessKey 정보는 제가 만든 임시 정보이며, recycle 데모용으로만 사용되니 참고해주세요. 💡 recycle 은 파일 시스템 업로드와 S3 업로드를 사용 목적에 맞게 선택할 수 있는 유연성을 제공합니다. `FileUploadType`은 파일 업로드가 필요한 주제 도메인들이 정의된 enum 객체입니다. 여기 기술된 `FileStorageType` 속성에 따라 파일 업로드 경로가 결정됩니다. ### 파일 참조 업로드된 파일은 참조될 수 있어야 합니다. `fileUrlPortIn`는 파일이 파일 시스템에 있든 S3 에 있든 정확한 참조 URL 을 전달해주는 인터페이스입니다. ```java // 참조 URL 전달 - inline 방식 fileUrlPortIn.getInline( uploadFile.getType().getFileStorageType(), uploadFile.getPath(), uploadFile.getName()); // 참조 URL 전달 - attachment 방식 fileUrlPortIn.getAttachment( uploadFile.getType().getFileStorageType(), uploadFile.getId()); ``` `inline` 과 `attachment` 는 응답 헤더의 content-disposition 속성 값을 의미합니다. 업로드된 파일은 사용자에게 전달할 때 `inline` 과 `attachment` 두 방식 중 요건에 맞게 사용하면 됩니다. ## PACKAGING 배포방식 설정을 위해 두가지 maven 프로파일을 제공한다. * `jar` (default) * `war` Jeus, WebLogic, Tomcat 등 별도 외장 컨테이너 이용시 사용 maven 빌드 시 프로파일을 지정하지 않으면 기본 `jar` 프로파일로 동작하고, `war` 의 경우 명시적인 지정이 필요하다. 아래는 admin 빌드시 `war` 프로파일을 지정한 예시이다. ```shell $ mvn --projects admin --also-make clean package -DskipTests -P war # 빌드 후, admin/target 디렉토리에 war 가 생성된걸 확인할 수 있다. $ ll admin/target -rw-r--r-- 1 user 197121 94905770 4월 22 09:59 admin-0.0.1-SNAPSHOT.war ``` ## 개발 서버 환경 ### database - postgresql 14.17 ``` URL: jdbc:postgresql://15.165.180.203:5432/korea_research USERNAME: ko_research PASSWORD: koresearch1@#4 ``` ### 🚀 ADMIN DEPLOY #### `deploy_dev_admin` 브렌치로 merge! pipeline 실행 후 아래 URL 에서 확인가능. * https://ko-research-admin.etribe.co.kr ### 🚀 FRONT DEPLOY #### `deploy_dev_front` 브렌치로 merge! pipeline 실행 후 아래 URL 에서 확인가능. * https://ko-research-front.etribe.co.kr