Update CICD

This commit is contained in:
M1 AIR
2026-01-13 10:46:55 +07:00
parent 2f22182605
commit 64fe845128
+20 -18
View File
@@ -6,31 +6,31 @@ stages:
default: default:
tags: tags:
- self-hosted-stg - self-hosted-prod
workflow: workflow:
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "production"'
when: always when: always
- when: never - when: never
variables: variables:
DOCKER_BUILDKIT: "1" DOCKER_BUILDKIT: "1"
IMAGE_TAG: "staging_${CI_COMMIT_SHORT_SHA}" IMAGE_TAG: "production_${CI_COMMIT_SHORT_SHA}"
IMAGE_NAME: "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}" IMAGE_NAME: "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
IMAGE_LATEST: "${CI_REGISTRY_IMAGE}:staging_latest" IMAGE_LATEST: "${CI_REGISTRY_IMAGE}:production_latest"
DEPLOY_DIR: "/opt/deploy/stg-lti-api" DEPLOY_DIR: "/opt/deploy/lti"
COMPOSE_FILE: "docker-compose.yaml" COMPOSE_FILE: "docker-compose.yaml"
# ========================= # =========================
# BUILD (AUTO) # BUILD (AUTO)
# ========================= # =========================
build_staging: build_production:
stage: build stage: build
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "production"'
script: | script: |
set -e set -e
docker info docker info
@@ -51,16 +51,16 @@ build_staging:
# ========================= # =========================
# MIGRATE (AUTO) # MIGRATE (AUTO)
# ========================= # =========================
migrate_staging: migrate_production:
stage: migrate stage: migrate
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "production"'
needs: needs:
- job: build_staging - job: build_production
artifacts: false artifacts: false
script: | script: |
set -e set -e
echo "✅ Running migrations (staging) ..." echo "✅ Running migrations (production) ..."
cd "$DEPLOY_DIR" cd "$DEPLOY_DIR"
test -f "$COMPOSE_FILE" || (echo "❌ $COMPOSE_FILE not found in $DEPLOY_DIR" && exit 1) test -f "$COMPOSE_FILE" || (echo "❌ $COMPOSE_FILE not found in $DEPLOY_DIR" && exit 1)
@@ -128,14 +128,14 @@ migrate_staging:
# ========================= # =========================
# DEPLOY (AUTO) # DEPLOY (AUTO)
# ========================= # =========================
deploy_staging: deploy_production:
stage: deploy stage: deploy
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "production"'
needs: needs:
- job: migrate_staging - job: migrate_production
artifacts: false artifacts: false
- job: build_staging - job: build_production
artifacts: false artifacts: false
script: | script: |
set -e set -e
@@ -154,12 +154,12 @@ deploy_staging:
# ========================= # =========================
# SEED (MANUAL) # SEED (MANUAL)
# ========================= # =========================
seed_staging: seed_production:
stage: seed stage: seed
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "production"'
needs: needs:
- job: deploy_staging - job: deploy_production
artifacts: false artifacts: false
when: manual when: manual
allow_failure: false allow_failure: false
@@ -171,3 +171,5 @@ seed_staging:
docker compose -f "$COMPOSE_FILE" pull seed || true docker compose -f "$COMPOSE_FILE" pull seed || true
docker compose -f "$COMPOSE_FILE" run --rm seed docker compose -f "$COMPOSE_FILE" run --rm seed