268 lines
8.6 KiB
YAML
268 lines
8.6 KiB
YAML
variables:
|
|
GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle"
|
|
|
|
BALLISTICS_SERVICE_DIR: "services/pcp-ballistics-service"
|
|
|
|
# При необходимости переопредели путь к chart через CI/CD variable
|
|
BALLISTICS_HELM_CHART_DIR: "helm/pcp-ballistics-service"
|
|
|
|
# Имя релиза в k8s
|
|
BALLISTICS_HELM_RELEASE: "pcp-ballistics-service"
|
|
|
|
# Полный путь до image во внутреннем registry
|
|
BALLISTICS_IMAGE_REPOSITORY: "$INTERNAL_REGISTRY/pcp-ballistics-service"
|
|
|
|
# Окружения / namespace
|
|
BALLISTICS_K8S_NAMESPACE_DEV: "pcp-dev"
|
|
BALLISTICS_K8S_NAMESPACE_MASTER: "pcp-master"
|
|
|
|
|
|
BALLISTICS_IMAGE_TAG: "$CI_COMMIT_SHORT_SHA"
|
|
.ballistics:changes: &ballistics_changes
|
|
- services/pcp-ballistics-service/**/*
|
|
- libs/ballistics-lib/**/*
|
|
- libs/pcp-types-lib/**/*
|
|
- build.gradle.kts
|
|
- settings.gradle.kts
|
|
- .gitlab/ci/pcp-ballistics-service.*
|
|
- helm/pcp-ballistics-service/**/*
|
|
- deploy/**/*
|
|
|
|
.ballistics:rules:build-and-image:
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
changes: *ballistics_changes
|
|
- if: '$CI_COMMIT_BRANCH == "dev"'
|
|
changes: *ballistics_changes
|
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
|
changes: *ballistics_changes
|
|
- when: never
|
|
|
|
.ballistics:rules:test:
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
changes: *ballistics_changes
|
|
- if: '$CI_COMMIT_BRANCH == "dev"'
|
|
changes: *ballistics_changes
|
|
when: manual
|
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
|
changes: *ballistics_changes
|
|
- when: never
|
|
|
|
.ballistics:rules:deploy-dev:
|
|
rules:
|
|
- if: '$CI_COMMIT_BRANCH == "dev"'
|
|
changes: *ballistics_changes
|
|
when: manual
|
|
- when: never
|
|
|
|
.ballistics:rules:deploy-master:
|
|
rules:
|
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
|
changes: *ballistics_changes
|
|
when: manual
|
|
- when: never
|
|
|
|
.ballistics:gradle-cache:
|
|
cache:
|
|
key: "gradle-ballistics-$CI_DEFAULT_BRANCH"
|
|
paths:
|
|
- .gradle/wrapper
|
|
- .gradle/caches
|
|
policy: pull-push
|
|
|
|
.ballistics: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
|
|
|
|
.ballistics: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
|
|
|
|
ballistics:test:
|
|
stage: test
|
|
image: repo.nstart.cloud/library/gradle:jdk21-ubi10
|
|
services:
|
|
- name: repo.nstart.cloud/postgis/postgis:16-3.4
|
|
alias: postgres
|
|
variables:
|
|
POSTGRES_DB: "pcp_ballistics"
|
|
POSTGRES_USER: "postgres"
|
|
POSTGRES_PASSWORD: "password"
|
|
SPRING_DATASOURCE_URL: "jdbc:postgresql://postgres:5432/pcp_ballistics"
|
|
SPRING_DATASOURCE_USERNAME: "postgres"
|
|
SPRING_DATASOURCE_PASSWORD: "password"
|
|
extends:
|
|
- .ballistics:rules:test
|
|
- .ballistics:gradle-cache
|
|
before_script:
|
|
- chmod +x gradlew
|
|
script:
|
|
- ./gradlew --no-daemon :services:pcp-ballistics-service:test
|
|
artifacts:
|
|
when: always
|
|
reports:
|
|
junit:
|
|
- services/pcp-ballistics-service/build/test-results/test/*.xml
|
|
paths:
|
|
- services/pcp-ballistics-service/build/reports/tests/
|
|
expire_in: 7 days
|
|
|
|
ballistics:build:
|
|
stage: build
|
|
image: repo.nstart.cloud/library/gradle:jdk21-ubi10
|
|
extends:
|
|
- .ballistics:rules:build-and-image
|
|
- .ballistics:gradle-cache
|
|
needs:
|
|
- job: ballistics:test
|
|
artifacts: true
|
|
before_script:
|
|
- chmod +x gradlew
|
|
script:
|
|
- ./gradlew --no-daemon :services:pcp-ballistics-service:bootJar
|
|
artifacts:
|
|
when: always
|
|
paths:
|
|
- services/pcp-ballistics-service/build/libs/*.jar
|
|
expire_in: 7 days
|
|
|
|
ballistics:package:
|
|
stage: package
|
|
extends:
|
|
- .ballistics:rules:build-and-image
|
|
- .ballistics:docker-build
|
|
needs:
|
|
- job: ballistics:build
|
|
artifacts: true
|
|
script:
|
|
- 'echo "BALLISTICS_IMAGE_REPOSITORY=$BALLISTICS_IMAGE_REPOSITORY"'
|
|
- |
|
|
JAR_COUNT="$(find "$BALLISTICS_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 "$BALLISTICS_SERVICE_DIR/build/libs" -maxdepth 1 -type f -name '*.jar' -print || true
|
|
exit 1
|
|
fi
|
|
|
|
JAR_FILE="$(find "$BALLISTICS_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 "$BALLISTICS_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 "$BALLISTICS_IMAGE_REPOSITORY:$BALLISTICS_IMAGE_TAG" docker-context
|
|
- docker push "$BALLISTICS_IMAGE_REPOSITORY:$BALLISTICS_IMAGE_TAG"
|
|
- printf "BALLISTICS_IMAGE=%s\n" "$BALLISTICS_IMAGE_REPOSITORY:$BALLISTICS_IMAGE_TAG" > ballistics-image.env
|
|
artifacts:
|
|
reports:
|
|
dotenv: ballistics-image.env
|
|
expire_in: 7 days
|
|
|
|
ballistics:deploy:dev:
|
|
stage: deploy
|
|
extends:
|
|
- .ballistics:rules:deploy-dev
|
|
- .ballistics:helm-deploy
|
|
needs:
|
|
- job: ballistics:package
|
|
artifacts: true
|
|
environment:
|
|
name: dev/pcp-ballistics-service
|
|
resource_group: pcp-ballistics-service-dev
|
|
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="${BALLISTICS_IMAGE%:*}"'
|
|
- 'export IMAGE_TAG="${BALLISTICS_IMAGE##*:}"'
|
|
- 'echo "Deploy image: $IMAGE_REPOSITORY:$IMAGE_TAG"'
|
|
- >
|
|
helm upgrade --install "$BALLISTICS_HELM_RELEASE"
|
|
"$BALLISTICS_HELM_CHART_DIR"
|
|
--namespace "$BALLISTICS_K8S_NAMESPACE_DEV"
|
|
--create-namespace
|
|
--wait
|
|
--atomic
|
|
--timeout 10m
|
|
-f "$BALLISTICS_HELM_CHART_DIR/values.yaml"
|
|
-f "$BALLISTICS_HELM_CHART_DIR/values-dev.yaml"
|
|
--set image.repository="$IMAGE_REPOSITORY"
|
|
--set image.tag="$IMAGE_TAG"
|
|
--set app.profile=dev
|
|
--set app.configLabel=dev
|
|
|
|
ballistics:deploy:master:
|
|
stage: deploy
|
|
extends:
|
|
- .ballistics:rules:deploy-master
|
|
- .ballistics:helm-deploy
|
|
needs:
|
|
- job: ballistics:package
|
|
artifacts: true
|
|
environment:
|
|
name: master/pcp-ballistics-service
|
|
resource_group: pcp-ballistics-service-master
|
|
script:
|
|
- |
|
|
if [ -n "${KUBE_CONFIG_MASTER:-}" ]; then
|
|
printf '%s' "$KUBE_CONFIG_MASTER" > /root/.kube/config
|
|
elif [ -n "${KUBE_CONFIG_MASTER_B64:-}" ]; then
|
|
if printf '%s' "$KUBE_CONFIG_MASTER_B64" | grep -qE '(^apiVersion:|^kind: Config|^clusters:)'; then
|
|
printf '%s' "$KUBE_CONFIG_MASTER_B64" > /root/.kube/config
|
|
elif ! printf '%s' "$KUBE_CONFIG_MASTER_B64" | base64 -d > /root/.kube/config; then
|
|
echo "KUBE_CONFIG_MASTER_B64 is not valid base64. Set KUBE_CONFIG_MASTER to raw kubeconfig or KUBE_CONFIG_MASTER_B64 to base64 kubeconfig."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "KUBE_CONFIG_MASTER or KUBE_CONFIG_MASTER_B64 must be set."
|
|
exit 1
|
|
fi
|
|
- chmod 600 /root/.kube/config
|
|
- export KUBECONFIG=/root/.kube/config
|
|
- 'export IMAGE_REPOSITORY="${BALLISTICS_IMAGE%:*}"'
|
|
- 'export IMAGE_TAG="${BALLISTICS_IMAGE##*:}"'
|
|
- 'echo "Deploy image: $IMAGE_REPOSITORY:$IMAGE_TAG"'
|
|
- >
|
|
helm upgrade --install "$BALLISTICS_HELM_RELEASE"
|
|
"$BALLISTICS_HELM_CHART_DIR"
|
|
--namespace "$BALLISTICS_K8S_NAMESPACE_MASTER"
|
|
--create-namespace
|
|
--wait
|
|
--atomic
|
|
--timeout 10m
|
|
-f "$BALLISTICS_HELM_CHART_DIR/values.yaml"
|
|
-f "$BALLISTICS_HELM_CHART_DIR/values-master.yaml"
|
|
--set image.repository="$IMAGE_REPOSITORY"
|
|
--set image.tag="$IMAGE_TAG"
|
|
--set app.profile=master
|
|
--set app.configLabel=master
|