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
25 changes: 17 additions & 8 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: Clokey-Dev CD

on:
push:
branches: [ develop ]
pull_request:
branches: [ "main", "develop" ]
paths:
- "clokey-api/**"
- "clokey-domain/**"
- "clokey-common/**"
- "clokey-common-web/**"
- ".github/workflows/ci.yml"

jobs:
dev-cd:
Expand Down Expand Up @@ -63,7 +69,7 @@ jobs:
username: ubuntu
host: ${{ secrets.DEV_EC2_HOST }}
key: ${{ secrets.DEV_EC2_SSH_KEY }}
envs: DOCKERHUB_USERNAME,DEV_MYSQL_HOST,MYSQL_PORT,DB_NAME,DB_USERNAME,DB_PASSWORD,REDIS_HOST,REDIS_PORT,REDIS_PASSWORD,DEV_KAKAO_CLIENT_ID,DEV_KAKAO_CLIENT_SECRET,DEV_APPLE_CLIENT_ID,DEV_APPLE_CLIENT_SECRET,JWT_ACCESS_TOKEN_SECRET,JWT_REFRESH_TOKEN_SECRET,JWT_ACCESS_TOKEN_EXPIRATION_TIME,JWT_REFRESH_TOKEN_EXPIRATION_TIME,JWT_ISSUER,DEV_AWS_ACCESS_KEY_ID,DEV_AWS_SECRET_ACCESS_KEY,AWS_REGION,DEV_S3_BUCKET,DEV_S3_ENDPOINT,SWAGGER_USERNAME,SWAGGER_PASSWORD,FIREBASE_SA_JSON_B64,AI_SERVER_IP,CLOTH_INFERENCE_PATH,STYLE_INFERENCE_PATH,CLOTH_DETECT_PATH,MEILISEARCH_ENDPOINT,MEILISEARCH_KEY
envs: DOCKERHUB_USERNAME,DEV_MYSQL_HOST,MYSQL_PORT,DB_NAME,DB_USERNAME,DB_PASSWORD,REDIS_HOST,REDIS_PORT,REDIS_PASSWORD,DEV_KAKAO_CLIENT_ID,DEV_KAKAO_CLIENT_SECRET,DEV_APPLE_CLIENT_ID,DEV_APPLE_CLIENT_SECRET,JWT_ACCESS_TOKEN_SECRET,JWT_REFRESH_TOKEN_SECRET,JWT_ACCESS_TOKEN_EXPIRATION_TIME,JWT_REFRESH_TOKEN_EXPIRATION_TIME,JWT_ISSUER,OCI_TENANCY_ID,OCI_USER_ID,OCI_FINGERPRINT,OCI_PRIVATE_KEY,OCI_REGION,OCI_PASSPHRASE,OCI_OBJECTSTORAGE_NAMESPACE,OCI_OBJECTSTORAGE_BUCKET,SWAGGER_USERNAME,SWAGGER_PASSWORD,FIREBASE_SA_JSON_B64,AI_SERVER_IP,CLOTH_INFERENCE_PATH,STYLE_INFERENCE_PATH,CLOTH_DETECT_PATH,MEILISEARCH_ENDPOINT,MEILISEARCH_KEY
script: |
export DOCKERHUB_NAME=${{ secrets.DOCKERHUB_USERNAME }}
export DOCKER_TAG=dev-app
Expand All @@ -90,11 +96,14 @@ jobs:
export JWT_REFRESH_TOKEN_EXPIRATION_TIME=${{ secrets.JWT_REFRESH_TOKEN_EXPIRATION_TIME }}
export JWT_ISSUER=${{ secrets.JWT_ISSUER }}

