Skip to content

Commit

Permalink
Merge pull request #227 from Team-Capple/release-v0.1.0
Browse files Browse the repository at this point in the history
[RELEASE] μΌ€ν”Œ 버전 2 배포
  • Loading branch information
jaewonLeeKOR authored Oct 6, 2024
2 parents 32403f8 + 5a294a6 commit 732d9c6
Show file tree
Hide file tree
Showing 151 changed files with 5,530 additions and 545 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/cicd-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags:
- 'v**'
- '!v**-**'

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -36,13 +37,16 @@ jobs:
run: |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Get Version
run: echo "VERSION=$(git tag --points-at)" >> ${GITHUB_ENV}

- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-prod:${{ github.sha }}" >> ${GITHUB_ENV}
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-prod:${{ env.VERSION }}" >> ${GITHUB_ENV}
- name: Write Version
run: |
echo "server-version: Prod" >> config/application.yml
echo -e "\nserver-version: ${{ env.VERSION }}" >> config/application-prod.yml
- name: Build Image
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f Dockerfile-deploy .
Expand Down Expand Up @@ -78,4 +82,4 @@ jobs:
sudo docker container rm spring
sudo docker image rm ${{ env.SPRING_IMAGE }}
sudo docker-compose --env-file=config/env/prod.env -f docker-compose.prod.yml -p backend up -d
sudo docker image prune -af
sudo docker image prune -af
53 changes: 4 additions & 49 deletions .github/workflows/cicd-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Release Deploy

on:
push:
branches:
- 'release-**'
tags:
- 'v**-**'

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -38,15 +38,15 @@ jobs:
- name: Get Version
run: |
echo "VERSION=$( echo ${{ github.ref_name }} | cut -c 9- )" >> ${GITHUB_ENV}
echo "VERSION=$( git tag --points-at )" >> ${GITHUB_ENV}
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-release:${{ env.VERSION }}" >> ${GITHUB_ENV}
- name: Write Version
run: |
echo "server-version: ${{ env.VERSION }}" >> config/application.yml
echo -e "\nserver-version: ${{ env.VERSION }}" >> config/application-release.yml
- name: Build Image
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f Dockerfile-deploy .
Expand Down Expand Up @@ -83,48 +83,3 @@ jobs:
sudo docker image rm ${{ env.SPRING_IMAGE }}
sudo docker-compose --env-file=config/env/release.env -f docker-compose.release.yml -p backend up -d
sudo docker image prune -af
releaseExport:
name: Export Release Jar
runs-on: ubuntu-latest
needs: releaseDeploy
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.GITHUB_ACTOR }}
password: ${{ secrets.TOKEN_GITHUB }}

- name: lowercase the image tag & repository
run: |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Get Version
run: |
echo "VERSION=$( echo ${{ github.ref_name }} | cut -c 9- )" >> ${GITHUB_ENV}
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-release:${{ env.VERSION }}" >> ${GITHUB_ENV}
- name: Run Container
run: docker run -d --name container-capple ${{ env.SPRING_IMAGE }}

- name: Extract .jar File From Container
run: docker cp container-capple:/app/app.jar .

- name: Stop Container
run: docker rm -f container-capple

- name: Rename Jar
run: mv app.jar capple-${{ env.VERSION }}.jar

