Skip to content

Commit

Permalink
Merge pull request #2 from onetime-with-members/feature/#1/cicd
Browse files Browse the repository at this point in the history
[Chore] : CICD 설정
  • Loading branch information
bbbang105 authored Aug 14, 2024
2 parents 6a2fa28 + 6e11e67 commit 1e934b4
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 7 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Onetime CI/CD with Gradle

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

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: ⏱️Set up JDK 17
uses: actions/setup-java@v3
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: ⏱️gradle build를 위한 권한을 부여합니다.
run: chmod +x gradlew

- name: ⏱️gradle build 중입니다.
run: ./gradlew build -x test

- name: ⏱️NCP Container Registry에 로그인 후, docker image build 후 NCP Container Registry에 push합니다.
run: |
docker login -u ${{ secrets.NCP_API_ACCESS_KEY }} -p ${{ secrets.NCP_API_SECRET_KEY }} ${{secrets.NCP_CONTAINER_REGISTRY_PUBLIC_ENDPOINT}}
docker build -f Dockerfile -t ${{ secrets.NCP_CONTAINER_REGISTRY_PUBLIC_ENDPOINT }}/${{ secrets.NCP_CONTAINER_REGISTRY_IMAGE }} .
docker push ${{ secrets.NCP_CONTAINER_REGISTRY_PUBLIC_ENDPOINT }}/${{ secrets.NCP_CONTAINER_REGISTRY_IMAGE }}
- name: ⏱️NCP Container Registry에서 pull 후 deploy합니다.
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
host: ${{ secrets.NCP_SERVER_HOST }}
port: ${{ secrets.NCP_SERVER_PORT }}
script: |
chmod 777 ./deploy.sh
./deploy.sh
docker image prune -f
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17

COPY ./build/libs/onetime-0.0.1-SNAPSHOT.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ repositories {
}

dependencies {
// Web
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// DB
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.security:spring-security-test'
// Lombok
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/side/onetime/controller/TestConrtoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package side.onetime.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestConrtoller {

@GetMapping("/api/v1/test")
public String test() {
return "Onetime!";
}
}
46 changes: 46 additions & 0 deletions src/main/java/side/onetime/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package side.onetime.global.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

import java.util.Collections;

@RequiredArgsConstructor
@Configuration
@EnableWebSecurity
public class SecurityConfig {

// CORS 설정
CorsConfigurationSource corsConfigurationSource() {
return request -> {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setAllowedOriginPatterns(Collections.singletonList("*")); // 허용할 origin
config.setAllowCredentials(true);
return config;
};
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.
httpBasic(HttpBasicConfigurer::disable)
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource())) // CORS 설정 추가
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/**").permitAll()
);

return httpSecurity.build();
}
}
25 changes: 25 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
server:
port: ${SERVER_PORT}

spring:
datasource:
url: ${DATABASE_URL}
username: ${DATABASE_HOST}
password: ${DATABASE_PW}
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: update

defer-datasource-initialization: true
open-in-view: false
generate-ddl: true
show-sql: true

sql:
init:
mode: always
3 changes: 1 addition & 2 deletions src/test/java/side/onetime/OnetimeApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@SpringBootTest(classes = OnetimeApplicationTests.class)
class OnetimeApplicationTests {

@Test
Expand Down

0 comments on commit 1e934b4

Please sign in to comment.