From 7738ec6d66d8c5f00721a5bbdcff28a6eaf11ebd Mon Sep 17 00:00:00 2001 From: enble Date: Thu, 28 Aug 2025 16:37:57 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20jpa=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 7474694..f56a645 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -4,20 +4,22 @@ spring: username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: com.mysql.cj.jdbc.Driver + sql: init: mode: never jpa: + hibernate: + ddl-auto: create-drop + show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.MySQL8Dialect - show-sql: true - format-sql: true - hbm2ddl: - auto: create + dialect: org.hibernate.dialect.MySQLDialect + format_sql: true logging: level: com.mey.backend: DEBUG org.springframework.web: DEBUG + org.hibernate.tool.schema.internal: TRACE From 432bccc8ed6cf075eab3972371d12a6c85086530 Mon Sep 17 00:00:00 2001 From: enble Date: Fri, 5 Sep 2025 23:56:16 +0900 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20s3=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../backend/global/config/AmazonConfig.java | 48 +++++++++++++++++++ src/main/resources/application-dev.yml | 12 +++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/java/com/mey/backend/global/config/AmazonConfig.java diff --git a/build.gradle b/build.gradle index 2499d8f..c248add 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,9 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'com.h2database:h2' + // s3 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + // swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9' } diff --git a/src/main/java/com/mey/backend/global/config/AmazonConfig.java b/src/main/java/com/mey/backend/global/config/AmazonConfig.java new file mode 100644 index 0000000..351557f --- /dev/null +++ b/src/main/java/com/mey/backend/global/config/AmazonConfig.java @@ -0,0 +1,48 @@ +package com.mey.backend.global.config; + +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import jakarta.annotation.PostConstruct; +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class AmazonConfig { + private AWSCredentials credentials; + + @Value("${cloud.aws.credentials.accessKey}") + private String accessKey; + + private String secretKey; + + private String region; + + private String bucket; + + @PostConstruct + public void init() { + this.credentials = new BasicAWSCredentials("accessKey", "secretKey"); + } + + @Bean + public AmazonS3 s3Client() { + BasicAWSCredentials awsCredentials = new BasicAWSCredentials("accessKey", "secretKey"); + return AmazonS3ClientBuilder.standard() + .withRegion("ap-northeast-2") + .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) + .build(); + } + + @Bean + public AWSCredentialsProvider awsCredentialsProvider() { + return new AWSStaticCredentialsProvider(this.credentials); + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f56a645..8f4519f 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -23,3 +23,15 @@ logging: com.mey.backend: DEBUG org.springframework.web: DEBUG org.hibernate.tool.schema.internal: TRACE + +cloud: + aws: + s3: + bucket: mey-s3 + region: + static: ap-northeast-2 + stack: + auto: false + credentials: + access-key: ${AWS_ACCESS_KEY} + secret-key: ${AWS_SECRET_KEY} From c3d9d2094a0b2055311f9c41e2f5a7b06f4769c3 Mon Sep 17 00:00:00 2001 From: Enble Date: Sat, 6 Sep 2025 22:55:01 +0900 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20s3=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mey/backend/global/config/AmazonConfig.java | 9 ++++++--- src/main/resources/application.yml | 13 ++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mey/backend/global/config/AmazonConfig.java b/src/main/java/com/mey/backend/global/config/AmazonConfig.java index 351557f..8537631 100644 --- a/src/main/java/com/mey/backend/global/config/AmazonConfig.java +++ b/src/main/java/com/mey/backend/global/config/AmazonConfig.java @@ -20,22 +20,25 @@ public class AmazonConfig { @Value("${cloud.aws.credentials.accessKey}") private String accessKey; + @Value("${cloud.aws.credentials.secretKey}") private String secretKey; + @Value("${cloud.aws.region.static}") private String region; + @Value("${cloud.aws.s3.bucket}") private String bucket; @PostConstruct public void init() { - this.credentials = new BasicAWSCredentials("accessKey", "secretKey"); + this.credentials = new BasicAWSCredentials(accessKey, secretKey); } @Bean public AmazonS3 s3Client() { - BasicAWSCredentials awsCredentials = new BasicAWSCredentials("accessKey", "secretKey"); + BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); return AmazonS3ClientBuilder.standard() - .withRegion("ap-northeast-2") + .withRegion(region) .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .build(); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f7f4118..a8c6082 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,6 @@ jwt: access-token-validity: 3600000 # 1시간 (밀리초) refresh-token-validity: 604800000 # 7일 (밀리초) - openai: api: key: ${OPENAI_API_KEY:dummy} @@ -29,3 +28,15 @@ tmap: app-key: ${TMAP_APP_KEY:dummy} lang: 0 # 0=Korean count: 1 + +cloud: + aws: + s3: + bucket: mey-cd-bucket + region: + static: ap-northeast-2 + stack: + auto: false + credentials: + access-key: ${S3_ACCESS_KEY} + secret-key: ${S3_SECRET_KEY} From 40d4f51307568fc5625ee247d1cf43e29c2b9006 Mon Sep 17 00:00:00 2001 From: Enble Date: Sat, 6 Sep 2025 22:58:25 +0900 Subject: [PATCH 4/6] =?UTF-8?q?chore:=20ci/cd=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 2 ++ .github/workflows/ci.yml | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 8001006..40b8c46 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -12,6 +12,8 @@ env: JWT_SECRET: ${{ secrets.JWT_SECRET }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} TMAP_APP_KEY: ${{ secrets.TMAP_APP_KEY }} + S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} + S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} jobs: build: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d41f9a..b4fb273 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,15 @@ jobs: name: CI runs-on: ubuntu-latest env: + S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} + DEPLOYMENT_APPLICATION_NAME: MEY-WAS + DEPLOYMENT_GROUP_NAME: MEY-CD + PROJECT_NAME: MEY + JWT_SECRET: ${{ secrets.JWT_SECRET }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - TMAP_APP_KEY: ${{ secrets.TMAP_APP_KEY }} + TMAP_APP_KEY: ${{ secrets.TMAP_APP_KEY }} + S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} + S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} steps: - uses: actions/checkout@v2 From fd302c5c2fd9a59d04198416878545be85fabd7f Mon Sep 17 00:00:00 2001 From: Enble Date: Sat, 6 Sep 2025 23:11:02 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20S3Manager=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/AmazonConfig.java | 10 ++++- .../mey/backend/global/util/S3Manager.java | 39 +++++++++++++++++++ src/main/resources/application.yml | 3 ++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/mey/backend/global/util/S3Manager.java diff --git a/src/main/java/com/mey/backend/global/config/AmazonConfig.java b/src/main/java/com/mey/backend/global/config/AmazonConfig.java index 8537631..58292d9 100644 --- a/src/main/java/com/mey/backend/global/config/AmazonConfig.java +++ b/src/main/java/com/mey/backend/global/config/AmazonConfig.java @@ -17,10 +17,10 @@ public class AmazonConfig { private AWSCredentials credentials; - @Value("${cloud.aws.credentials.accessKey}") + @Value("${cloud.aws.credentials.access-key}") private String accessKey; - @Value("${cloud.aws.credentials.secretKey}") + @Value("${cloud.aws.credentials.secret-key}") private String secretKey; @Value("${cloud.aws.region.static}") @@ -29,6 +29,12 @@ public class AmazonConfig { @Value("${cloud.aws.s3.bucket}") private String bucket; + @Value("${cloud.aws.s3.path.profile}") + private String profilePath; + + @Value("${cloud.aws.s3.path.place}") + private String placePath; + @PostConstruct public void init() { this.credentials = new BasicAWSCredentials(accessKey, secretKey); diff --git a/src/main/java/com/mey/backend/global/util/S3Manager.java b/src/main/java/com/mey/backend/global/util/S3Manager.java new file mode 100644 index 0000000..bed1432 --- /dev/null +++ b/src/main/java/com/mey/backend/global/util/S3Manager.java @@ -0,0 +1,39 @@ +package com.mey.backend.global.util; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.mey.backend.global.config.AmazonConfig; +import java.io.IOException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +@Slf4j +@Component +@RequiredArgsConstructor +public class S3Manager { + private final AmazonS3 amazonS3; + private final AmazonConfig amazonConfig; + + public String uploadFile(String keyName, MultipartFile file) { + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentLength(file.getSize()); + try { + amazonS3.putObject(new PutObjectRequest(amazonConfig.getBucket(), keyName, file.getInputStream(), metadata)); + } catch (IOException e){ + log.error("error at AmazonS3Manager uploadFile : {}", (Object) e.getStackTrace()); + } + + return amazonS3.getUrl(amazonConfig.getBucket(), keyName).toString(); + } + + public String generateProfileKeyName(String fileName) { + return amazonConfig.getProfilePath() + "/" + System.currentTimeMillis() + "_" + fileName; + } + + public String generatePlaceKeyName(String fileName) { + return amazonConfig.getPlacePath() + "/" + System.currentTimeMillis() + "_" + fileName; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a8c6082..5ca6317 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,6 +33,9 @@ cloud: aws: s3: bucket: mey-cd-bucket + path: + profile: profile + place: place region: static: ap-northeast-2 stack: From 63b97fd1e940c29686cee4c0b30dafe6ac03ec97 Mon Sep 17 00:00:00 2001 From: Enble Date: Sat, 6 Sep 2025 23:20:44 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20yml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 12 ------------ src/test/resources/application.yml | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index dc5d18d..41bfb7e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -25,15 +25,3 @@ logging: com.mey.backend: DEBUG org.springframework.web: DEBUG org.hibernate.tool.schema.internal: TRACE - -cloud: - aws: - s3: - bucket: mey-s3 - region: - static: ap-northeast-2 - stack: - auto: false - credentials: - access-key: ${AWS_ACCESS_KEY} - secret-key: ${AWS_SECRET_KEY} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 898cf0e..f73ce87 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -22,16 +22,29 @@ jwt: access-token-validity: 3600000 refresh-token-validity: 604800000 - - openai: api: - key: ${OPENAI_API_KEY} + key: ${OPENAI_API_KEY:testOpenAIApiKeyForDevelopmentAndTestingPurposesOnly} url: https://api.openai.com/v1/chat/completions tmap: transit: base-url: https://apis.openapi.sk.com/transit - app-key: ${TMAP_APP_KEY} + app-key: ${TMAP_APP_KEY:testTmapAppKeyForDevelopmentAndTestingPurposesOnly} lang: 0 # 0=Korean count: 1 + +cloud: + aws: + s3: + bucket: mey-cd-bucket + path: + profile: profile + place: place + region: + static: ap-northeast-2 + stack: + auto: false + credentials: + access-key: ${S3_ACCESS_KEY:testS3AccessKeyForDevelopmentAndTestingPurposesOnly} + secret-key: ${S3_SECRET_KEY:testS3SecretKeyForDevelopmentAndTestingPurposesOnly}