From cb439319c559955a2184de914e22f39ad13076d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A1=D0=BE?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D1=8C=D0=B5=D0=B2?= Date: Tue, 9 Jun 2026 13:43:47 +0300 Subject: [PATCH] =?UTF-8?q?pcp-tgu-ui-service=20=D0=B2=20=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=BF=D0=BF=D0=B5=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20pcp:=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=20CI=20+=20per-service?= =?UTF-8?q?=20Node-=D0=BF=D0=B0=D0=B9=D0=BF=D0=BB=D0=B0=D0=B9=D0=BD=20+=20?= =?UTF-8?q?helm-=D1=87=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 7 + .gitlab/ci/pcp-tgu-ui-service.yml | 187 ++++++++++++++++++ helm/pcp-tgu-ui-service/Chart.yaml | 6 + .../pcp-tgu-ui-service/templates/_helpers.tpl | 18 ++ .../templates/deployment.yaml | 75 +++++++ .../pcp-tgu-ui-service/templates/ingress.yaml | 31 +++ .../pcp-tgu-ui-service/templates/service.yaml | 16 ++ helm/pcp-tgu-ui-service/values-dev.yaml | 10 + helm/pcp-tgu-ui-service/values-master.yaml | 10 + helm/pcp-tgu-ui-service/values.yaml | 40 ++++ 10 files changed, 400 insertions(+) create mode 100644 .gitlab/ci/pcp-tgu-ui-service.yml create mode 100644 helm/pcp-tgu-ui-service/Chart.yaml create mode 100644 helm/pcp-tgu-ui-service/templates/_helpers.tpl create mode 100644 helm/pcp-tgu-ui-service/templates/deployment.yaml create mode 100644 helm/pcp-tgu-ui-service/templates/ingress.yaml create mode 100644 helm/pcp-tgu-ui-service/templates/service.yaml create mode 100644 helm/pcp-tgu-ui-service/values-dev.yaml create mode 100644 helm/pcp-tgu-ui-service/values-master.yaml create mode 100644 helm/pcp-tgu-ui-service/values.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 518fa1f..bcb63bf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,7 @@ workflow: - services/pcp-ui-service/**/* - services/pcp-coverage-scheme-service/**/* - services/pcp-tgu-service/**/* + - services/pcp-tgu-ui-service/**/* - services/pcp-dynamic-plan-service/**/* - libs/pcp-types-lib/**/* - libs/ballistics-lib/**/* @@ -37,6 +38,7 @@ workflow: - helm/pcp-ui-service/**/* - helm/pcp-coverage-scheme-service/**/* - helm/pcp-tgu-service/**/* + - helm/pcp-tgu-ui-service/**/* - helm/pcp-dynamic-plan-service/**/* - if: '$CI_PIPELINE_SOURCE == "push"' changes: @@ -57,6 +59,7 @@ workflow: - services/pcp-ui-service/**/* - services/pcp-coverage-scheme-service/**/* - services/pcp-tgu-service/**/* + - services/pcp-tgu-ui-service/**/* - services/pcp-dynamic-plan-service/**/* - libs/pcp-types-lib/**/* - libs/ballistics-lib/**/* @@ -79,6 +82,7 @@ workflow: - helm/pcp-ui-service/**/* - helm/pcp-coverage-scheme-service/**/* - helm/pcp-tgu-service/**/* + - helm/pcp-tgu-ui-service/**/* - helm/pcp-dynamic-plan-service/**/* - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"' changes: @@ -95,6 +99,7 @@ workflow: - services/pcp-ui-service/**/* - services/pcp-coverage-scheme-service/**/* - services/pcp-tgu-service/**/* + - services/pcp-tgu-ui-service/**/* - services/pcp-dynamic-plan-service/**/* - libs/pcp-types-lib/**/* - libs/ballistics-lib/**/* @@ -117,6 +122,7 @@ workflow: - helm/pcp-ui-service/**/* - helm/pcp-coverage-scheme-service/**/* - helm/pcp-tgu-service/**/* + - helm/pcp-tgu-ui-service/**/* - helm/pcp-dynamic-plan-service/**/* - when: never @@ -157,4 +163,5 @@ include: - local: .gitlab/ci/pcp-ui-service.yml - local: .gitlab/ci/pcp-coverage-scheme-service.yml - local: .gitlab/ci/pcp-tgu-service.yml + - local: .gitlab/ci/pcp-tgu-ui-service.yml - local: .gitlab/ci/pcp-dynamic-plan-service.yml diff --git a/.gitlab/ci/pcp-tgu-ui-service.yml b/.gitlab/ci/pcp-tgu-ui-service.yml new file mode 100644 index 0000000..841b348 --- /dev/null +++ b/.gitlab/ci/pcp-tgu-ui-service.yml @@ -0,0 +1,187 @@ +# pcp-tgu-ui-service — статический фронт ТГУ (Node/Vite → nginx). В отличие от +# остальных сервисов группы (gradle/Spring), собирается на Node: test = vitest, +# build = npm run build (tsc+vite), package = docker по своему Dockerfile. +variables: + TGU_UI_SERVICE_DIR: "services/pcp-tgu-ui-service" + TGU_UI_HELM_CHART_DIR: "helm/pcp-tgu-ui-service" + TGU_UI_HELM_RELEASE: "pcp-tgu-ui-service" + TGU_UI_IMAGE_REPOSITORY: "$INTERNAL_REGISTRY/pcp-tgu-ui-service" + TGU_UI_IMAGE_TAG: "$CI_COMMIT_SHORT_SHA" + TGU_UI_K8S_NAMESPACE_DEV: "pcp-dev" + TGU_UI_K8S_NAMESPACE_MASTER: "pcp-master" + TGU_UI_NODE_IMAGE: "repo.nstart.cloud/nstart/node:24-trixie-slim" + +.tgu_ui_changes: &tgu_ui_changes + - services/pcp-tgu-ui-service/**/* + - .gitlab/ci/pcp-tgu-ui-service.yml + - helm/pcp-tgu-ui-service/**/* + - deploy/**/* + +.tgu-ui:rules:build-and-image: + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + changes: *tgu_ui_changes + - if: '$CI_COMMIT_BRANCH == "dev"' + changes: *tgu_ui_changes + - if: '$CI_COMMIT_BRANCH == "master"' + changes: *tgu_ui_changes + - when: never + +.tgu-ui:rules:test: + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + changes: *tgu_ui_changes + - if: '$CI_COMMIT_BRANCH == "dev"' + changes: *tgu_ui_changes + when: manual + - if: '$CI_COMMIT_BRANCH == "master"' + changes: *tgu_ui_changes + - when: never + +.tgu-ui:rules:deploy-dev: + rules: + - if: '$CI_COMMIT_BRANCH == "dev"' + changes: *tgu_ui_changes + when: manual + - when: never + +.tgu-ui:rules:deploy-master: + rules: + - if: '$CI_COMMIT_BRANCH == "master"' + changes: *tgu_ui_changes + when: manual + - when: never + +.tgu-ui:npm-cache: + cache: + key: "npm-tgu-ui-$CI_DEFAULT_BRANCH" + paths: + - services/pcp-tgu-ui-service/.npm + policy: pull-push + +.tgu-ui:docker-build: + image: docker:26 + services: + - name: 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 + +.tgu-ui:helm-deploy: + image: + name: alpine/helm:3.16.4 + entrypoint: [""] + before_script: + - mkdir -p ~/.kube + - helm version + +tgu-ui:test: + stage: test + image: $TGU_UI_NODE_IMAGE + extends: + - .tgu-ui:rules:test + - .tgu-ui:npm-cache + script: + - cd "$TGU_UI_SERVICE_DIR" + - npm ci --cache .npm --prefer-offline + - npm run test + +tgu-ui:build: + stage: build + image: $TGU_UI_NODE_IMAGE + extends: + - .tgu-ui:rules:build-and-image + - .tgu-ui:npm-cache + script: + - cd "$TGU_UI_SERVICE_DIR" + - npm ci --cache .npm --prefer-offline + - npm run build + artifacts: + when: always + paths: + - services/pcp-tgu-ui-service/dist/ + expire_in: 7 days + +# Образ собирает сам Dockerfile (multi-stage: npm ci + build внутри). Артефакт +# tgu-ui:build — быстрый gate на tsc+vite перед более тяжёлым docker build. +tgu-ui:package: + stage: package + extends: + - .tgu-ui:rules:build-and-image + - .tgu-ui:docker-build + needs: + - job: tgu-ui:build + artifacts: false + script: + - 'echo "TGU_UI_IMAGE_REPOSITORY=$TGU_UI_IMAGE_REPOSITORY"' + - docker build --file "$TGU_UI_SERVICE_DIR/Dockerfile" --tag "$TGU_UI_IMAGE_REPOSITORY:$TGU_UI_IMAGE_TAG" "$TGU_UI_SERVICE_DIR" + - docker push "$TGU_UI_IMAGE_REPOSITORY:$TGU_UI_IMAGE_TAG" + - printf "TGU_UI_IMAGE=%s\n" "$TGU_UI_IMAGE_REPOSITORY:$TGU_UI_IMAGE_TAG" > tgu-ui-image.env + artifacts: + reports: + dotenv: tgu-ui-image.env + expire_in: 7 days + +tgu-ui:deploy:dev: + stage: deploy + extends: + - .tgu-ui:rules:deploy-dev + - .tgu-ui:helm-deploy + needs: + - job: tgu-ui:package + artifacts: true + environment: + name: dev/pcp-tgu-ui-service + script: + - 'echo "$KUBE_CONFIG_DEV_B64" | base64 -d > ~/.kube/config' + - chmod 600 ~/.kube/config + - 'export IMAGE_REPOSITORY="${TGU_UI_IMAGE%:*}"' + - 'export IMAGE_TAG="${TGU_UI_IMAGE##*:}"' + - 'echo "Deploy image: $IMAGE_REPOSITORY:$IMAGE_TAG"' + - > + helm upgrade --install "$TGU_UI_HELM_RELEASE" + "$TGU_UI_HELM_CHART_DIR" + --namespace "$TGU_UI_K8S_NAMESPACE_DEV" + --create-namespace + --wait + --atomic + --timeout 10m + -f "$TGU_UI_HELM_CHART_DIR/values.yaml" + -f "$TGU_UI_HELM_CHART_DIR/values-dev.yaml" + --set image.repository="$IMAGE_REPOSITORY" + --set image.tag="$IMAGE_TAG" + +tgu-ui:deploy:master: + stage: deploy + extends: + - .tgu-ui:rules:deploy-master + - .tgu-ui:helm-deploy + needs: + - job: tgu-ui:package + artifacts: true + environment: + name: master/pcp-tgu-ui-service + script: + - 'echo "$KUBE_CONFIG_MASTER_B64" | base64 -d > ~/.kube/config' + - chmod 600 ~/.kube/config + - 'export IMAGE_REPOSITORY="${TGU_UI_IMAGE%:*}"' + - 'export IMAGE_TAG="${TGU_UI_IMAGE##*:}"' + - 'echo "Deploy image: $IMAGE_REPOSITORY:$IMAGE_TAG"' + - > + helm upgrade --install "$TGU_UI_HELM_RELEASE" + "$TGU_UI_HELM_CHART_DIR" + --namespace "$TGU_UI_K8S_NAMESPACE_MASTER" + --create-namespace + --wait + --atomic + --timeout 10m + -f "$TGU_UI_HELM_CHART_DIR/values.yaml" + -f "$TGU_UI_HELM_CHART_DIR/values-master.yaml" + --set image.repository="$IMAGE_REPOSITORY" + --set image.tag="$IMAGE_TAG" diff --git a/helm/pcp-tgu-ui-service/Chart.yaml b/helm/pcp-tgu-ui-service/Chart.yaml new file mode 100644 index 0000000..ecdff64 --- /dev/null +++ b/helm/pcp-tgu-ui-service/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: pcp-tgu-ui-service +description: Helm chart for deploying pcp-tgu-ui-service (статический фронт на nginx) from GitLab CI/CD. +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/helm/pcp-tgu-ui-service/templates/_helpers.tpl b/helm/pcp-tgu-ui-service/templates/_helpers.tpl new file mode 100644 index 0000000..bfbdc73 --- /dev/null +++ b/helm/pcp-tgu-ui-service/templates/_helpers.tpl @@ -0,0 +1,18 @@ +{{- define "pcp-tgu-ui-service.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "pcp-tgu-ui-service.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- include "pcp-tgu-ui-service.name" . | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + +{{- define "pcp-tgu-ui-service.labels" -}} +app.kubernetes.io/name: {{ include "pcp-tgu-ui-service.name" . }} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/helm/pcp-tgu-ui-service/templates/deployment.yaml b/helm/pcp-tgu-ui-service/templates/deployment.yaml new file mode 100644 index 0000000..9da55cb --- /dev/null +++ b/helm/pcp-tgu-ui-service/templates/deployment.yaml @@ -0,0 +1,75 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "pcp-tgu-ui-service.fullname" . }} + labels: + {{- include "pcp-tgu-ui-service.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "pcp-tgu-ui-service.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + {{- include "pcp-tgu-ui-service.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.image.pullSecrets }} + imagePullSecrets: + {{- range . }} + - name: {{ . }} + {{- end }} + {{- end }} + containers: + - name: {{ include "pcp-tgu-ui-service.name" . }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + # APP_* читаются entrypoint'ом и попадают в /config.js → window.__NSTART_APP_ENV__. + env: + - name: APP_API_URL + value: {{ .Values.app.apiUrl | quote }} + - name: APP_AUTH_MODE + value: {{ .Values.app.authMode | quote }} + {{- if .Values.app.newStartIdUrl }} + - name: APP_NEW_START_ID_URL + value: {{ .Values.app.newStartIdUrl | quote }} + {{- end }} + {{- if .Values.app.newStartIdRealm }} + - name: APP_NEW_START_ID_REALM + value: {{ .Values.app.newStartIdRealm | quote }} + {{- end }} + {{- if .Values.app.newStartIdClientId }} + - name: APP_NEW_START_ID_CLIENT_ID + value: {{ .Values.app.newStartIdClientId | quote }} + {{- end }} + {{- with .Values.extraEnv }} + {{- toYaml . | nindent 12 }} + {{- end }} + readinessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 5 + periodSeconds: 15 + timeoutSeconds: 5 + livenessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 10 + periodSeconds: 20 + timeoutSeconds: 5 + resources: + {{- toYaml .Values.resources | nindent 12 }} diff --git a/helm/pcp-tgu-ui-service/templates/ingress.yaml b/helm/pcp-tgu-ui-service/templates/ingress.yaml new file mode 100644 index 0000000..c77dcf5 --- /dev/null +++ b/helm/pcp-tgu-ui-service/templates/ingress.yaml @@ -0,0 +1,31 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "pcp-tgu-ui-service.fullname" . }} + labels: + {{- include "pcp-tgu-ui-service.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className | quote }} + {{- end }} + {{- with .Values.ingress.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + - host: {{ .Values.ingress.host | quote }} + http: + paths: + - path: {{ .Values.ingress.path | quote }} + pathType: {{ .Values.ingress.pathType }} + backend: + service: + name: {{ include "pcp-tgu-ui-service.fullname" . }} + port: + number: {{ .Values.service.port }} +{{- end }} diff --git a/helm/pcp-tgu-ui-service/templates/service.yaml b/helm/pcp-tgu-ui-service/templates/service.yaml new file mode 100644 index 0000000..d12681d --- /dev/null +++ b/helm/pcp-tgu-ui-service/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "pcp-tgu-ui-service.fullname" . }} + labels: + {{- include "pcp-tgu-ui-service.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + app.kubernetes.io/name: {{ include "pcp-tgu-ui-service.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP diff --git a/helm/pcp-tgu-ui-service/values-dev.yaml b/helm/pcp-tgu-ui-service/values-dev.yaml new file mode 100644 index 0000000..5f57671 --- /dev/null +++ b/helm/pcp-tgu-ui-service/values-dev.yaml @@ -0,0 +1,10 @@ +app: + apiUrl: "/api" + authMode: "anonymous" + +service: + port: 8081 + +ingress: + enabled: true + host: pcp-tgu-ui-service.dev.k8s.264.nstart.cloud diff --git a/helm/pcp-tgu-ui-service/values-master.yaml b/helm/pcp-tgu-ui-service/values-master.yaml new file mode 100644 index 0000000..9b40bfd --- /dev/null +++ b/helm/pcp-tgu-ui-service/values-master.yaml @@ -0,0 +1,10 @@ +app: + apiUrl: "/api" + authMode: "anonymous" + +service: + port: 8081 + +ingress: + enabled: true + host: pcp-tgu-ui-service.master.k8s.264.nstart.cloud diff --git a/helm/pcp-tgu-ui-service/values.yaml b/helm/pcp-tgu-ui-service/values.yaml new file mode 100644 index 0000000..befc187 --- /dev/null +++ b/helm/pcp-tgu-ui-service/values.yaml @@ -0,0 +1,40 @@ +replicaCount: 1 + +image: + repository: registry.example.com/pcp/pcp-tgu-ui-service + tag: latest + pullPolicy: IfNotPresent + pullSecrets: [] + +service: + type: ClusterIP + # Порт nginx из Dockerfile (EXPOSE 8081, non-root). + port: 8081 + +# Runtime-конфиг фронта: docker-entrypoint.d/20-nstart-runtime-config.sh генерит +# /config.js из этих APP_*-переменных (см. src/config/env.ts). Темы нет намеренно. +app: + apiUrl: "/api" + authMode: "anonymous" + newStartIdUrl: "" + newStartIdRealm: "" + newStartIdClientId: "pcp-tgu-ui-service" + +ingress: + enabled: false + className: "" + annotations: {} + host: "" + path: / + pathType: Prefix + tls: [] + +extraEnv: [] + +resources: {} + +podAnnotations: {} +podLabels: {} + +nameOverride: "" +fullnameOverride: ""