Skip to content

Commit

Permalink
Merge pull request #63 from Mu-necting/feat/#61
Browse files Browse the repository at this point in the history
프로파일 분리 완료
  • Loading branch information
mingmingmon authored Nov 29, 2024
2 parents 5f374d1 + b2e769e commit 1db7877
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 118 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/develop-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ jobs:
distribution: 'temurin'

# 환경 변수 파일 생성
- name: Set environment values for main application
- name: Set environment values for common
run: |
cd ./src/main/resources
touch ./env.properties
echo "${{ secrets.ENV }}" > ./env.properties
touch ./env-common.properties
echo "${{ secrets.ENV_COMMON }}" > ./env-common.properties
shell: bash

- name: Set environment values for prod
run: |
cd ./src/main/resources
touch ./env-prod.properties
echo "${{ secrets.ENV_PROD }}" > ./env-prod.properties
shell: bash

- name: Set environment values for test
run: |
cd ./src/test/resources
touch ./env.properties
echo "${{ secrets.TEST_ENV }}" > ./env.properties
cd ./src/main/resources
touch ./env-test.properties
echo "${{ secrets.TEST_ENV }}" > ./env-test.properties
shell: bash

# Gradle에 권한 부여
Expand All @@ -49,7 +56,8 @@ jobs:
- name: Make zip file
run: |
mkdir develop-deploy
cp ./src/main/resources/env.properties ./develop-deploy/.env
cp ./src/main/resources/env-common.properties ./develop-deploy/.env.common
cp ./src/main/resources/env-prod.properties ./develop-deploy/.env.prod
cp ./docker-compose.blue.yml ./develop-deploy/
cp ./docker-compose.green.yml ./develop-deploy/
cp ./appspec.yml ./develop-deploy/
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ java {
}

configurations {
all {
exclude group: "commons-logging", module: "commons-logging"
exclude group: "org.slf4j", module: "slf4j-simple"
}
compileOnly {
extendsFrom annotationProcessor
}
Expand Down Expand Up @@ -53,6 +57,7 @@ dependencies {
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'it.ozimov:embedded-redis:0.7.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// Spotify
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.blue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ services:
ports:
- "8081:8080"
container_name: spring-blue
environment:
- SPRING_PROFILES_ACTIVE=prod
env_file:
- .env.common
- .env.prod
networks:
- munecting-network

Expand Down
5 changes: 5 additions & 0 deletions docker-compose.green.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ services:
ports:
- "8082:8080"
container_name: spring-green
environment:
- SPRING_PROFILES_ACTIVE=prod
env_file:
- .env.common
- .env.prod
networks:
- munecting-network

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/munecting/api/global/config/DevConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.munecting.api.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;

@Configuration
@Profile("dev")
@PropertySource(value = {"classpath:env-common.properties", "classpath:env-dev.properties"})
public class DevConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.munecting.api.global.config;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import redis.embedded.RedisServer;

@Configuration
@Profile("test")
public class EmbeddedRedisConfig {

@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

private RedisServer redisServer;

@PostConstruct
public void startEmbeddedRedis() {
redisServer = new RedisServer(port);
redisServer.start();
}

@PreDestroy
public void stopEmbeddedRedis() {
if (redisServer != null) {
redisServer.stop();
}
}

@Bean
public RedissonClient redissonClient() {
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + host + ":" + port);
return Redisson.create(config);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.munecting.api.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@PropertySources({
@PropertySource("classpath:env.properties")
})
public class PropertyConfig {
@Profile("prod")
@PropertySource(value = {"classpath:env-common.properties","classpath:env-prod.properties"})
public class ProdConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Profile({"prod","dev"})
public class RedisConfig {

@Value("${spring.data.redis.host}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile({"prod","dev"})
public class RedissonConfig {

@Value("${spring.data.redis.host}")
Expand All @@ -29,4 +31,5 @@ private Config createRedissonConfig() {
config.useSingleServer().setAddress(REDISSON_HOST_PREFIX + redisHost + ":" + redisPort);
return config;
}

}
12 changes: 12 additions & 0 deletions src/main/java/com/munecting/api/global/config/TestConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.munecting.api.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@Profile("test")
@PropertySource(value = {"classpath:env-common.properties", "classpath:env-test.properties"})
public class TestConfig {
}
110 changes: 87 additions & 23 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ server:
spring :
application:
name: munectingV4
profiles:
active: dev
mvc:
path match:
matching-strategy: ant_path_matcher
Expand All @@ -17,32 +19,16 @@ spring :
format_sql: true
jdbc:
timezone: Asia/Seoul

datasource:
url: jdbc:${DATASOURCE}://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver
hikari:
initialization-fail-timeout: 3600

data:
redis:
host: ${REDIS_HOST}
port: 6379
# password: 1234


security:
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:*}
allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,PATCH,DELETE}
allowed-headers: ${CORS_ALLOWED_HEADERS:*}
allowed-origins: "*"
allowed-methods: GET,POST,PUT,PATCH,DELETE
allowed-headers: "*"
path-pattern: "/**"

auth:
header: ${AUTH_HEADER:Authorization}
prefix: ${AUTH_PREFIX:Bearer }
header: Authorization
prefix: Bearer

oauth:
kakao:
Expand All @@ -62,14 +48,12 @@ spring :
maxRequestSize: 10MB # 한 번에 최대 업로드 가능 용량
resolve-lazily: true


cloud:
aws:
s3:
bucket: munecting
path:
profile-image: profileImage

region:
static: ap-northeast-2
stack:
Expand All @@ -91,3 +75,83 @@ jwt:

kakao-map:
api-key: ${KAKAO_MAP_API_KEY}

---
spring:
config:
activate:
on-profile: prod

datasource:
url: jdbc:${DATASOURCE}://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver
hikari:
initialization-fail-timeout: 3600
jpa:
hibernate:
ddl-auto: validate
data:
redis:
host: ${REDIS_HOST}
port: 6379

---
spring:
config:
activate:
on-profile: dev
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/munecting
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
hikari:
initialization-fail-timeout: 3600
jpa:
hibernate:
ddl-auto: update
data:
redis:
host: 127.0.0.1
port: 6379
cloud:
aws:
s3:
bucket: munecting-dev
path:
profile-image: profileImage
---
spring:
config:
activate:
on-profile: test
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:~/munecting
username: sa
password:
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
show_sql: true
format_sql: true
h2:
console:
enabled: true
path: /h2-console
data:
redis:
host: localhost
port: 6378
cloud:
aws:
s3:
bucket: munecting-test
path:
profile-image: profileImage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

package com.munecting.api;

import org.junit.jupiter.api.Test;
Expand All @@ -14,4 +14,4 @@ void contextLoads() {
}

}
*/

Loading

0 comments on commit 1db7877

Please sign in to comment.