Skip to content

Commit

Permalink
Merge pull request #63 from locavell/feat/#62
Browse files Browse the repository at this point in the history
Feat/#62
  • Loading branch information
J-neat authored Aug 16, 2024
2 parents 3ef615a + ddbe5f0 commit fd51636
Show file tree
Hide file tree
Showing 112 changed files with 5,602 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
66 changes: 66 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Deploy To EC2

on:
pull_request:
branches:
- dev

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Github Repository 파일 불러오기
uses: actions/checkout@v4

- name: JDK 17버전 설치
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: yml 파일 생성
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml
echo "${{ secrets.APPLICATION_JWT }}" > ./src/main/resources/application-jwt.yml
echo "${{ secrets.APPLICATION_OAUTH }}" > ./src/main/resources/application-oauth.yml
- name: gradlew 파일 실행 권한 부여
run: chmod +x ./gradlew

- name: 테스트 및 빌드
run: ./gradlew clean build

- name: AWS Resource에 접근할 수 있게 AWS credentials 설정
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: ECR에 로그인
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Docker 이미지 생성
run: docker build -t locavel-server .

- name: Docker 이미지에 Tag 붙이기
run: docker tag locavel-server ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest

- name: ECR에 Docker 이미지 Push 하기
run: docker push ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest


- name: SSH로 EC2에 접속하기
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
docker stop locavel-server || true
docker rm locavel-server || true
docker pull ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest
docker run -d --name locavel-server -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ out/

### VS Code ###
.vscode/
# YAML files
*.yml

