This commit is contained in:
Заид Омар Медхат 2025-12-14 00:08:57 +05:00
parent e6cfbdc1f7
commit 8059d1b0a3
2 changed files with 28 additions and 5 deletions

View File

@ -1,6 +1,28 @@
stages:
- build
- deploy
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
build_and_push:
stage: build
image: docker:29
services:
- name: docker:29-dind
command: ["--tls=false"]
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- docker build --target production -t "$IMAGE_TAG" -t "$IMAGE_TAG_LATEST" .
- docker push "$IMAGE_TAG"
- docker push "$IMAGE_TAG_LATEST"
deploy_production:
stage: deploy
image: alpine:3.20
@ -9,6 +31,8 @@ deploy_production:
url: https://api-finance.ai-assistant-bot.xyz
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
allow_failure: false
before_script:
- apk add --no-cache openssh-client rsync
- mkdir -p ~/.ssh
@ -25,4 +49,6 @@ deploy_production:
--exclude='coverage' \
--exclude='dist' \
./ "$DEPLOY_USER@$DEPLOY_HOST:/opt/apps/api-finance/"
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "cd /opt/apps/api-finance && docker compose -f docker-compose.server.yml up -d --build"
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "docker login -u '$CI_REGISTRY_USER' -p '$CI_REGISTRY_PASSWORD' '$CI_REGISTRY'"
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "cd /opt/apps/api-finance && APP_IMAGE='$IMAGE_TAG' docker compose -f docker-compose.server.yml pull"
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "cd /opt/apps/api-finance && APP_IMAGE='$IMAGE_TAG' docker compose -f docker-compose.server.yml up -d"

View File

@ -21,10 +21,7 @@ services:
restart: unless-stopped
app:
build:
context: .
dockerfile: Dockerfile
target: production
image: ${APP_IMAGE}
container_name: api_finance_app
environment:
NODE_ENV: production