- name: Extract .jar File
uses: actions/upload-artifact@v4
with:
name: capple-${{ env.VERSION }}
path: ./*.jar
compression-level: 9
retention-days: 1
overwrite: true
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ dependencies {
// thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'

// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation 'com.google.code.findbugs:jsr305:3.0.2'
// webflux
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64'
// actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
// open csv
implementation 'com.opencsv:opencsv:5.5.1'
}

dependencyManagement {
Expand Down
2 changes: 1 addition & 1 deletion config
2 changes: 2 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ services:
image: ${SPRING_IMAGE}
ports:
- ${SPRING_OUTER_PORT}:${SPRING_INNER_PORT}
volumes:
- ${LOCAL_SPRING_LOG_PATH}:/app/logs
environment:
- SPRING_PROFILES_ACTIVE=prod
2 changes: 2 additions & 0 deletions docker-compose.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ services:
image: ${SPRING_IMAGE}
ports:
- ${SPRING_OUTER_PORT}:${SPRING_INNER_PORT}
volumes:
- ${LOCAL_SPRING_LOG_PATH}:/app/logs
environment:
- SPRING_PROFILES_ACTIVE=release
4 changes: 4 additions & 0 deletions src/main/java/com/server/capple/CappleApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.time.ZoneId;
Expand All @@ -16,6 +18,8 @@
@EnableFeignClients
@EnableConfigurationProperties
@EnableScheduling
@EnableCaching
@EnableAsync
public class CappleApplication {

public static void main(String[] args) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/server/capple/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.server.capple.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;

@Configuration
public class RedisConfig {

Expand All @@ -25,6 +32,7 @@ public RedisConnectionFactory redisConnectionFactory() {
connectionFactory.setDatabase(database);
return connectionFactory;
}

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
Expand All @@ -35,4 +43,31 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisC

return redisTemplate;
}

@Bean
@Primary
public CacheManager noExpireCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(redisConnectionFactory).cacheDefaults(redisCacheConfiguration).build();
}

@Bean
public CacheManager oneDayExpireCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
.entryTtl(Duration.ofDays(1));
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(redisConnectionFactory).cacheDefaults(redisCacheConfiguration).build();
}

@Bean
public CacheManager apnsJwtCacheManager(RedisConnectionFactory redisCloudConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
.entryTtl(Duration.ofMinutes(30));
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(redisCloudConnectionFactory).cacheDefaults(redisCacheConfiguration).build();
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/server/capple/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public OpenAPI openAPI() {
Info info = new Info()
.title("Capple API Document")
.version(version)
.description("Capple API λͺ…μ„Έμ„œμž…λ‹ˆλ‹€.");
.description(
version.charAt(0) == 'v' ?
String.format("Capple API λͺ…μ„Έμ„œμž…λ‹ˆλ‹€.<br>[%s 변경사항](https://github.com/Team-Capple/Capple-Server/releases/tag/%s)",version, version)
: "Capple API λͺ…μ„Έμ„œμž…λ‹ˆλ‹€."
);
return new OpenAPI()
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme))
.security(Arrays.asList(securityRequirement))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.server.capple.config.apns.config;

import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.timeout.WriteTimeoutHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;

import javax.net.ssl.SSLException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

@Configuration
public class ApnsClientConfig {
@Bean("apnsSslContext")
public SslContext getApnsSslContext() throws SSLException {
return SslContextBuilder.forClient().protocols("TLSv1.2").build(); // SSL μ„€μ •
}

@Bean("apnsConnectionProvider")
public ConnectionProvider getApnsConnectionProvider() {
return ConnectionProvider.builder("apns")
.maxConnections(10) // μ΅œλŒ€ μ»€λ‚΅μ…˜ 수
.pendingAcquireMaxCount(-1) // μž¬μ‹œλ„ 횟수 (-1 : λ¬΄ν•œλŒ€)
.pendingAcquireTimeout(java.time.Duration.ofSeconds(10)) // 컀λ„₯μ…˜ 풀에 μ‚¬μš© κ°€λŠ₯ν•œ 컀λ„₯μ…˜ 없을 λ•Œμ˜ λŒ€κΈ° μ‹œκ°„
.maxIdleTime(java.time.Duration.ofSeconds(5)) // μ΅œλŒ€ 유휴 μ‹œκ°„
.maxLifeTime(java.time.Duration.ofSeconds(300)) // μ΅œλŒ€ 생λͺ… μ‹œκ°„
.lifo() // ν›„μž…μ„ μΆœ
.build();
}

@Bean("apnsH2HttpClient")
public HttpClient getApnsH2HttpClient(ConnectionProvider apnsConnectionProvider, SslContext apnsSslContext) {
return HttpClient.create(apnsConnectionProvider) // reactor HttpClient 생성
.keepAlive(true) // keep-alive ν™œμ„±ν™”
.protocol(HttpProtocol.H2) // HTTP/2 ν™œμ„±ν™”
.doOnConnected(connection -> connection.addHandlerLast(new WriteTimeoutHandler(10, TimeUnit.SECONDS))) // μ“°κΈ° νƒ€μž„ 아웃
.responseTimeout(Duration.ofSeconds(10)) // 응닡 νƒ€μž„ 아웃
.secure(sslSpec -> sslSpec.sslContext(apnsSslContext)); // SSL ν™œμ„±ν™”
}
}
Loading

0 comments on commit 732d9c6

Please sign in to comment.