export DEV_AWS_ACCESS_KEY_ID=${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
export DEV_AWS_SECRET_ACCESS_KEY=${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
export AWS_REGION=${{ secrets.AWS_REGION }}
export DEV_S3_BUCKET=${{ secrets.DEV_S3_BUCKET }}
export DEV_S3_ENDPOINT=${{ secrets.DEV_S3_ENDPOINT }}
export OCI_TENANCY_ID=${{ secrets.DEV_OCI_TENANCY_ID }}
export OCI_USER_ID=${{ secrets.DEV_CI_USER_ID }}
export OCI_FINGERPRINT=${{ secrets.DEV_OCI_FINGERPRINT }}
export OCI_PRIVATE_KEY=${{ secrets.DEV_OCI_PRIVATE_KEY }}
export OCI_REGION=${{ secrets.DEV_OCI_REGION }}
export OCI_PASSPHRASE=${{ secrets.DEV_OCI_PASSPHRASE }}
export OCI_OBJECTSTORAGE_NAMESPACE=${{ secrets.DEV_OCI_OBJECTSTORAGE_NAMESPACE }}
export OCI_OBJECTSTORAGE_BUCKET=${{ secrets.DEV_OCI_OBJECTSTORAGE_BUCKET }}

export SWAGGER_USERNAME=${{ secrets.SWAGGER_USERNAME }}
export SWAGGER_PASSWORD=${{ secrets.SWAGGER_PASSWORD }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.clokey.global.util.MemberUtil;
import org.clokey.member.entity.Member;
import org.clokey.properties.WebClientProperties;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.clokey.util.WebClientUtil;
import org.springframework.stereotype.Service;

Expand All @@ -47,7 +47,7 @@ public class ClothAiServiceImpl implements ClothAiService {

private final MemberUtil memberUtil;
private final CategoryRepository categoryRepository;
private final S3Util s3Util;
private final StorageUtil storageUtil;
private final WebClientUtil webClientUtil;
private final WebClientProperties webClientProperties;

Expand All @@ -61,7 +61,7 @@ public ClothImagesPresignedUrlResponse getClothUploadPresignedUrls(
request.payloads().stream()
.map(
req ->
s3Util.createPresignedUrl(
storageUtil.createPresignedUrl(
ImageType.CLOTH_IMAGE,
currentMember.getId(),
req.fileExtension(),
Expand Down Expand Up @@ -262,13 +262,13 @@ public ClothDetectResponse detectClothes(ClothDetectRequest request) {
}

private void validateImageUrls(List<String> imageUrls) {
if (!s3Util.doAllFilesExistByUrls(imageUrls)) {
if (!storageUtil.doAllFilesExistByUrls(imageUrls)) {
throw new BaseCustomException(ClothErrorCode.ClOTH_NOT_FOUND);
}
}

private void validateImageUrl(String imageUrl) {
if (!s3Util.doesFileExistByUrl(imageUrl)) {
if (!storageUtil.doesFileExistByUrl(imageUrl)) {
throw new BaseCustomException(HistoryErrorCode.HISTORY_IMAGE_NOT_FOUND);
}
}
Expand All @@ -295,7 +295,7 @@ private List<String> createPresignedUrls(Long memberId, int count) {
return java.util.stream.IntStream.range(0, count)
.mapToObj(
i ->
s3Util.createPresignedUrlWithoutMd5(
storageUtil.createPresignedUrlWithoutMd5(
ImageType.CLOTH_IMAGE, memberId, FileExtension.JPEG))
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.clokey.global.util.MemberUtil;
import org.clokey.member.entity.Member;
import org.clokey.response.SliceResponse;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
Expand All @@ -44,7 +44,7 @@ public class ClothServiceImpl implements ClothService {

private final ApplicationEventPublisher eventPublisher;
private final CoordinateClothRepository coordinateClothRepository;
private final S3Util s3Util;
private final StorageUtil storageUtil;

@Override
@Transactional
Expand Down Expand Up @@ -80,7 +80,7 @@ public ClothCreateResponse createClothes(ClothCreateRequests request) {
List<String> clothImageUrls =
request.content().stream().map(ClothCreateRequest::clothImageUrl).toList();
// 모든 선택된 url들을 확정하는 로직.
s3Util.updateTagsToCompleteByUrls(clothImageUrls);
storageUtil.updateTagsToCompleteByUrls(clothImageUrls);

return ClothCreateResponse.from(clothes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.clokey.member.entity.Member;
import org.clokey.member.enums.Visibility;
import org.clokey.report.enums.TargetType;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -65,7 +65,7 @@ public class HistoryServiceImpl implements HistoryService {
private final ReportRepository reportRepository;
private final MemberRepository memberRepository;
private final ApplicationEventPublisher eventPublisher;
private final S3Util s3Util;
private final StorageUtil storageUtil;

@Override
@Transactional
Expand Down Expand Up @@ -384,7 +384,7 @@ public HistoryImagesPresignedUrlResponse getHistoryUploadPresignedUrls(
request.payloads().stream()
.map(
payload ->
s3Util.createPresignedUrl(
storageUtil.createPresignedUrl(
ImageType.HISTORY_IMAGE,
currentMember.getId(),
payload.fileExtension(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.clokey.domain.image.event;

import lombok.RequiredArgsConstructor;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
Expand All @@ -11,17 +11,17 @@
@RequiredArgsConstructor
public class ImageEventListener {

private final S3Util s3Util;
private final StorageUtil storageUtil;

@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void handleImagesDeleteEvent(ImagesDeleteEvent event) {
s3Util.deleteAllByUrls(event.imageUrls());
storageUtil.deleteAllByUrls(event.imageUrls());
}

@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void handleImageDeleteEvent(ImageDeleteEvent event) {
s3Util.deleteByUrl(event.imageUrl());
storageUtil.deleteByUrl(event.imageUrl());
}
}
17 changes: 10 additions & 7 deletions clokey-api/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ jwt:
refresh-token-expiration-time: ${JWT_REFRESH_TOKEN_EXPIRATION_TIME}
issuer: ${JWT_ISSUER}

aws:
access-key-id: ${DEV_AWS_ACCESS_KEY_ID}
secret-access-key: ${DEV_AWS_SECRET_ACCESS_KEY}
region: ${AWS_REGION}
s3:
bucket: ${DEV_S3_BUCKET}
endpoint: ${DEV_S3_ENDPOINT:https://s3.ap-northeast-2.amazonaws.com}
oci:
tenancy-id: ${OCI_TENANCY_ID}
user-id: ${OCI_USER_ID}
fingerprint: ${OCI_FINGERPRINT}
private-key: ${OCI_PRIVATE_KEY}
region: ${OCI_REGION}
passphrase: ${OCI_PASSPHRASE:}
objectstorage:
namespace: ${OCI_OBJECTSTORAGE_NAMESPACE}
bucket: ${OCI_OBJECTSTORAGE_BUCKET}

external:
api:
Expand Down
17 changes: 10 additions & 7 deletions clokey-api/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ jwt:
refresh-token-expiration-time: ${JWT_REFRESH_TOKEN_EXPIRATION_TIME}
issuer: ${JWT_ISSUER}

aws:
access-key-id: ${AWS_ACCESS_KEY_ID}
secret-access-key: ${AWS_SECRET_ACCESS_KEY}
region: ${AWS_REGION}
s3:
bucket: ${S3_BUCKET}
endpoint: ${S3_ENDPOINT:https://s3.ap-northeast-2.amazonaws.com}
oci:
tenancy-id: ${OCI_TENANCY_ID}
user-id: ${OCI_USER_ID}
fingerprint: ${OCI_FINGERPRINT}
private-key: ${OCI_PRIVATE_KEY}
region: ${OCI_REGION}
passphrase: ${OCI_PASSPHRASE:}
objectstorage:
namespace: ${OCI_OBJECTSTORAGE_NAMESPACE}
bucket: ${OCI_OBJECTSTORAGE_BUCKET}

external:
api:
Expand Down
17 changes: 10 additions & 7 deletions clokey-api/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ jwt:
refresh-token-expiration-time: ${JWT_REFRESH_TOKEN_EXPIRATION_TIME}
issuer: ${JWT_ISSUER}

aws:
access-key-id: ${PROD_AWS_ACCESS_KEY_ID}
secret-access-key: ${PROD_AWS_SECRET_ACCESS_KEY}
region: ${AWS_REGION}
s3:
bucket: ${PROD_S3_BUCKET}
endpoint: ${PROD_S3_ENDPOINT:https://s3.ap-northeast-2.amazonaws.com}
oci:
tenancy-id: ${OCI_TENANCY_ID}
user-id: ${OCI_USER_ID}
fingerprint: ${OCI_FINGERPRINT}
private-key: ${OCI_PRIVATE_KEY}
region: ${OCI_REGION}
passphrase: ${OCI_PASSPHRASE:}
objectstorage:
namespace: ${OCI_OBJECTSTORAGE_NAMESPACE}
bucket: ${OCI_OBJECTSTORAGE_BUCKET}

firebase:
credentials-path: ${FIREBASE_CREDENTIALS_PATH}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.clokey.member.entity.OauthInfo;
import org.clokey.member.enums.OauthProvider;
import org.clokey.response.SliceResponse;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -80,7 +80,7 @@ class ClothServiceTest extends IntegrationTest {
@Autowired private SituationRepository situationRepository;

@MockitoBean private MemberUtil memberUtil;
@MockitoBean private S3Util s3Util;
@MockitoBean private StorageUtil storageUtil;
@Autowired private ApplicationEvents applicationEvents;

@Nested
Expand Down Expand Up @@ -109,10 +109,10 @@ void setUp() {
FileExtension.JPEG, "testMd5Hash1"),
new ClothImagesUploadRequest.Payload(
FileExtension.JPEG, "testMd5Hash2")));
given(s3Util.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash1")))
given(storageUtil.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash1")))
.willReturn("testUrl1");

given(s3Util.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash2")))
given(storageUtil.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash2")))
.willReturn("testUrl2");

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.clokey.member.entity.Member;
import org.clokey.member.entity.OauthInfo;
import org.clokey.member.enums.OauthProvider;
import org.clokey.util.S3Util;
import org.clokey.util.StorageUtil;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
Expand Down Expand Up @@ -77,7 +77,7 @@ class HistoryServiceImplTest extends IntegrationTest {
@Autowired private BlockRepository blockRepository;

@MockitoBean private MemberUtil memberUtil;
@MockitoBean private S3Util s3Util;
@MockitoBean private StorageUtil storageUtil;
@Autowired private ApplicationEvents applicationEvents;

@Nested
Expand Down Expand Up @@ -105,9 +105,9 @@ void setUp() {
new HistoryImagesUploadRequest.Payload(
FileExtension.PNG, "testMd5Hash2")));

given(s3Util.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash1")))
given(storageUtil.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash1")))
.willReturn("testUrl1");
given(s3Util.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash2")))
given(storageUtil.createPresignedUrl(any(), anyLong(), any(), eq("testMd5Hash2")))
.willReturn("testUrl2");

// when
Expand Down
2 changes: 1 addition & 1 deletion clokey-infrastructure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4'
implementation 'com.oracle.oci.sdk:oci-java-sdk-objectstorage:3.47.0'
api 'com.google.firebase:firebase-admin:9.7.0'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'io.vanslog:spring-data-meilisearch:0.7.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package org.clokey.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.oracle.bmc.auth.SimpleAuthenticationDetailsProvider;
import com.oracle.bmc.objectstorage.ObjectStorageClient;
import java.io.ByteArrayInputStream;
import lombok.RequiredArgsConstructor;
import org.clokey.properties.AwsProperties;
import org.clokey.properties.S3Properties;
import org.clokey.properties.OciProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class S3Config {

private final AwsProperties awsProperties;
private final S3Properties s3Properties;
private final OciProperties ociProperties;

@Bean
public AmazonS3 s3Client() {
BasicAWSCredentials credentials =
new BasicAWSCredentials(
awsProperties.accessKeyId(), awsProperties.secretAccessKey());
AwsClientBuilder.EndpointConfiguration endpointConfiguration =
new AwsClientBuilder.EndpointConfiguration(
s3Properties.endpoint(), awsProperties.region());
public ObjectStorageClient objectStorageClient() {
String privateKey = ociProperties.privateKey();
String passphrase = ociProperties.passphrase();

return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
SimpleAuthenticationDetailsProvider provider =
SimpleAuthenticationDetailsProvider.builder()
.tenantId(ociProperties.tenancyId())
.userId(ociProperties.userId())
.fingerprint(ociProperties.fingerprint())
.privateKeySupplier(() -> new ByteArrayInputStream(privateKey.getBytes()))
.passPhrase(passphrase != null && !passphrase.isEmpty() ? passphrase : null)
.region(com.oracle.bmc.Region.fromRegionId(ociProperties.region()))
.build();

return new ObjectStorageClient(provider);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.clokey.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("oci")
public record OciProperties(
String tenancyId,
String userId,
String fingerprint,
String privateKey,
String region,
String passphrase) {}
Loading
Loading