Skip to content

Commit

Permalink
1st
Browse files Browse the repository at this point in the history
  • Loading branch information
sik2 committed Jan 13, 2025
1 parent 3b73734 commit 0a10b0a
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ out/

### VS Code ###
.vscode/

### extra ###
src/main/resources/application-secret.yml
src/main/generated
db.mv.db
db.trace.db
.idea
.terraform/**
*.tfstate
*.tfstate.backup
.terraform.lock.hcl
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 첫 번째 스테이지: 빌드 스테이지
FROM gradle:jdk21-graal-jammy as builder

# 작업 디렉토리 설정
WORKDIR /app

# 소스 코드와 Gradle 래퍼 복사
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .

# Gradle 래퍼에 실행 권한 부여
RUN chmod +x ./gradlew

# 종속성 설치
RUN ./gradlew dependencies --no-daemon

# 소스 코드 복사
COPY src src

# 애플리케이션 빌드
RUN ./gradlew build --no-daemon

# 두 번째 스테이지: 실행 스테이지
FROM ghcr.io/graalvm/jdk-community:21

# 작업 디렉토리 설정
WORKDIR /app

# 첫 번째 스테이지에서 빌드된 JAR 파일 복사
COPY --from=builder /app/build/libs/*.jar app.jar

# 실행할 JAR 파일 지정
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "app.jar"]
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.session:spring-session-data-redis'
testImplementation 'org.springframework.security:spring-security-test'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'
}

tasks.named('test') {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/ll/k8s/domain/home/home/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ll.k8s.domain.home.home;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HomeController {
@Value("${custom.jwt.secretKey}")
private String jwtSecretKey;
@GetMapping("/")
@ResponseBody
public String showMain() {
return "홈8";
}
@GetMapping("/jwtSecretKey")
@ResponseBody
public String showJwtSecretKey() {
return jwtSecretKey;
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/ll/k8s/global/app/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ll.k8s.global.app;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
@RequiredArgsConstructor
public class AppConfig {
private static String activeProfile;
@Value("${spring.profiles.active}")
public void setActiveProfile(String activeProfile) {
this.activeProfile = activeProfile;
}
public static boolean isProd() {
return activeProfile.equals("prod");
}
public static boolean isDev() {
return activeProfile.equals("dev");
}
public static boolean isTest() {
return activeProfile.equals("Test");
}
public static boolean isNotProd() {
return !isProd();
}
@Getter
private static String jwtSecretKey;
@Value("${custom.jwt.secretKey}")
public void setJwtSecretKey(String jwtSecretKey) {
this.jwtSecretKey = jwtSecretKey;
}
@Getter
public static String tempDirPath;
@Value("${custom.temp.dirPath}")
public void setTempDirPath(String tempDirPath) {
this.tempDirPath = tempDirPath;
}
@Getter
public static String genDirPath;
@Value("${custom.gen.dirPath}")
public void setGenDirPath(String genDirPath) {
this.genDirPath = genDirPath;
}
}

15 changes: 15 additions & 0 deletions src/main/java/com/ll/k8s/global/webMvcConfig/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ll.k8s.global.webMvcConfig;

import com.ll.k8s.global.app.AppConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/gen/**")
.addResourceLocations("file:///" + AppConfig.getGenDirPath() + "/");
}
}
39 changes: 39 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
server:
port: 8080
# 스프링부트가 종료 요청을 받았을 때 현재 본인이 하던 일(요청에 대한 응답, 배치작업 등)을 전부 마친 후 종료되도록
shutdown: graceful
spring:
autoconfigure:
exclude:
lifecycle:
# 스프링부트가 종료 요청을 받은 후 기다려줄 수 있는 최대한의 시간
timeout-per-shutdown-phase: 1h
data:
redis:
host: redis-1-service
port: 6379
datasource:
url: jdbc:mysql://mysql-1-service:3306/k8s_prod
username: llddlocal
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: false
highlight_sql: false
use_sql_comments: false
logging:
level:
com.ll.k8s: INFO
org.hibernate.SQL: INFO
org.hibernate.orm.jdbc.bind: INFO
org.hibernate.orm.jdbc.extract: INFO
org.springframework.transaction.interceptor: INFO
custom:
temp:
dirPath: /tmp
gen:
dirPath: /gen
3 changes: 3 additions & 0 deletions src/main/resources/application-secret.yml.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
custom:
jwt:
secretKey: NEED_TO_INPUT
9 changes: 9 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
datasource:
url: jdbc:h2:mem:test;MODE=MYSQL
username: sa
password:
driver-class-name: org.h2.Driver
custom:
gen:
dirPath: /usr/temp/gen
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
server:
port: 8090
spring:
profiles:
active: dev
include: secret
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
servlet:
multipart:
max-file-size: 50MB
max-request-size: ${spring.servlet.multipart.max-file-size}
threads:
virtual:
enabled: true
datasource:
url: jdbc:h2:./db;MODE=MYSQL
username: sa
password:
driver-class-name: org.h2.Driver
security:
user:
name: user1
password: 1234
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
default_batch_fetch_size: 100
format_sql: true
highlight_sql: true
use_sql_comments: true
logging:
level:
com.ll.k8s: DEBUG # ?? ??? ?? ??
org.hibernate.SQL: DEBUG
org.hibernate.orm.jdbc.bind: TRACE
org.hibernate.orm.jdbc.extract: TRACE
org.springframework.transaction.interceptor: TRACE
custom:
temp:
dirPath: usr/temp
gen:
dirPath: usr/temp/gen

0 comments on commit 0a10b0a

Please sign in to comment.