# CI/CD 관련 deploy.yml 파일 제외
!.github/workflows/deploy.yml
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM eclipse-temurin:17-jdk-alpine
COPY ./build/libs/*SNAPSHOT.jar project.jar
ENTRYPOINT ["java", "-jar", "project.jar"]

17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,30 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'com.auth0:java-jwt:4.2.1'//jwt추가
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 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3'
testImplementation 'org.springframework.security:spring-security-test'
// testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'

// S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// 네이버맵
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-actuator'

runtimeOnly("io.netty:netty-resolver-dns-native-macos:4.1.94.Final:osx-aarch_64")

}

tasks.named('test') {
useJUnitPlatform()
}
g
Binary file added src/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/java/com/example/locavel/LocavelApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
public class LocavelApplication {

public static void main(String[] args) {
Expand Down
169 changes: 169 additions & 0 deletions src/main/java/com/example/locavel/MakeInitData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.example.locavel;

import com.example.locavel.domain.Region;
import com.example.locavel.domain.Term;
import com.example.locavel.repository.RegionRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//더미 데이터 생성용
@Configuration
public class MakeInitData {

@Bean // 지역별 엔티티 생성
public CommandLineRunner loadRegionData(RegionRepository regionRepository) {
return args -> {
Region region1 = Region.builder()
.name("강남구")
.build();
Region region2 = Region.builder()
.name("강동구")
.build();
Region region3 = Region.builder()
.name("강북구")
.build();
Region region4 = Region.builder()
.name("강서구")
.build();
Region region5 = Region.builder()
.name("관악구")
.build();
Region region6 = Region.builder()
.name("광진구")
.build();
Region region7 = Region.builder()
.name("구로구")
.build();
Region region8 = Region.builder()
.name("금천구")
.build();
Region region9 = Region.builder()
.name("노원구")
.build();
Region region10 = Region.builder()
.name("도봉구")
.build();
Region region11 = Region.builder()
.name("동대문구")
.build();
Region region12 = Region.builder()
.name("동작구")
.build();
Region region13 = Region.builder()
.name("마포구")
.build();
Region region14 = Region.builder()
.name("서대문구")
.build();
Region region15 = Region.builder()
.name("서초구")
.build();
Region region16 = Region.builder()
.name("성동구")
.build();
Region region17 = Region.builder()
.name("성북구")
.build();
Region region18 = Region.builder()
.name("송파구")
.build();
Region region19 = Region.builder()
.name("양천구")
.build();
Region region20 = Region.builder()
.name("영등포구")
.build();
Region region21 = Region.builder()
.name("용산구")
.build();
Region region22 = Region.builder()
.name("은평구")
.build();
Region region23 = Region.builder()
.name("종로구")
.build();
Region region24 = Region.builder()
.name("중구")
.build();
Region region25 = Region.builder()
.name("중랑구")
.build();
if (regionRepository.findByName(region1.getName()) == null) {
regionRepository.save(region1);
}
if (regionRepository.findByName(region2.getName()) == null) {
regionRepository.save(region2);
}
if (regionRepository.findByName(region3.getName()) == null) {
regionRepository.save(region3);
}
if (regionRepository.findByName(region4.getName()) == null) {
regionRepository.save(region4);
}
if (regionRepository.findByName(region5.getName()) == null) {
regionRepository.save(region5);
}
if (regionRepository.findByName(region6.getName()) == null) {
regionRepository.save(region6);
}
if (regionRepository.findByName(region7.getName()) == null) {
regionRepository.save(region7);
}
if (regionRepository.findByName(region8.getName()) == null) {
regionRepository.save(region8);
}
if (regionRepository.findByName(region9.getName()) == null) {
regionRepository.save(region9);
}
if (regionRepository.findByName(region10.getName()) == null) {
regionRepository.save(region10);
}
if (regionRepository.findByName(region11.getName()) == null) {
regionRepository.save(region11);
}
if (regionRepository.findByName(region12.getName()) == null) {
regionRepository.save(region12);
}
if (regionRepository.findByName(region13.getName()) == null) {
regionRepository.save(region13);
}
if (regionRepository.findByName(region14.getName()) == null) {
regionRepository.save(region14);
}
if (regionRepository.findByName(region15.getName()) == null) {
regionRepository.save(region15);
}
if (regionRepository.findByName(region16.getName()) == null) {
regionRepository.save(region16);
}
if (regionRepository.findByName(region17.getName()) == null) {
regionRepository.save(region17);
}
if (regionRepository.findByName(region18.getName()) == null) {
regionRepository.save(region18);
}
if (regionRepository.findByName(region19.getName()) == null) {
regionRepository.save(region19);
}
if (regionRepository.findByName(region20.getName()) == null) {
regionRepository.save(region20);
}
if (regionRepository.findByName(region21.getName()) == null) {
regionRepository.save(region21);
}
if (regionRepository.findByName(region22.getName()) == null) {
regionRepository.save(region22);
}
if (regionRepository.findByName(region23.getName()) == null) {
regionRepository.save(region23);
}
if (regionRepository.findByName(region24.getName()) == null) {
regionRepository.save(region24);
}
if (regionRepository.findByName(region25.getName()) == null) {
regionRepository.save(region25);
}
};
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/example/locavel/apiPayload/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.locavel.apiPayload;

import com.example.locavel.apiPayload.code.BaseCode;
import com.example.locavel.apiPayload.code.status.SuccessStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@JsonPropertyOrder({"isSuccess", "code", "message", "result"})
public class ApiResponse<T> {

@JsonProperty("isSuccess")
private final Boolean isSuccess;
private final String code;
private final String message;
@JsonInclude(JsonInclude.Include.NON_NULL)
private T result; //generic type: 어떤 값이 올지 모르기 때문에 generic 으로 선언, 추후에 외부에서 지정 가능


// 성공한 경우 응답 생성

public static <T> ApiResponse<T> onSuccess(T result){
return new ApiResponse<>(true, SuccessStatus._OK.getCode() , SuccessStatus._OK.getMessage(), result);
}

public static <T> ApiResponse<T> of(BaseCode code, T result){
return new ApiResponse<>(true, code.getReasonHttpStatus().getCode() , code.getReasonHttpStatus().getMessage(), result);
}

// 실패한 경우 응답 생성
public static <T> ApiResponse<T> onFailure(String code, String message, T data){
return new ApiResponse<>(false, code, message, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.locavel.apiPayload.code;

public interface BaseCode {
public ReasonDTO getReason();

public ReasonDTO getReasonHttpStatus();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.locavel.apiPayload.code;

public interface BaseErrorCode {
public ErrorReasonDTO getReason();

public ErrorReasonDTO getReasonHttpStatus();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.locavel.apiPayload.code;

import lombok.Builder;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@Builder
public class ErrorReasonDTO {

private HttpStatus httpStatus;

private final boolean isSuccess;
private final String code;
private final String message;

public boolean getIsSuccess(){return isSuccess;}
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/locavel/apiPayload/code/ReasonDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.locavel.apiPayload.code;

import lombok.Builder;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@Builder
public class ReasonDTO {

private HttpStatus httpStatus;

private final boolean isSuccess;
private final String code;
private final String message;

public boolean getIsSuccess(){return isSuccess;}
}
Loading

0 comments on commit fd51636

Please sign in to comment.