Skip to content

Commit

Permalink
Merge pull request #3 from Kernel360/develop
Browse files Browse the repository at this point in the history
Update latest version
  • Loading branch information
stoneHee99 authored Jan 8, 2024
2 parents 1f5b5d4 + caf981a commit 210aecd
Show file tree
Hide file tree
Showing 67 changed files with 13,234 additions and 3,160 deletions.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/이길어때-이슈-템플릿⭐️.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: 이길어때 이슈 템플릿⭐️
about: 이길어때 개발 시 진행사항 공유를 위한 이슈 템플릿
title: ''
labels: ''
assignees: ''

---

### 📝Description

### ✅Task
- [ ] task1
- [ ] task2

### ✍️Additional
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Motivation 🧐

-

<br>

## Key Changes 🔑

<br>

## To Reviewers 🙏
61 changes: 61 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CD with Gradle
on:
push:
branches: [ "main" ]
permissions:
contents: read
defaults:
run:
working-directory: ./backend
jobs:
build:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
## application.yml 생성 후 secret 값 복붙
# Gradle Build를 위한 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Gradle Build (test 제외)
- name: Build with Gradle
run: ./gradlew clean build -x test
# DockerHub 로그인
- name: DockerHub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Docker 이미지 빌드
- name: Docker Image Build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} . --platform=linux/amd64
# DockerHub Push
- name: DockerHub Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}

# EC2 인스턴스 접속 및 애플리케이션 실행
- name: Application Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}

script: |
sudo docker kill ${{ secrets.PROJECT_NAME }}
sudo docker rm -f ${{ secrets.PROJECT_NAME }}
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker run -p ${{ secrets.PORT }}:${{ secrets.PORT }} -v postgre-volume:/data --name ${{ secrets.PROJECT_NAME }} -d ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
pull_request:
branches: [ "develop" ]

permissions:
contents: read

defaults:
run:
working-directory: ./backend

jobs:
build:
runs-on: ubuntu-latest

steps:
## jdk setting
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
## application.yml 생성 후 secret 값 복붙

