feat(gateway): сервис pcp-gateway-service + сворачивание маршрутизации фронта на него
- новый Spring Cloud Gateway (WebFlux): доменные маршруты /api/pcp-<x>/**
со StripPrefix=2, /api/stations без среза пути, catch-all /api/** → ui-service;
опциональная JWT-валидация на edge (gateway.security.jwt-enabled, по умолчанию off)
- config-repo: pcp-gateway-service.yaml (маршруты) + порт/адрес gateway в реестрах
application-{local,docker-local,dev}
- build: репозитории переведены на mavenCentral (nstart-proxy закомментирован),
включены mavenLocal/gradlePluginPortal; settings: include модуля
- pcp-tgu-ui-service: vite-proxy и nginx.conf свёрнуты на единый /api → gateway
(вместо набора per-service правил)
- deploy: сервис gateway в docker-compose; helm-чарт pcp-gateway-service
- CI: .gitlab/ci/pcp-gateway-service.yml + проводка в .gitlab-ci.yml
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
variables:
|
||||
GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle"
|
||||
|
||||
GATEWAY_SERVICE_DIR: "services/pcp-gateway-service"
|
||||
GATEWAY_HELM_CHART_DIR: "helm/pcp-gateway-service"
|
||||
GATEWAY_HELM_RELEASE: "pcp-gateway-service"
|
||||
GATEWAY_IMAGE_REPOSITORY: "$INTERNAL_REGISTRY/pcp-gateway-service"
|
||||
GATEWAY_IMAGE_TAG: "$CI_COMMIT_SHORT_SHA"
|
||||
GATEWAY_K8S_NAMESPACE_DEV: "pcp-dev"
|
||||
|
||||
.gateway_changes: &gateway_changes
|
||||
- services/pcp-gateway-service/**/*
|
||||
- build.gradle.kts
|
||||
- settings.gradle.kts
|
||||
- .gitlab/ci/pcp-gateway-service.yml
|
||||
- helm/pcp-gateway-service/**/*
|
||||
- deploy/**/*
|
||||
|
||||
.gateway:rules:build-and-image:
|
||||
rules:
|
||||
- if: '$RUN_ALL == "true"'
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
changes: *gateway_changes
|
||||
- if: '$CI_COMMIT_BRANCH == "dev"'
|
||||
changes: *gateway_changes
|
||||
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||
changes: *gateway_changes
|
||||
- when: never
|
||||
|
||||
.gateway:rules:test:
|
||||
rules:
|
||||
- if: '$RUN_ALL == "true"'
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
changes: *gateway_changes
|
||||
- if: '$CI_COMMIT_BRANCH == "dev"'
|
||||
changes: *gateway_changes
|
||||
when: manual
|
||||
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||
changes: *gateway_changes
|
||||
- when: never
|
||||
|
||||
.gateway:rules:deploy-dev:
|
||||
rules:
|
||||
- if: '$RUN_ALL == "true"'
|
||||
when: manual
|
||||
- if: '$CI_COMMIT_BRANCH == "dev"'
|
||||
changes: *gateway_changes
|
||||
when: manual
|
||||
- when: never
|
||||
|
||||
.gateway:gradle-cache:
|
||||
cache:
|
||||
key: "gradle-gateway-$CI_DEFAULT_BRANCH"
|
||||
paths:
|
||||
- .gradle/wrapper
|
||||
- .gradle/caches
|
||||
policy: pull-push
|
||||
|
||||
.gateway:docker-build:
|
||||
image: repo.nstart.cloud/library/docker:26
|
||||
services:
|
||||
- name: repo.nstart.cloud/library/docker:26-dind
|
||||
alias: docker
|
||||
command: ["--tls=false", "--insecure-registry=registry.k8s.265.nstart.local"]
|
||||
variables:
|
||||
DOCKER_HOST: tcp://docker:2375
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
DOCKER_BUILDKIT: "1"
|
||||
before_script:
|
||||
- docker version
|
||||
- docker info
|
||||
|
||||
.gateway:helm-deploy:
|
||||
image: repo.nstart.cloud/dtzar/helm-kubectl:3.14.0
|
||||
before_script:
|
||||
- mkdir -p /root/.kube
|
||||
- helm version
|
||||
after_script:
|
||||
- rm -f /root/.kube/config
|
||||
|
||||
gateway:test:
|
||||
stage: test
|
||||
image: repo.nstart.cloud/library/gradle:jdk21-ubi10
|
||||
extends:
|
||||
- .gateway:rules:test
|
||||
- .gateway:gradle-cache
|
||||
script:
|
||||
- gradle --no-daemon :services:pcp-gateway-service:test
|
||||
artifacts:
|
||||
when: always
|
||||
reports:
|
||||
junit:
|
||||
- services/pcp-gateway-service/build/test-results/test/*.xml
|
||||
paths:
|
||||
- services/pcp-gateway-service/build/reports/tests/
|
||||
expire_in: 7 days
|
||||
|
||||
gateway:build:
|
||||
stage: build
|
||||
image: repo.nstart.cloud/library/gradle:jdk21-ubi10
|
||||
extends:
|
||||
- .gateway:rules:build-and-image
|
||||
- .gateway:gradle-cache
|
||||
needs:
|
||||
- job: gateway:test
|
||||
artifacts: true
|
||||
script:
|
||||
- gradle --no-daemon :services:pcp-gateway-service:bootJar
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- services/pcp-gateway-service/build/libs/*.jar
|
||||
expire_in: 7 days
|
||||
|
||||
gateway:package:
|
||||
stage: package
|
||||
extends:
|
||||
- .gateway:rules:build-and-image
|
||||
- .gateway:docker-build
|
||||
needs:
|
||||
- job: gateway:build
|
||||
artifacts: true
|
||||
script:
|
||||
- 'echo "GATEWAY_IMAGE_REPOSITORY=$GATEWAY_IMAGE_REPOSITORY"'
|
||||
- |
|
||||
JAR_COUNT="$(find "$GATEWAY_SERVICE_DIR/build/libs" -maxdepth 1 -type f -name '*.jar' ! -name '*-plain.jar' | wc -l)"
|
||||
|
||||
if [ "$JAR_COUNT" -ne 1 ]; then
|
||||
echo "Expected exactly one executable jar, found: $JAR_COUNT"
|
||||
find "$GATEWAY_SERVICE_DIR/build/libs" -maxdepth 1 -type f -name '*.jar' -print || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
JAR_FILE="$(find "$GATEWAY_SERVICE_DIR/build/libs" -maxdepth 1 -type f -name '*.jar' ! -name '*-plain.jar' | head -n 1)"
|
||||
- rm -rf docker-context
|
||||
- mkdir -p docker-context/build/libs
|
||||
- cp "$GATEWAY_SERVICE_DIR/Dockerfile" docker-context/Dockerfile
|
||||
- cp "$JAR_FILE" docker-context/build/libs/app.jar
|
||||
- find docker-context -maxdepth 4 -type f -print -exec ls -la {} \;
|
||||
- docker build --file docker-context/Dockerfile --tag "$GATEWAY_IMAGE_REPOSITORY:$GATEWAY_IMAGE_TAG" docker-context
|
||||
- docker push "$GATEWAY_IMAGE_REPOSITORY:$GATEWAY_IMAGE_TAG"
|
||||
- printf "GATEWAY_IMAGE=%s\n" "$GATEWAY_IMAGE_REPOSITORY:$GATEWAY_IMAGE_TAG" > gateway-image.env
|
||||
artifacts:
|
||||
reports:
|
||||
dotenv: gateway-image.env
|
||||
expire_in: 7 days
|
||||
|
||||
gateway:deploy:dev:
|
||||
stage: deploy
|
||||
extends:
|
||||
- .gateway:rules:deploy-dev
|
||||
- .gateway:helm-deploy
|
||||
needs:
|
||||
- job: gateway:package
|
||||
artifacts: true
|
||||
environment:
|
||||
name: dev/pcp-gateway-service
|
||||
script:
|
||||
- |
|
||||
if [ -n "${KUBE_CONFIG_DEV:-}" ]; then
|
||||
printf '%s' "$KUBE_CONFIG_DEV" > /root/.kube/config
|
||||
elif [ -n "${KUBE_CONFIG_DEV_B64:-}" ]; then
|
||||
if printf '%s' "$KUBE_CONFIG_DEV_B64" | grep -qE '(^apiVersion:|^kind: Config|^clusters:)'; then
|
||||
printf '%s' "$KUBE_CONFIG_DEV_B64" > /root/.kube/config
|
||||
elif ! printf '%s' "$KUBE_CONFIG_DEV_B64" | base64 -d > /root/.kube/config; then
|
||||
echo "KUBE_CONFIG_DEV_B64 is not valid base64. Set KUBE_CONFIG_DEV to raw kubeconfig or KUBE_CONFIG_DEV_B64 to base64 kubeconfig."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "KUBE_CONFIG_DEV or KUBE_CONFIG_DEV_B64 must be set."
|
||||
exit 1
|
||||
fi
|
||||
- chmod 600 /root/.kube/config
|
||||
- export KUBECONFIG=/root/.kube/config
|
||||
- 'export IMAGE_REPOSITORY="${GATEWAY_IMAGE%:*}"'
|
||||
- 'export IMAGE_TAG="${GATEWAY_IMAGE##*:}"'
|
||||
- 'echo "Deploy image: $IMAGE_REPOSITORY:$IMAGE_TAG"'
|
||||
- >
|
||||
helm upgrade --install "$GATEWAY_HELM_RELEASE"
|
||||
"$GATEWAY_HELM_CHART_DIR"
|
||||
--namespace "$GATEWAY_K8S_NAMESPACE_DEV"
|
||||
--create-namespace
|
||||
--values "$GATEWAY_HELM_CHART_DIR/values.yaml"
|
||||
--values "$GATEWAY_HELM_CHART_DIR/values-dev.yaml"
|
||||
--set-string image.repository="$IMAGE_REPOSITORY"
|
||||
--set-string image.tag="$IMAGE_TAG"
|
||||
--set-string app.profile=dev
|
||||
--set-string app.configLabel=dev
|
||||
--atomic
|
||||
--wait
|
||||
--timeout 15m
|
||||
Reference in New Issue
Block a user