diff --git a/.gitignore b/.gitignore index e21dba8..9da7b18 100644 --- a/.gitignore +++ b/.gitignore @@ -246,11 +246,15 @@ out/ !**/src/main/**/out/ !**/src/test/**/out/ +# End of https://www.toptal.com/developers/gitignore/api/macos,intellij,java,intellij+all **/src/main/resources/application-rds-local.yml **/src/main/resources/application-rds-prod.yml -# End of https://www.toptal.com/developers/gitignore/api/macos,intellij,java,intellij+all + **/src/main/resources/application-redis-local.yml **/src/main/resources/application-redis-prod.yml +**/src/main/resources/application-s3-local.yml +**/src/main/resources/application-s3-prod.yml + # 깃허브 서브모듈 관련 폴더 ignore backend-submodule/ \ No newline at end of file diff --git a/api/api-health-check/build.gradle b/api/api-health-check/build.gradle index e5b3daf..a30dcd5 100644 --- a/api/api-health-check/build.gradle +++ b/api/api-health-check/build.gradle @@ -4,5 +4,6 @@ jar {enabled = true} dependencies { implementation project(':domain:domain-rds') implementation project(':infra:infra-redis') - implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation project(':infra:infra-s3') + implementation project(':monitoring') } diff --git a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/TestSuccessStatus.java b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/TestSuccessStatus.java new file mode 100644 index 0000000..f56abc4 --- /dev/null +++ b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/TestSuccessStatus.java @@ -0,0 +1,20 @@ +package com.drinkhere.apihealthcheck; + +import com.drinkhere.common.response.BaseSuccessStatus; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum TestSuccessStatus implements BaseSuccessStatus { + GET_PRESIGNED_SUCCESS(HttpStatus.OK, "GET 위한 Presigned URL 조회 성공"); + + private final HttpStatus httpStatus; + private final String message; + + @Override + public int getStatusCode() { + return this.httpStatus.value(); + } +} diff --git a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/request/GetPresignedUrlRequest.java b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/request/GetPresignedUrlRequest.java new file mode 100644 index 0000000..bfb1baa --- /dev/null +++ b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/request/GetPresignedUrlRequest.java @@ -0,0 +1,6 @@ +package com.drinkhere.apihealthcheck.dto.request; + +public record GetPresignedUrlRequest( + String fileName +) { +} diff --git a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlCollectionResponse.java b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlCollectionResponse.java new file mode 100644 index 0000000..3647bee --- /dev/null +++ b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlCollectionResponse.java @@ -0,0 +1,14 @@ +package com.drinkhere.apihealthcheck.dto.response; + +import com.drinkhere.infras3.aop.Interface.TransformToPresignedUrl; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@AllArgsConstructor +@Getter +@TransformToPresignedUrl +public class GetPresignedUrlCollectionResponse { + private List filePaths; +} \ No newline at end of file diff --git a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlResponse.java b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlResponse.java new file mode 100644 index 0000000..026386a --- /dev/null +++ b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/dto/response/GetPresignedUrlResponse.java @@ -0,0 +1,14 @@ +package com.drinkhere.apihealthcheck.dto.response; + +import com.drinkhere.infras3.aop.Interface.TransformToPresignedUrl; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@AllArgsConstructor +@Getter +@TransformToPresignedUrl +public class GetPresignedUrlResponse { + private String filePath; +} \ No newline at end of file diff --git a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/presentations/HealthCheckController.java b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/presentations/HealthCheckController.java index e20ac90..9d15003 100644 --- a/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/presentations/HealthCheckController.java +++ b/api/api-health-check/src/main/java/com/drinkhere/apihealthcheck/presentations/HealthCheckController.java @@ -1,10 +1,17 @@ package com.drinkhere.apihealthcheck.presentations; +import com.drinkhere.apihealthcheck.TestSuccessStatus; +import com.drinkhere.apihealthcheck.dto.request.GetPresignedUrlRequest; +import com.drinkhere.apihealthcheck.dto.response.GetPresignedUrlCollectionResponse; +import com.drinkhere.apihealthcheck.dto.response.GetPresignedUrlResponse; +import com.drinkhere.common.response.ApiResponse; import com.drinkhere.infraredis.util.RedisUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.drinkhere.infras3.application.PresignedUrlService; +import lombok.*; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; @RestController @RequestMapping("/api/v1/health-check") @@ -12,6 +19,8 @@ public class HealthCheckController { private final RedisUtil redisUtil; + private final PresignedUrlService presignedUrlService; + @GetMapping public String healthCheck() { return "This Turn is Green!"; @@ -30,4 +39,38 @@ public String redisConnectionCheck() { return "No value found for key 'id1'"; } } + + @PostMapping("/presigned") + public ResponseEntity> getPresignedUrl( + @RequestBody GetPresignedUrlRequest getPresignedUrlRequest + ) { + System.out.println("getPresignedUrl.filePath() = " + getPresignedUrlRequest.fileName()); + + String presignedUrlForGet = presignedUrlService.getPresignedUrlForGet( getPresignedUrlRequest.fileName()); + + System.out.println("presignedUrlForGet = " + presignedUrlForGet); + + com.drinkhere.apihealthcheck.dto.response.GetPresignedUrlResponse getPresignedUrlResponse = new com.drinkhere.apihealthcheck.dto.response.GetPresignedUrlResponse(getPresignedUrlRequest.fileName()); + + return ApiResponse.success(TestSuccessStatus.GET_PRESIGNED_SUCCESS, getPresignedUrlResponse); + } + + @PostMapping("/presigned/collection") + public ResponseEntity> getPresignedUrlCollection( + @RequestBody GetPresignedUrlRequest getPresignedUrlRequest + ) { + System.out.println("getPresignedUrl.filePath() = " + getPresignedUrlRequest.fileName()); + + String presignedUrlForGet = presignedUrlService.getPresignedUrlForGet(getPresignedUrlRequest.fileName()); + + System.out.println("presignedUrlForGet = " + presignedUrlForGet); + ArrayList list = new ArrayList<>(); + GetPresignedUrlCollectionResponse getPresignedUrlResponse = new GetPresignedUrlCollectionResponse(list); + getPresignedUrlResponse.getFilePaths().add(getPresignedUrlRequest.fileName()); + getPresignedUrlResponse.getFilePaths().add(getPresignedUrlRequest.fileName()); + // 리스트를 포함한 ApiResponse 반환 + return ApiResponse.success(TestSuccessStatus.GET_PRESIGNED_SUCCESS, getPresignedUrlResponse); + } + + } diff --git a/api/api-health-check/src/main/resources/application-hc-local.yml b/api/api-health-check/src/main/resources/application-hc-local.yml index bd2a371..c4b126b 100644 --- a/api/api-health-check/src/main/resources/application-hc-local.yml +++ b/api/api-health-check/src/main/resources/application-hc-local.yml @@ -3,10 +3,16 @@ spring: name: api-health-check management: - endpoint: - health: - show-details: always endpoints: web: exposure: - include: "*" \ No newline at end of file + include: health,metrics,prometheus + metrics: + export: + cors: + allowed-origins: "*" + allowed-methods: GET + prometheus: + metrics: + export: + enabled: true \ No newline at end of file diff --git a/backend-submodule b/backend-submodule index 576c4b0..22542c3 160000 --- a/backend-submodule +++ b/backend-submodule @@ -1 +1 @@ -Subproject commit 576c4b0b823b23fb034d5fdfbcaead97bd6a0d33 +Subproject commit 22542c3a451b8a4e5e61d519b1bf0b0ffed83240 diff --git a/build.gradle b/build.gradle index 36bcc61..33c6c64 100644 --- a/build.gradle +++ b/build.gradle @@ -73,4 +73,10 @@ task copyPrivate(type: Copy) { include "application-redis-prod.yml" into 'infra/infra-redis/src/main/resources' } + + copy { + from './backend-submodule' + include "application-s3-prod.yml" + into 'infra/infra-s3/src/main/resources' + } } \ No newline at end of file diff --git a/common/src/main/java/com/drinkhere/common/utils/HttpResponseUtil.java b/common/src/main/java/com/drinkhere/common/utils/HttpResponseUtil.java index 94f662f..06a3a09 100644 --- a/common/src/main/java/com/drinkhere/common/utils/HttpResponseUtil.java +++ b/common/src/main/java/com/drinkhere/common/utils/HttpResponseUtil.java @@ -14,7 +14,6 @@ import java.io.IOException; @Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class HttpResponseUtil { diff --git a/execute/src/main/resources/application.yml b/execute/src/main/resources/application.yml index cd84e56..c4d6115 100644 --- a/execute/src/main/resources/application.yml +++ b/execute/src/main/resources/application.yml @@ -17,6 +17,7 @@ spring: import: - application-rds-local.yml - application-redis-local.yml + - application-s3-local.yml - application-hc-local.yml logging: @@ -34,6 +35,7 @@ spring: import: - application-rds-prod.yml - application-redis-prod.yml + - application-s3-prod.yml - application-hc-prod.yml logging: diff --git a/infra/infra-s3/.gitattributes b/infra/infra-s3/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/infra/infra-s3/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/infra/infra-s3/.gitignore b/infra/infra-s3/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/infra/infra-s3/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/infra/infra-s3/build.gradle b/infra/infra-s3/build.gradle new file mode 100644 index 0000000..5b8fabe --- /dev/null +++ b/infra/infra-s3/build.gradle @@ -0,0 +1,11 @@ +bootJar { enabled = false } +jar { enabled = true } + +dependencies { + implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' + implementation 'io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.4.4' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-aop' +} + +tasks.register("prepareKotlinBuildScriptModel"){} \ No newline at end of file diff --git a/infra/infra-s3/gradle/wrapper/gradle-wrapper.jar b/infra/infra-s3/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/infra/infra-s3/gradle/wrapper/gradle-wrapper.jar differ diff --git a/infra/infra-s3/gradle/wrapper/gradle-wrapper.properties b/infra/infra-s3/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e2847c8 --- /dev/null +++ b/infra/infra-s3/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/infra/infra-s3/gradlew b/infra/infra-s3/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/infra/infra-s3/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/infra/infra-s3/gradlew.bat b/infra/infra-s3/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/infra/infra-s3/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/infra/infra-s3/settings.gradle b/infra/infra-s3/settings.gradle new file mode 100644 index 0000000..f149fb4 --- /dev/null +++ b/infra/infra-s3/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'infra-s3' diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/InfraS3Application.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/InfraS3Application.java new file mode 100644 index 0000000..1d3c3eb --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/InfraS3Application.java @@ -0,0 +1,15 @@ +package com.drinkhere.infras3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = "com.drinkhere") +public class InfraS3Application { + + public static void main(String[] args) { + SpringApplication.run(InfraS3Application.class, args); + } + +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/Interface/TransformToPresignedUrl.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/Interface/TransformToPresignedUrl.java new file mode 100644 index 0000000..3d08bdb --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/Interface/TransformToPresignedUrl.java @@ -0,0 +1,15 @@ +package com.drinkhere.infras3.aop.Interface; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 해당 어노테이션을 DTO에 추가하면 + * filePath 필드를 Presigned URL로 변경 + */ +@Target({ElementType.TYPE, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TransformToPresignedUrl { +} \ No newline at end of file diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlAspect.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlAspect.java new file mode 100644 index 0000000..07c84a3 --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlAspect.java @@ -0,0 +1,118 @@ +package com.drinkhere.infras3.aop; + +import com.drinkhere.common.response.ApiResponse; +import com.drinkhere.infras3.aop.Interface.TransformToPresignedUrl; +import com.drinkhere.infras3.application.PresignedUrlService; +import lombok.RequiredArgsConstructor; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.List; +import java.util.Map; +@Aspect +@Component +@RequiredArgsConstructor +public class PresignedUrlAspect { + + private final PresignedUrlService presignedUrlService; + + + /** + * RestController이면서 GetMapping일때 처리를 수행 + */ + @Around("execution(public * com.drinkhere..*.*(..)) " + + "&& @target(org.springframework.web.bind.annotation.RestController)" + + "&& @annotation(org.springframework.web.bind.annotation.GetMapping)") + public Object handlePresignedUrl(ProceedingJoinPoint joinPoint) throws Throwable { + Object result = joinPoint.proceed(); + + // ResponseEntity 객체가 반환되면 + if (result instanceof ResponseEntity responseEntity) { + Object body = responseEntity.getBody(); + if (body instanceof ApiResponse apiResponse) { + Object data = apiResponse.getData(); + // 데이터가 존재하면 Presigned URL 처리 + if (data != null) { + processIfPresignedUrlApplicable(data); + } + } + } + + return result; + } + + /** + * Presigned URL을 생성하여 데이터 처리 + */ + private void processIfPresignedUrlApplicable(Object data) { + // 단일 객체일 경우 처리 + if (data.getClass().isAnnotationPresent(TransformToPresignedUrl.class)) { + processPresignedUrl(data); + } + // 컬렉션 객체 처리 + else if (data instanceof Collection collection) { + collection.stream() + .filter(item -> item.getClass().isAnnotationPresent(TransformToPresignedUrl.class)) + .forEach(this::processPresignedUrl); + } + // 맵 객체 처리 + else if (data instanceof Map map) { + map.values().stream() + .filter(value -> value.getClass().isAnnotationPresent(TransformToPresignedUrl.class)) + .forEach(this::processPresignedUrl); + } + } + + /** + * Presigned URL을 생성하고 해당 값을 업데이트 + */ + private void processPresignedUrl(Object data) { + for (Field field : data.getClass().getDeclaredFields()) { + // filePath 필드만 찾아서 처리 + if (field.getType().equals(String.class) && (field.getName().contains("filePath") || field.getName().contains("Paths"))) { + field.setAccessible(true); + try { + // 단일 filePath 값 처리 + String filePath = (String) field.get(data); + if (filePath != null) { + // Presigned URL 생성 + String presignedUrl = presignedUrlService.getPresignedUrlForGet(filePath); + // 필드 값 업데이트 + field.set(data, presignedUrl); + } + } catch (IllegalAccessException e) { + // 필드 접근 시 예외 처리 + throw new IllegalStateException("Failed to update field value", e); + } + } + // filePath가 List인 경우 처리 + else if (field.getType().equals(List.class) && field.getName().contains("filePath")) { + field.setAccessible(true); + try { + // List 타입의 filePath를 처리 + List filePaths = (List) field.get(data); + if (filePaths != null) { + // 각 fileName에 대해 Presigned URL 처리 + for (int i = 0; i < filePaths.size(); i++) { + String filePath = filePaths.get(i); + if (filePath != null) { + // Presigned URL 생성 + String presignedUrl = presignedUrlService.getPresignedUrlForGet(filePath); + // Presigned URL로 업데이트 + filePaths.set(i, presignedUrl); + } + } + } + } catch (IllegalAccessException e) { + // 필드 접근 시 예외 처리 + throw new IllegalStateException("Failed to update field value", e); + } + } + } + } +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlPointCutProperties.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlPointCutProperties.java new file mode 100644 index 0000000..6f6fb1d --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/aop/PresignedUrlPointCutProperties.java @@ -0,0 +1,16 @@ +package com.drinkhere.infras3.aop; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Getter +@Setter +@Component +@ConfigurationProperties(prefix = "presigned-url") +public class PresignedUrlPointCutProperties { + private List pointcuts; +} \ No newline at end of file diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/application/PresignedUrlService.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/application/PresignedUrlService.java new file mode 100644 index 0000000..7302be8 --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/application/PresignedUrlService.java @@ -0,0 +1,78 @@ +package com.drinkhere.infras3.application; + +import com.amazonaws.HttpMethod; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; +import com.drinkhere.infras3.config.S3Config; +import com.drinkhere.infras3.dto.request.GetPresignedUrlRequest; +import com.drinkhere.infras3.dto.response.GetPresignedUrlResponse; +import lombok.RequiredArgsConstructor; +import org.hibernate.validator.internal.util.stereotypes.Lazy; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class PresignedUrlService { + + @Value("${cloud.s3.bucket}") private String bucket; + @Value("${cloud.s3.expTime}") private Long expTime; + private final S3Config s3Config; + + + /** + * PUT용 presigned url 발급 -> 이미지 업로드 + */ + + public GetPresignedUrlResponse getPresignedUrlForPut(GetPresignedUrlRequest getPresignedUrlRequest) { + String filePath = createPath(getPresignedUrlRequest.prefix(), getPresignedUrlRequest.fileName()); + GeneratePresignedUrlRequest generatePresignedUrlRequest = getGeneratePresignedUrlRequest(bucket, filePath, HttpMethod.PUT); + URL url = s3Config.amazonS3().generatePresignedUrl(generatePresignedUrlRequest); + return GetPresignedUrlResponse.of(url.toString(), filePath); + } + + /** + * GET용 presigned url 발급 -> 이미지 조회 + */ + public String getPresignedUrlForGet(String filePath) { + if (filePath != null) { + GeneratePresignedUrlRequest generatePresignedUrlRequest = getGeneratePresignedUrlRequest(bucket, filePath, HttpMethod.GET); + URL url = s3Config.amazonS3().generatePresignedUrl(generatePresignedUrlRequest); + return url.toString(); + } + return filePath; + } + + /** + * Amazon S3 SDK에서 Presigned URL을 생성하기 위한 요청 객체를 생성 + */ + private GeneratePresignedUrlRequest getGeneratePresignedUrlRequest(String bucket, String fileName, HttpMethod method) { + GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, fileName) + .withMethod(method) + .withExpiration(getPresignedUrlExpiration()); + + return generatePresignedUrlRequest; + } + + // + private Date getPresignedUrlExpiration() { + Date expiration = new Date(); + long expTimeMillis = expiration.getTime(); + expTimeMillis += expTime; + expiration.setTime(expTimeMillis); + + return expiration; + } + + // 파일 경로 생성 -> {prefix}/{yyyyMMddHHmmss}-{UUID}-{파일명}.png + private String createPath(String prefix, String fileName) { + String fileUniqueId = UUID.randomUUID().toString(); + String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + return String.format("%s/%s-%s-%s", prefix, timestamp, fileUniqueId, fileName); + } +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/config/S3Config.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/config/S3Config.java new file mode 100644 index 0000000..78fba43 --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/config/S3Config.java @@ -0,0 +1,35 @@ +package com.drinkhere.infras3.config; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class S3Config { + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + @Value("${cloud.aws.region}") + private String region; + + @Bean + @Primary + public BasicAWSCredentials awsCredentialsProvider() { + BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey); + return basicAWSCredentials; + } + + @Bean + public AmazonS3 amazonS3() { + return AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCredentialsProvider())) + .build(); + } +} \ No newline at end of file diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/request/GetPresignedUrlRequest.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/request/GetPresignedUrlRequest.java new file mode 100644 index 0000000..3c27476 --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/request/GetPresignedUrlRequest.java @@ -0,0 +1,9 @@ +package com.drinkhere.infras3.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record GetPresignedUrlRequest( + @NotNull(message = "prefix는 null일 수 없습니다.") String prefix, + @NotNull(message = "fileName는 null일 수 없습니다.") String fileName +) { +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/response/GetPresignedUrlResponse.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/response/GetPresignedUrlResponse.java new file mode 100644 index 0000000..715e360 --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/dto/response/GetPresignedUrlResponse.java @@ -0,0 +1,10 @@ +package com.drinkhere.infras3.dto.response; + +public record GetPresignedUrlResponse( + String url, + String filePath +) { + public static GetPresignedUrlResponse of(String url, String filePath) { + return new GetPresignedUrlResponse(url,filePath); + } +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/presentation/PresignedUrlController.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/presentation/PresignedUrlController.java new file mode 100644 index 0000000..2a38bcb --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/presentation/PresignedUrlController.java @@ -0,0 +1,29 @@ +package com.drinkhere.infras3.presentation; + +import com.drinkhere.common.response.ApiResponse; +import com.drinkhere.infras3.application.PresignedUrlService; +import com.drinkhere.infras3.dto.request.GetPresignedUrlRequest; +import com.drinkhere.infras3.dto.response.GetPresignedUrlResponse; +import com.drinkhere.infras3.response.PresignedUrlSuccessStatus; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static com.drinkhere.infras3.response.PresignedUrlSuccessStatus.CREATE_PRESIGNED_SUCCESS; + +@RestController +@RequestMapping("/api/v1/presigned-url") +@RequiredArgsConstructor +public class PresignedUrlController { + private final PresignedUrlService presignedUrlService; + @PostMapping + public ResponseEntity> getPresignedUrl(GetPresignedUrlRequest getPresignedUrlRequest) { + return ApiResponse.success( + CREATE_PRESIGNED_SUCCESS, + presignedUrlService.getPresignedUrlForPut(getPresignedUrlRequest) + ); + } +} diff --git a/infra/infra-s3/src/main/java/com/drinkhere/infras3/response/PresignedUrlSuccessStatus.java b/infra/infra-s3/src/main/java/com/drinkhere/infras3/response/PresignedUrlSuccessStatus.java new file mode 100644 index 0000000..c08e57b --- /dev/null +++ b/infra/infra-s3/src/main/java/com/drinkhere/infras3/response/PresignedUrlSuccessStatus.java @@ -0,0 +1,20 @@ +package com.drinkhere.infras3.response; + +import com.drinkhere.common.response.BaseSuccessStatus; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum PresignedUrlSuccessStatus implements BaseSuccessStatus { + CREATE_PRESIGNED_SUCCESS(HttpStatus.CREATED, "PUT 위한 Presigned URL 생성 성공"); + + private final HttpStatus httpStatus; + private final String message; + + @Override + public int getStatusCode() { + return this.httpStatus.value(); + } +} diff --git a/infra/infra-s3/src/test/java/com/drinkhere/infras3/InfraS3ApplicationTests.java b/infra/infra-s3/src/test/java/com/drinkhere/infras3/InfraS3ApplicationTests.java new file mode 100644 index 0000000..dcb36e7 --- /dev/null +++ b/infra/infra-s3/src/test/java/com/drinkhere/infras3/InfraS3ApplicationTests.java @@ -0,0 +1,13 @@ +package com.drinkhere.infras3; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class InfraS3ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/monitoring/.gitattributes b/monitoring/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/monitoring/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/monitoring/.gitignore b/monitoring/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/monitoring/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/monitoring/build.gradle b/monitoring/build.gradle new file mode 100644 index 0000000..cae0e39 --- /dev/null +++ b/monitoring/build.gradle @@ -0,0 +1,7 @@ +bootJar {enabled = false} +jar {enabled = true} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-actuator' + runtimeOnly 'io.micrometer:micrometer-registry-prometheus' +} diff --git a/monitoring/gradle/wrapper/gradle-wrapper.jar b/monitoring/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/monitoring/gradle/wrapper/gradle-wrapper.jar differ diff --git a/monitoring/gradle/wrapper/gradle-wrapper.properties b/monitoring/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e2847c8 --- /dev/null +++ b/monitoring/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/monitoring/gradlew b/monitoring/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/monitoring/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/monitoring/gradlew.bat b/monitoring/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/monitoring/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/monitoring/settings.gradle b/monitoring/settings.gradle new file mode 100644 index 0000000..97e89a5 --- /dev/null +++ b/monitoring/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'monitoring' diff --git a/monitoring/src/main/java/com/drinkhere/monitoring/MonitoringApplication.java b/monitoring/src/main/java/com/drinkhere/monitoring/MonitoringApplication.java new file mode 100644 index 0000000..5669306 --- /dev/null +++ b/monitoring/src/main/java/com/drinkhere/monitoring/MonitoringApplication.java @@ -0,0 +1,15 @@ +package com.drinkhere.monitoring; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = "com.drinkhere") +public class MonitoringApplication { + + public static void main(String[] args) { + SpringApplication.run(MonitoringApplication.class, args); + } + +} diff --git a/monitoring/src/main/resources/application-monitoring-local.yml b/monitoring/src/main/resources/application-monitoring-local.yml new file mode 100644 index 0000000..a0a52e4 --- /dev/null +++ b/monitoring/src/main/resources/application-monitoring-local.yml @@ -0,0 +1,18 @@ +spring: + application: + name: monitoring + +management: + endpoints: + web: + exposure: + include: health, metrics, prometheus + metrics: + export: + cors: + allowed-origins: "*" + allowed-methods: GET + prometheus: + metrics: + export: + enabled: true \ No newline at end of file diff --git a/monitoring/src/main/resources/application-monitoring-prod.yml b/monitoring/src/main/resources/application-monitoring-prod.yml new file mode 100644 index 0000000..f6a0430 --- /dev/null +++ b/monitoring/src/main/resources/application-monitoring-prod.yml @@ -0,0 +1,18 @@ +spring: + application: + name: monitoring + +management: + endpoints: + web: + exposure: + include: health,metrics,prometheus + metrics: + export: + cors: + allowed-origins: "*" + allowed-methods: GET + prometheus: + metrics: + export: + enabled: true \ No newline at end of file diff --git a/monitoring/src/test/java/com/drinkhere/monitoring/MonitoringApplicationTests.java b/monitoring/src/test/java/com/drinkhere/monitoring/MonitoringApplicationTests.java new file mode 100644 index 0000000..9180a0e --- /dev/null +++ b/monitoring/src/test/java/com/drinkhere/monitoring/MonitoringApplicationTests.java @@ -0,0 +1,13 @@ +package com.drinkhere.monitoring; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class MonitoringApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 5ab3740..87cf299 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,11 +3,15 @@ rootProject.name = 'server' // 공통 모듈 include 'common' +// 모니터링 모듈 +include 'monitoring' + // Domain 모듈 include 'domain:domain-rds' // Infra 모듈 include 'infra:infra-redis' +include 'infra:infra-s3' // API 모듈 include 'api:api-health-check'