- name: make properties files
shell: bash
env:
JASYPT_SECRET_KEY: ${{ secrets.JASYPT_SECRET_KEY }}
KAKAO_TOKEN_INFO_URL: ${{ secrets.KAKAO_TOKEN_INFO_URL }}
run: |
echo "Jasypt-Secret-Key=$JASYPT_SECRET_KEY" > ./src/main/resources/config.properties
echo "kakao.token.info.url=$KAKAO_TOKEN_INFO_URL" > ./src/main/resources/url.properties
cat ./src/main/resources/*
# Gradle Build를 위한 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# Gradle Build (test 제외)
- name: Build with Gradle
run: ./gradlew clean build

22 changes: 22 additions & 0 deletions .github/workflows/cr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .github/workflows/cr.yml 파일 생성

name: Code Review

permissions:
contents: read
pull-requests: write

on:
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: anc95/ChatGPT-CodeReview@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LANGUAGE: Korean
PROMPT: 당신은 10년차 시니어 개발자입니다. 우리가 작성한 코드에 문제가 없는지 리뷰해주세요. 대답은 한국어로 작성해주시고 보안 이슈, 버그, 변수명 체크는 꼭 해주세요. 단순한 부분이나 큰 이슈가 없는 부분은 리뷰해주지 않아도 되요. 대답 잘하면 200$ tip 줄게요.
31 changes: 31 additions & 0 deletions .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Frontend CI

on:
push:
pull_request:
branches: [ "develop" ]

defaults:
run:
working-directory: ./frontend

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
sparse-checkout:
frontend

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- run: npm ci
- name: Run test
run: npm run test

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# f1-Yigil
# f1-Yigil

## 이길
1 change: 0 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
implementation 'org.postgresql:postgresql'
implementation 'org.hibernate:hibernate-core:6.4.0.Final'
Expand Down
2 changes: 2 additions & 0 deletions backend/docker/postgreSQL/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM postgres:latest
RUN apt-get update && apt-get install -y postgis postgresql-16-postgis-3
10 changes: 10 additions & 0 deletions backend/docker/postgreSQL/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
postgres-master:
build: .
ports:
- "5432:5432"
postgres-slave:
build: .
ports:
- "5433:5432"
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ private FileType determineFileType(MultipartFile file) {

throw new FileException(INVALID_FILE_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.amazonaws.services.s3.model.ObjectMetadata;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
Expand All @@ -19,7 +21,7 @@ public class FileUploadEventListener {

@Async
@EventListener
public void handleFileUpload(FileUploadEvent event) throws IOException {
public Future<String> handleFileUpload(FileUploadEvent event) throws IOException {
MultipartFile file = event.getFile();
FileType fileType = event.getFileType();
String fileName = generateUniqueFileName(file.getOriginalFilename());
Expand All @@ -29,6 +31,7 @@ public void handleFileUpload(FileUploadEvent event) throws IOException {
metadata.setContentLength(file.getSize());
amazonS3Client.putObject(bucketName, s3Path, file.getInputStream(), metadata);
event.getCallback().accept(s3Path);
return CompletableFuture.completedFuture(s3Path);
}

private String getS3Path(FileType fileType, String fileName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kr.co.yigil.follow.domain.repository;



import java.util.Optional;
import kr.co.yigil.follow.domain.FollowCount;
import org.springframework.data.repository.CrudRepository;

public interface FollowCountRepository extends CrudRepository<FollowCount, Long> {

Optional<FollowCount> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {
" (SELECT COUNT(f1) FROM Follow f1 WHERE f1.following = :member), " +
" (SELECT COUNT(f2) FROM Follow f2 WHERE f2.follower = :member)) " +
"FROM Follow f WHERE f.follower = :member OR f.following = :member")

FollowCountDto getFollowCounts(@Param("member") Member member);

public void deleteByFollowerAndFollowing(Member Follower, Member Following);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Data
@NoArgsConstructor

public class FollowCountDto {
private int followerCount;
private int followingCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
@AllArgsConstructor
@NoArgsConstructor
public class FollowResponse {

private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.co.yigil.global.config.datasource;

public enum DataSourceType {
Master, Slave
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kr.co.yigil.global.config.datasource;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class MasterDataSourceConfig {

@Primary
@Bean(name = "masterDataSource")
@ConfigurationProperties(prefix = "spring.datasource.master.hikari")
public DataSource masterDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kr.co.yigil.global.config.datasource;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SlaveDataSourceConfig {

@Bean(name= "slaveDataSource")
@ConfigurationProperties(prefix = "spring.datasource.slave.hikari")
public DataSource slaveDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kr.co.yigil.global.config.replication;

import kr.co.yigil.global.config.datasource.DataSourceType;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class ReplicationRoutingDataSource extends AbstractRoutingDataSource {

@Override
protected Object determineCurrentLookupKey() {
return TransactionSynchronizationManager.isCurrentTransactionReadOnly() ?
DataSourceType.Slave : DataSourceType.Master;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package kr.co.yigil.global.config.replication;

import java.util.Map;
import javax.sql.DataSource;
import kr.co.yigil.global.config.datasource.DataSourceType;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;

@Configuration
public class RoutingDataSourceConfig {

@Bean(name= "routingDataSource")
public DataSource routingDataSource(@Qualifier("masterDataSource") DataSource masterDataSource,
@Qualifier("slaveDataSource") DataSource slaveDataSource) {
ReplicationRoutingDataSource routingDataSource = new ReplicationRoutingDataSource();

Map<Object, Object> dataSourceMap = Map.of(
DataSourceType.Master, masterDataSource,
DataSourceType.Slave, slaveDataSource
);

routingDataSource.setTargetDataSources(dataSourceMap);
routingDataSource.setDefaultTargetDataSource(masterDataSource);

return routingDataSource;
}

@Bean(name = "dataSource")
public DataSource dataSource(@Qualifier("routingDataSource") DataSource routingDataSource) {
return new LazyConnectionDataSourceProxy(routingDataSource);
}
}
Loading

0 comments on commit 210aecd

Please sign in to comment.