Skip to content
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

fix: 설정 파일 분리 #334

Merged
merged 7 commits into from
Sep 9, 2024
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ jobs:
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_DEV }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi

# 배포 스크립트 실행
sudo ./deploy.sh
6 changes: 6 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ jobs:
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi

# 배포 스크립트 실행
sudo ./deploy.sh
6 changes: 5 additions & 1 deletion script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source .env

REGISTRY_URL=${REGISTRY_URL}
IMAGE_NAME=${IMAGE_NAME}
SECRET_MANAGER_TOKEN=${SECRET_MANAGER_TOKEN}
SECRET_MANAGER_WORKSPACE_ID=${SECRET_MANAGER_WORKSPACE_ID}
TAG="latest"
CONTAINER_NAME="smeem"
HEALTH_CHECK_URI="/actuator/health"
Expand All @@ -17,7 +19,9 @@ if [ "$(sudo docker ps -a -q -f name=${CONTAINER_NAME})" ]; then
fi

echo "> Run docker"
sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG}
sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG} \
-e SECRET_MANAGER_TOKEN="${SECRET_MANAGER_TOKEN}" \
-e SECRET_MANAGER_WORKSPACE_ID="${SECRET_MANAGER_WORKSPACE_ID}"

echo "----------------------------------------------------------------------"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.smeem.application.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SmeemProperties.class)
public class SmeemConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.smeem.application.config;

import jakarta.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Getter
@ConfigurationProperties(prefix = "smeem")
public class SmeemProperties {
private final Secret secret;
private final Duration duration;
private final Client client;

public SmeemProperties(Secret secret, Duration duration, Client client) {
this.secret = secret;
this.duration = duration;
this.client = client;
}

@Getter
public static class Secret {
private String key;

public Secret(String key) {
this.key = key;
}

@PostConstruct
private void init() {
this.key = Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8));
}
}

public record Duration(
int remind,
int expired
) {
}

public record Client(
Version version
) {

public record Version(
String title,
String content,
APP ios,
APP android
) {

public record APP(
String app,
String force
) {
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.smeem.application.domain.auth;

import com.smeem.common.util.SmeemProperty;
import com.smeem.application.config.SmeemProperties;
import io.jsonwebtoken.security.Keys;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;

import static java.util.Base64.getEncoder;
import java.util.Base64;

@Component
@RequiredArgsConstructor
public class SecretKeyFactory {
private final SmeemProperty smeemProperty;
private final SmeemProperties smeemProperties;

public SecretKey create() {
val encodedKey = getEncoder().encodeToString(smeemProperty.getSMEEM_SECRET_KEY().getBytes());
val encodedKey = Base64.getEncoder().encodeToString(smeemProperties.getSecret().getKey().getBytes());
return Keys.hmacShaKeyFor(encodedKey.getBytes());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smeem.application.domain.diary;

import com.smeem.application.config.SmeemProperties;
import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.badge.BadgeType;
import com.smeem.application.domain.member.Member;
Expand Down Expand Up @@ -27,6 +28,7 @@ public class DiaryService implements DiaryUseCase {
private final BadgePort badgePort;
private final MemberBadgePort memberBadgePort;
private final TopicPort topicPort;
private final SmeemProperties smeemProperties;

@Transactional
public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) {
Expand Down Expand Up @@ -73,9 +75,10 @@ public void deleteDiary(long diary) {
}

public RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate) {
val remindDuration = smeemProperties.getDuration().remind();
return RetrieveDiariesResponse.of(
diaryPort.findByMemberAndTerm(memberId, startDate, endDate),
diaryPort.isExistByMemberAndPastAgo(memberId, 30));
diaryPort.isExistByMemberAndPastAgo(memberId, remindDuration));
}

@Transactional
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smeem.application.domain.version;

import com.smeem.application.config.SmeemProperties;
import com.smeem.application.port.input.VersionUseCase;
import com.smeem.application.port.input.dto.response.version.RetrieveAppVersionResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -10,16 +11,16 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class VersionService implements VersionUseCase {
private final Property property;
private final SmeemProperties smeemProperties;

@Override
public RetrieveAppVersionResponse retrieveAppVersion() {
return RetrieveAppVersionResponse.of(
property.getCLIENT_VERSION_UPDATE_TITLE(),
property.getCLIENT_VERSION_UPDATE_CONTENT(),
property.getCLIENT_VERSION_ANDROID_VERSION(),
property.getCLIENT_VERSION_ANDROID_FORCE_VERSION(),
property.getCLIENT_VERSION_IOS_VERSION(),
property.getCLIENT_VERSION_IOS_FORCE_VERSION());
smeemProperties.getClient().version().title(),
smeemProperties.getClient().version().content(),
smeemProperties.getClient().version().android().app(),
smeemProperties.getClient().version().android().force(),
smeemProperties.getClient().version().ios().app(),
smeemProperties.getClient().version().ios().force());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.smeem.batch.scheduler;

import com.smeem.application.config.SmeemProperties;
import com.smeem.application.port.input.DiaryUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import lombok.val;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class DiaryScheduler {
private final DiaryUseCase diaryUseCase;

@Value("${smeem.duration.expired}")
private int DURATION_EXPIRED;
private final SmeemProperties smeemProperties;

@Scheduled(cron = "0 0 0 * * *")
public void deleteExpiredDiaries() {
diaryUseCase.deleteExpiredDiaries(DURATION_EXPIRED);
val expiredDuration = smeemProperties.getDuration().expired();
diaryUseCase.deleteExpiredDiaries(expiredDuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class NotificationScheduler {
private final MemberPort memberPort;
private final NotificationPort notificationPort;

@Scheduled(cron = "${smeem.notification.cron_expression}")
@Scheduled(cron = "0 0/30 * * * *")
public void pushAlarmByTrainingTime() throws InterruptedException {
Thread.sleep(1000);
val members = memberPort.findByTrainingTime(LocalDateTime.now());
Expand Down
Loading
Loading