Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] GitHub action 도입 #23

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "bug"
about: 버그 이슈 템플릿
title: "[Bug] "
labels: "🐛 bug"
assignees: ''

---

## 📌 Description
-
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/chore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: "chore"
about: 세팅
title: "[Chore] "
labels: "⚙️ chore"
assignees: ''
---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "deploy"
about: 배포
title: "[Deploy] "
labels: "💡 deploy"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "docs"
about: 문서 작업
title: "[Docs] "
labels: "✏️ docs"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "feature"
about: 새로운 기능 추가
title: "[Feat] "
labels: "⭐️ feature"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "test"
about: 테스트
title: "[Test] "
labels: "✅ test"
assignees: ''

---

## 📌 Description
-
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 @@
## 💡 Issue
- close #

## 📌 Work Description
-

## 📝 Reference
-

## 📚 Etc
-
119 changes: 119 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: CI/CD Pipeline for Spring Project

# 트리거 설정: 해당 브랜치로 풀리퀘스트가 머지될 때 트리거
on:
push:
branches:
- develop
jobs:
build:
# 빌드 작업은 Ubuntu에서 실행
runs-on: ubuntu-latest

steps:
# 1. 소스 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v2

# 2. JDK 설치 (Java 17 기준)
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt' # OpenJDK 사용
java-version: '17'

# 3. Gradle 빌드
- name: Build with Gradle
run: ./gradlew clean build -x test # 테스트를 제외한 Gradle 빌드

# 4. Docker 이미지 빌드
- name: Build Docker image
run: docker build -t fitpet .

# 5. Docker Hub로 Docker 이미지 푸시 (선택적 단계)
- name: Push Docker Image to Docker Hub
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker tag fitpet:latest ${{ secrets.DOCKER_USERNAME }}/fitpet:latest
docker push ${{ secrets.DOCKER_USERNAME }}/fitpet:latest

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v0.1.5
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin


docker pull ${{ secrets.DOCKER_USERNAME }}/fitpet:latest

cd /home/ubuntu

docker-compose -f docker-compose.yml up --build -d


#name: CI/CD Pipeline for Spring Project - 이거는 도커파일만 이용해서 사용한 방식
## 트리거 설정: 해당 브랜치로 풀리퀘스트가 머지될 때 트리거
#on:
# push:
# branches: [ "test/#25-workflow-test" ]
# # 나중에 최종으로 사용할 때
## pull_request:
## brances: [develop]
#jobs:
# build:
# # 빌드 작업은 Ubuntu에서 실행
# runs-on: ubuntu-latest
# steps:
# # 1. 소스 코드 체크아웃
# - name: Checkout code
# uses: actions/checkout@v2
# # 2. JDK 설치 (Java 17 기준)
# - name: Set up JDK 17
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt' # OpenJDK 사용
# java-version: '17'
# # 3. Gradle 빌드
# - name: Build with Gradle
# run: ./gradlew clean build -x test # 테스트를 제외한 Gradle 빌드
# # 4. Docker 이미지 빌드
# - name: Build Docker image
# run: docker build -t fitpet .
# # 5. Docker Hub로 Docker 이미지 푸시 (선택적 단계)
# - name: Push Docker Image to Docker Hub
# run: |
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# docker tag fitpet:latest ${{ secrets.DOCKER_USERNAME }}/fitpet:latest
# docker push ${{ secrets.DOCKER_USERNAME }}/fitpet:latest
# deploy:
# # 배포 작업은 빌드 작업이 완료된 후 실행
# runs-on: ubuntu-latest
# needs: build
#
# steps:
# # 1. EC2 인스턴스로 SSH 접속시키게
# - name: Deploy to EC2 via SSH
# uses: appleboy/ssh-action@v0.1.5
# with:
# host: ${{ secrets.EC2_HOST }}
# username: ${{ secrets.EC2_USERNAME }}
# key: ${{ secrets.EC2_SSH_KEY }}
# port: 22
# script: |
#
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# docker pull ${{ secrets.DOCKER_USERNAME }}/fitpet:latest
#
# docker stop fitpet || true
# docker rm fitpet || true
#
# docker run -d --name fitpet -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/fitpet:latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.env
.idea
*.iws
*.iml
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openjdk:17-jdk-alpine
VOLUME /tmp
ARG JAR_FILE=build/libs/fitpet-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} /app.jar

# spring.profiles.active를 prod로 설정
ENV SPRING_PROFILES_ACTIVE=prod

# 작업 디렉토리 설정
WORKDIR /

# JAR 파일을 실행하게
ENTRYPOINT ["java", "-jar", "/app.jar"]
38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33'

//Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

//Querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

//Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'

// Oauth2
implementation 'org.springframework.security:spring-security-oauth2-client'
implementation 'org.springframework.security:spring-security-oauth2-jose'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Spring Cloud
implementation platform("org.springframework.cloud:spring-cloud-dependencies:2023.0.2")

// Spring Cloud Open Feign
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

}

tasks.named('test') {
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3'
services:
app:
image: jihyun2ee/fitpet:latest
## 이게 필수세요~ env_file 등록!
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: prod
PROD_MYSQL_HOST: ${PROD_MYSQL_HOST}
PROD_MYSQL_DB_NAME: ${PROD_MYSQL_DB_NAME}
PROD_MYSQL_USERNAME: ${PROD_MYSQL_USERNAME}
PROD_MYSQL_PASSWORD: ${PROD_MYSQL_PASSWORD}
ports:
- "8080:8080"
networks:
- app-network

networks:
app-network:
driver: bridge
18 changes: 18 additions & 0 deletions src/main/java/appjjang/fitpet/domain/advertising/Advertising.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package appjjang.fitpet.domain.advertising;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Advertising {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "advertising_id")
private Long id;

private String imageUrl;
}
41 changes: 41 additions & 0 deletions src/main/java/appjjang/fitpet/domain/auth/api/AuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package appjjang.fitpet.domain.auth.api;

import appjjang.fitpet.domain.auth.application.AuthService;
import appjjang.fitpet.domain.auth.dto.request.TokenRefreshRequest;
import appjjang.fitpet.domain.auth.dto.response.TokenPairResponse;
import appjjang.fitpet.global.util.MemberUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static appjjang.fitpet.global.common.constants.SecurityConstants.REDIRECT_LOGIN_CODE;

@Tag(name = "인증 API", description = "인증 관련 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/auth")
public class AuthController {
private final AuthService authService;
private final MemberUtil memberUtil;

@Operation(summary = "소셜 로그인 및 회원가입", description = "카카오 소셜 로그인을 이용하여 회원가입 및 로그인을 진행합니다.")
@GetMapping("/login")
public TokenPairResponse memberOauthLogin(@RequestParam(REDIRECT_LOGIN_CODE) String code) {
return authService.socialLogin(code);
}

@Operation(summary = "토큰 재발급", description = "엑세스 토큰 및 리프테시 토큰을 모두 재발급합니다.")
@PostMapping("/refresh")
public TokenPairResponse refreshToken(@RequestBody TokenRefreshRequest request) {
return authService.tokenRefresh(request);
}

@Operation(summary = "로그아웃", description = "로그아웃을 진행합니다.")
@PostMapping("/logout")
public ResponseEntity<Void> memberLogout() {
authService.memberLogout();
return ResponseEntity.ok().build();
}
}
Loading
Loading