feat: add gateway-service, analytics-service, update CI/CD
This commit is contained in:
163
.gitlab-ci.yml
163
.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
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user