Skip to content

Commit

Permalink
🎉Start: Start New Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Jindongleee committed Oct 14, 2024
1 parent 691b29d commit 272b6a0
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/cd.yml
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
}

tasks.named('test') {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/example/gather_back_end/HelloController.java
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";
}
}
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 src/main/java/org/example/gather_back_end/config/WebConfig.java
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);
}
}

0 comments on commit 272b6a0

Please sign in to comment.