-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Chore] : CICD 설정
- Loading branch information
Showing
7 changed files
with
155 additions
and
7 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 |
---|---|---|
@@ -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 |
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,5 @@ | ||
FROM openjdk:17 | ||
|
||
COPY ./build/libs/onetime-0.0.1-SNAPSHOT.jar app.jar | ||
|
||
ENTRYPOINT ["java", "-jar", "app.jar"] |
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
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,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
46
src/main/java/side/onetime/global/config/SecurityConfig.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,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(); | ||
} | ||
} |
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,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 |
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