Skip to content

Commit

Permalink
release: 1.0.0 배포
Browse files Browse the repository at this point in the history
release: 1.0.0 배포
  • Loading branch information
kth990303 authored Jun 4, 2023
2 parents c306be0 + 60cdfb4 commit 55f0c41
Show file tree
Hide file tree
Showing 221 changed files with 10,516 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 개요
-

## 작업사항
-

## 주의사항
- PR 제목의 형식은 커밋 메시지의 제목 형식과 동일하다.
- 제목에는 이 PR이 무엇을 했는지 명시해주기
- ex) feat: 로그인 토큰 발행 기능 추가
54 changes: 54 additions & 0 deletions .github/workflows/cd-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Java CD with Gradle and Docker

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: make application-prod.yml
run: |
cd ./src/main/resources
touch ./application-prod.yml
echo "${{ secrets.PROD_YML }}" >> ./application-prod.yml
shell: bash

- name: Grant execute permisson for gradlew
run: chmod +x gradlew

- name: Build with Gradle (without Test)
run: ./gradlew clean build -x test --stacktrace

- name: Docker Hub build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
docker images
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
- name: Deploy to Prod WAS Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
key: ${{ secrets.WAS_KEY }}
port: ${{ secrets.WAS_SSH_PORT }}
script: |
cd /home/ubuntu/Mocacong-Backend/
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
sudo docker-compose up -d
sudo docker image prune -f
30 changes: 30 additions & 0 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Java CI with Gradle

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Grant execute permisson for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build
49 changes: 33 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'mocacong'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

jar {
enabled = false
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'com.amazonaws:aws-java-sdk-ses:1.12.429'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'com.slack.api:slack-api-client:1.29.0'
implementation platform("org.springframework.cloud:spring-cloud-dependencies:2021.0.5")
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'it.ozimov:embedded-redis:0.7.2'
}

tasks.named('test') {
useJUnitPlatform()
test {
useJUnitPlatform()
}
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
app:
container_name: app
user: "1000:1000"
image: mocacong/mocacong
expose:
- "8080"
ports: # host - container 포트 매핑
- "8080:8080"
volumes: # host 로그 디렉토리 - container 로그 디렉토리 볼륨 마운트
- ./logs:/logs
5 changes: 5 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM adoptopenjdk/openjdk11:jre-11.0.6_10-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENV SPRING_PROFILES_ACTIVE=prod
ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=prod", "/app.jar"]
7 changes: 3 additions & 4 deletions src/main/java/mocacong/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@SpringBootApplication
public class ServerApplication {

public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
9 changes: 9 additions & 0 deletions src/main/java/mocacong/server/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mocacong.server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

@Configuration
@EnableAsync
public class AsyncConfig {
}
33 changes: 33 additions & 0 deletions src/main/java/mocacong/server/config/AuthConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mocacong.server.config;

import java.util.List;
import lombok.RequiredArgsConstructor;
import mocacong.server.security.auth.AuthenticationPrincipalArgumentResolver;
import mocacong.server.security.auth.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class AuthConfig implements WebMvcConfigurer {

private final LoginInterceptor loginInterceptor;
private final AuthenticationPrincipalArgumentResolver authenticationPrincipalArgumentResolver;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor)
.addPathPatterns("/members/**", "/cafes/**")
.excludePathPatterns("/members", "/members/oauth", "/members/all",
"/members/check-duplicate/**", "/members/email-verification", "/members/info/reset-password")
.excludePathPatterns("/cafes");
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(authenticationPrincipalArgumentResolver);
WebMvcConfigurer.super.addArgumentResolvers(resolvers);
}
}
16 changes: 16 additions & 0 deletions src/main/java/mocacong/server/config/BaseTimeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mocacong.server.config;

import java.util.TimeZone;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class BaseTimeConfig {

@PostConstruct
public void setSeoulTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}
}
23 changes: 23 additions & 0 deletions src/main/java/mocacong/server/config/BatchConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mocacong.server.config;

import lombok.RequiredArgsConstructor;
import mocacong.server.service.CafeService;
import mocacong.server.service.MemberService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@EnableScheduling
@Configuration
@RequiredArgsConstructor
public class BatchConfig {

private final CafeService cafeService;
private final MemberService memberService;

@Scheduled(cron = "0 0 4 * * *", zone = "Asia/Seoul")
public void deleteNotUsedImages() {
memberService.deleteNotUsedProfileImages();
cafeService.deleteNotUsedCafeImages();
}
}
10 changes: 10 additions & 0 deletions src/main/java/mocacong/server/config/FeignClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package mocacong.server.config;

import mocacong.server.ServerApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableFeignClients(basePackageClasses = ServerApplication.class)
public class FeignClientConfig {
}
58 changes: 58 additions & 0 deletions src/main/java/mocacong/server/config/RedisCacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mocacong.server.config;

import java.time.Duration;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
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.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@EnableCaching
@Configuration
public class RedisCacheConfig {

@Bean
@Primary
public CacheManager cafeCacheManager(RedisConnectionFactory redisConnectionFactory) {
/*
* 카페 관련 캐시는 충분히 많이 쌓일 수 있으므로 OOM 방지 차 ttl 12시간으로 설정
*/
RedisCacheConfiguration redisCacheConfiguration = generateCacheConfiguration()
.entryTtl(Duration.ofHours(12L));

return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.build();
}

@Bean
public CacheManager oauthPublicKeyCacheManager(RedisConnectionFactory redisConnectionFactory) {
/*
* public key 갱신은 1년에 몇 번 안되므로 ttl 3일로 설정
* 유저가 하루 1번 로그인한다고 가정, 최소 1일은 넘기는 것이 좋다고 판단
*/
RedisCacheConfiguration redisCacheConfiguration = generateCacheConfiguration()
.entryTtl(Duration.ofDays(3L));
return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.build();
}

private RedisCacheConfiguration generateCacheConfiguration() {
return RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new GenericJackson2JsonRedisSerializer()));
}
}
38 changes: 38 additions & 0 deletions src/main/java/mocacong/server/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mocacong.server.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

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

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

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort));
}

@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());

/* Java 기본 직렬화가 아닌 JSON 직렬화 설정 */
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

return redisTemplate;
}
}
Loading

0 comments on commit 55f0c41

Please sign in to comment.