-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#1 CI/CD 구축 및 Netflix Eureka Client(Gateway) 설정 #2
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
Changes from 16 commits
84a6ab0
328c3c5
065d2a2
025222d
69defe5
98bd457
e841c55
7edc481
8bdeae5
cba66d1
e8ab40e
d5ee785
f1fadb2
1e18f6b
cde3e4b
ee57b7e
98548ce
0bc45eb
b92874b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: gateway-service dev CD 파이프라인 | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["gateway-service CI pipeline"] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| environment: dev | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Docker 이미지 dev 서버 배포 | ||
| uses: appleboy/ssh-action@master | ||
| with: | ||
| host: ${{secrets.DEV_HOST}} | ||
| username: ${{secrets.DEV_USERNAME}} | ||
| key: ${{secrets.DEV_KEY}} | ||
| script: | | ||
| cd /home/ubuntu | ||
| docker rm -f gateway-service-dev || true | ||
| docker compose pull gateway-service-dev | ||
| docker compose up -d --no-deps --force-recreate --pull always gateway-service-dev | ||
| docker image prune -f |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: gateway-service prod CD 파이프라인 | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["gateway-service CI pipeline"] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| environment: dev | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Docker 이미지 dev 서버 배포 | ||
| uses: appleboy/ssh-action@master | ||
| with: | ||
| host: ${{secrets.PROD_HOST}} | ||
| username: ${{secrets.PROD_USERNAME}} | ||
| key: ${{secrets.PROD_KEY}} | ||
| script: | | ||
| cd /home/ubuntu | ||
| docker rm -f gateway-service-prod || true | ||
| docker compose pull gateway-service-prod | ||
| docker compose up -d --no-deps --force-recreate --pull always gateway-service-prod | ||
| docker image prune -f |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: gateway-service CI pipeline | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - dev | ||
| pull_request: | ||
| branches: | ||
| - dev | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| environment: production | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: jdk 설정 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
| cache: 'gradle' | ||
|
|
||
| - name: Gradle Wrapper 권한 부여 | ||
| run: chmod +x gradlew | ||
|
|
||
| - name: gradle 빌드 | ||
| run: ./gradlew clean build | ||
|
|
||
| - name: 도커 로그인 | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_ACCESS_TOKEN }} | ||
|
|
||
| - name: 이미지 빌드 및 푸시 | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| tags: ${{ secrets.DOCKER_USERNAME }}/unionmate-gateway-service:latest | ||
| push: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM openjdk:21-jdk | ||
|
|
||
| COPY build/libs/*SNAPSHOT.jar app.jar | ||
|
|
||
| ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -Dspring.profiles.active=${PROFILE} -jar /app.jar"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.unionmate.gateway_service.global; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.cors.CorsConfiguration; | ||
| import org.springframework.web.cors.reactive.CorsWebFilter; | ||
| import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; | ||
|
|
||
| @Configuration | ||
| public class SecurityConfig { | ||
| @Bean | ||
| public CorsWebFilter corsWebFilter() { | ||
| CorsConfiguration config = new CorsConfiguration(); | ||
| config.setAllowedOrigins(List.of("http://localhost:3000")); | ||
| config.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); | ||
| config.setAllowCredentials(true); | ||
| config.setAllowedHeaders(List.of("*")); | ||
| config.setExposedHeaders(List.of("Authorization", "Authorization-refresh")); | ||
1winhyun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
| source.registerCorsConfiguration("/**", config); | ||
|
|
||
| return new CorsWebFilter(source); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.unionmate.gateway_service.global.gateway; | ||
|
|
||
| import org.springframework.cloud.gateway.route.RouteLocator; | ||
| import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.http.HttpHeaders; | ||
|
|
||
| @Configuration | ||
| @Profile({"local","dev","prod"}) | ||
| public class GatewayConfiguration { | ||
|
|
||
| @Bean | ||
| public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { | ||
| return builder.routes() | ||
| // 인증 필요 없는 라우트 | ||
| .route("backend_route", r -> r.path("/**") | ||
| .filters(f -> f | ||
| .removeRequestHeader(HttpHeaders.COOKIE) | ||
| ) | ||
| .uri("lb://backend-service")) | ||
|
|
||
| //스웨거를 위한 라우트 설정(각 서비스마다 등록해줘야 합니다.) | ||
| .route("backend-service_api_docs", r -> r.path("/api-docs/backend/**") | ||
| .filters(f -> f | ||
| .rewritePath("/api-docs/backend/(?<rem>.*)", "/${rem}") | ||
| ) | ||
| .uri("lb://backend-service")) | ||
1winhyun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .build(); | ||
| } | ||
| } | ||
|
Comment on lines
10
to
33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 또
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 첫번째 질문에 대해서는 모든 요청(/**)을 backend-service로 전달해주는 역할이 맞습니다. 하지만 현재 저희는 user와 관련된 서비스, 메일과 관련된 서비스가 추가될 예정이기에 추후 해당 부분은 수정될 예정입니다. 예를 들면 다음 코드와 같이 구현될 예정입니다. .route("user_public_route", r -> r.path("/users/public/**")
.filters(f -> f
.removeRequestHeader(HttpHeaders.COOKIE)
)
.uri("lb://USER-SERVICE"))두번째 질문의 경우 취지는 동일합니다. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| server: | ||
| port: 8000 | ||
|
|
||
| spring: | ||
| main: | ||
| web-application-type: reactive | ||
| application: | ||
| name: gateway-service | ||
|
|
||
| eureka: | ||
| client: | ||
| fetch-registry: true | ||
| register-with-eureka: true | ||
| service-url: | ||
| defaultZone: http://3.34.87.16:8761/eureka | ||
|
|
||
| springdoc: | ||
| api-docs: | ||
| enabled: true | ||
| swagger-ui: | ||
| path: /swagger-ui.html | ||
| urls: | ||
| - name: backend-service | ||
| url: /api-docs/backend/v3/api-docs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| server: | ||
| port: 8000 | ||
|
|
||
| spring: | ||
| main: | ||
| web-application-type: reactive | ||
| application: | ||
| name: gateway-service | ||
|
|
||
| eureka: | ||
| client: | ||
| fetch-registry: true | ||
| register-with-eureka: true | ||
| service-url: | ||
| defaultZone: http://localhost:8761/eureka | ||
|
|
||
| springdoc: | ||
| api-docs: | ||
| enabled: true | ||
| swagger-ui: | ||
| path: /swagger-ui.html | ||
| urls: | ||
| - name: backend-service | ||
| url: /api-docs/backend/v3/api-docs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| server: | ||
| port: 8000 | ||
|
|
||
| spring: | ||
| main: | ||
| web-application-type: reactive | ||
| application: | ||
| name: gateway-service | ||
|
|
||
| eureka: | ||
| client: | ||
| fetch-registry: true | ||
| register-with-eureka: true | ||
| service-url: | ||
| defaultZone: http://discovery-service-prod:8761/eureka | ||
|
|
||
| springdoc: | ||
| api-docs: | ||
| enabled: true | ||
| swagger-ui: | ||
| path: /swagger-ui.html | ||
| urls: | ||
| - name: backend-service | ||
| url: /api-docs/backend/v3/api-docs | ||
|
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.