-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
691b29d
commit 272b6a0
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
name: cd with Gradle | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # main 브랜치에 push될 때 | ||
|
||
permissions: write-all # 테스트 결과 작성을 위해 쓰기권한 추가 | ||
|
||
jobs: | ||
build: | ||
if: github.event.pull_request.merged == true || github.event_name == 'push' # PR merge 또는 push일 때 실행 | ||
runs-on: ubuntu-latest # 환경 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 # 코드 체크아웃 = 가상환경 복사 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 #jdk 컴파일러 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' # 자바 개발 키트 배포판 | ||
|
||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Grant execute permission for Gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build -x test #빌드 | ||
|
||
- name: Ensure target directory exists | ||
uses: appleboy/ssh-action@master # SSH를 통해 대상 디렉토리 생성 | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.SSH_HOST }} | ||
key: ${{ secrets.SSH_KEY }} | ||
script: | | ||
mkdir -p /home/ubuntu/gather_back_end | ||
- name: List build directory | ||
run: ls -la build/libs | ||
|
||
- name: Transfer Build File using SCP | ||
uses: appleboy/scp-action@master # .jar 파일 원격 서버로 복사 | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.SSH_HOST }} | ||
key: ${{ secrets.SSH_KEY }} | ||
source: | | ||
build/libs/gather_back_end-0.0.1-SNAPSHOT.jar | ||
target: "/home/ubuntu/gather_back_end" | ||
|
||
- name: Deploy using Docker Compose via SSH(Prod) | ||
if: github.ref == 'refs/heads/main' | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.SSH_KEY }} | ||
script_stop: true | ||
script: | | ||
cd /home/ubuntu/gather_back_end || exit 1 # 경로 변경 실패 시 종료 | ||
sudo docker compose --env-file .env down | ||
sudo docker compose --env-file .env up --build -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/example/gather_back_end/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.example.gather_back_end; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("api") | ||
public class HelloController { | ||
|
||
@GetMapping | ||
public String helloGetMapping(){ | ||
return "hello"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/example/gather_back_end/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.example.gather_back_end.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.servers.Server; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@OpenAPIDefinition( | ||
info = @Info(title = "Gather", description = "4호선톤 숙쓰러운 서성한", version = "v1"), | ||
servers = { | ||
@Server(url = "http://158.180.73.142:8080", description = "서버 URL"), | ||
@Server(url = "http://localhost:8080", description = "로컬 URL") | ||
} | ||
) | ||
@RequiredArgsConstructor | ||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public GroupedOpenApi SwaggerOpenApi() { | ||
return GroupedOpenApi.builder() | ||
.group("Swagger-api") | ||
.pathsToMatch("/api/**") | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/example/gather_back_end/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.example.gather_back_end.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("*") | ||
.allowedMethods("GET", "POST", "PATCH", "DELETE") | ||
.maxAge(3000); | ||
} | ||
} |