From fdfd891deb51544069f122307d3f15d13a193cab Mon Sep 17 00:00:00 2001 From: balex Date: Tue, 17 Feb 2026 20:48:46 +0100 Subject: [PATCH] feat: add gateway-service, analytics-service, update CI/CD --- .gitlab-ci.yml | 163 ++++++++++++++++++++++++++-- rag-service/{ => docker}/Dockerfile | 8 +- 2 files changed, 158 insertions(+), 13 deletions(-) rename rag-service/{ => docker}/Dockerfile (86%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43dc098..12b9372 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,10 @@ stages: variables: REGISTRY: registry.gitlab.com/$CI_PROJECT_PATH -# ---------- BUILD ---------- +# ══════════════════════════════════════════════════════════ +# BUILD +# ══════════════════════════════════════════════════════════ + build-rag: stage: build image: eclipse-temurin:25-jdk-alpine @@ -22,8 +25,55 @@ build-rag: paths: - rag-service/target/*.jar expire_in: 1h + rules: + - changes: + - rag-service/**/* + - if: $CI_COMMIT_BRANCH == "main" + +build-gateway: + stage: build + image: eclipse-temurin:25-jdk-alpine + cache: + key: "${CI_COMMIT_REF_SLUG}-gateway" + paths: + - gateway-service/.m2/repository + script: + - cd gateway-service + - apk add --no-cache maven + - mvn package -DskipTests -B -Dmaven.repo.local=.m2/repository + artifacts: + paths: + - gateway-service/target/*.jar + expire_in: 1h + rules: + - changes: + - gateway-service/**/* + - if: $CI_COMMIT_BRANCH == "main" + +build-analytics: + stage: build + image: eclipse-temurin:25-jdk-alpine + cache: + key: "${CI_COMMIT_REF_SLUG}-analytics" + paths: + - analytics-service/.m2/repository + script: + - cd analytics-service + - apk add --no-cache maven + - mvn package -DskipTests -B -Dmaven.repo.local=.m2/repository + artifacts: + paths: + - analytics-service/target/*.jar + expire_in: 1h + rules: + - changes: + - analytics-service/**/* + - if: $CI_COMMIT_BRANCH == "main" + +# ══════════════════════════════════════════════════════════ +# PUBLISH DOCKER IMAGES +# ══════════════════════════════════════════════════════════ -# ---------- PUBLISH DOCKER IMAGE ---------- publish-rag: stage: publish image: docker:27 @@ -34,16 +84,60 @@ publish-rag: before_script: - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin script: - - docker build -t $REGISTRY/rag-service:${CI_COMMIT_SHORT_SHA} -t $REGISTRY/rag-service:latest rag-service/ + - docker build -t $REGISTRY/rag-service:${CI_COMMIT_SHORT_SHA} -t $REGISTRY/rag-service:latest -f rag-service/docker/Dockerfile rag-service/ - docker push $REGISTRY/rag-service:${CI_COMMIT_SHORT_SHA} - docker push $REGISTRY/rag-service:latest needs: [build-rag] + rules: + - changes: + - rag-service/**/* + - if: $CI_COMMIT_BRANCH == "main" -# ---------- DEPLOY TO VPS ---------- -deploy: +publish-gateway: + stage: publish + image: docker:27 + services: + - docker:27-dind + variables: + DOCKER_TLS_CERTDIR: "" + before_script: + - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin + script: + - docker build -t $REGISTRY/gateway-service:${CI_COMMIT_SHORT_SHA} -t $REGISTRY/gateway-service:latest -f gateway-service/docker/Dockerfile gateway-service/ + - docker push $REGISTRY/gateway-service:${CI_COMMIT_SHORT_SHA} + - docker push $REGISTRY/gateway-service:latest + needs: [build-gateway] + rules: + - changes: + - gateway-service/**/* + - if: $CI_COMMIT_BRANCH == "main" + +publish-analytics: + stage: publish + image: docker:27 + services: + - docker:27-dind + variables: + DOCKER_TLS_CERTDIR: "" + before_script: + - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin + script: + - docker build -t $REGISTRY/analytics-service:${CI_COMMIT_SHORT_SHA} -t $REGISTRY/analytics-service:latest -f analytics-service/docker/Dockerfile analytics-service/ + - docker push $REGISTRY/analytics-service:${CI_COMMIT_SHORT_SHA} + - docker push $REGISTRY/analytics-service:latest + needs: [build-analytics] + rules: + - changes: + - analytics-service/**/* + - if: $CI_COMMIT_BRANCH == "main" + +# ══════════════════════════════════════════════════════════ +# DEPLOY TO VPS +# ══════════════════════════════════════════════════════════ + +.deploy_template: &deploy_setup stage: deploy image: alpine:3.20 - needs: [publish-rag] only: - main before_script: @@ -52,6 +146,13 @@ deploy: - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - ssh-keyscan -H $VPS_HOST >> ~/.ssh/known_hosts + environment: + name: production + url: https://balexvic.com + +deploy-rag: + <<: *deploy_setup + needs: [publish-rag] script: - | ssh $VPS_USER@$VPS_HOST << ENDSSH @@ -63,6 +164,50 @@ deploy: docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d rag-service docker image prune -f ENDSSH - environment: - name: production - url: https://balexvic.com \ No newline at end of file + +deploy-gateway: + <<: *deploy_setup + needs: [publish-gateway] + script: + - | + ssh $VPS_USER@$VPS_HOST << ENDSSH + set -e + echo "$CI_REGISTRY_PASSWORD" | docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin + cd /opt/services + export CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA} + docker compose -f docker-compose.yml -f docker-compose.prod.yml pull gateway-service + docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d gateway-service + docker image prune -f + ENDSSH + +deploy-analytics: + <<: *deploy_setup + needs: [publish-analytics] + script: + - | + ssh $VPS_USER@$VPS_HOST << ENDSSH + set -e + echo "$CI_REGISTRY_PASSWORD" | docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin + cd /opt/services + export CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA} + docker compose -f docker-compose.yml -f docker-compose.prod.yml pull analytics-service + docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d analytics-service + docker image prune -f + ENDSSH + +# Deploy all services at once (manual trigger) +deploy-all: + <<: *deploy_setup + needs: [publish-rag, publish-gateway, publish-analytics] + when: manual + script: + - | + ssh $VPS_USER@$VPS_HOST << ENDSSH + set -e + echo "$CI_REGISTRY_PASSWORD" | docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin + cd /opt/services + export CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA} + docker compose -f docker-compose.yml -f docker-compose.prod.yml pull + docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d + docker image prune -f + ENDSSH diff --git a/rag-service/Dockerfile b/rag-service/docker/Dockerfile similarity index 86% rename from rag-service/Dockerfile rename to rag-service/docker/Dockerfile index 4e7fbe5..e78f9ab 100644 --- a/rag-service/Dockerfile +++ b/rag-service/docker/Dockerfile @@ -1,11 +1,11 @@ # Stage 1: Build FROM eclipse-temurin:25-jdk-alpine AS build WORKDIR /app -COPY pom.xml . -COPY .mvn .mvn -COPY mvnw . +COPY ../pom.xml . +COPY ../.mvn .mvn +COPY ../mvnw . RUN chmod +x mvnw && ./mvnw dependency:go-offline -B -COPY src src +COPY ../src src RUN ./mvnw package -DskipTests -B # Stage 2: Run