|
| 1 | +# ============================================================================= |
| 2 | +# Dynamic Pipeline — Registry-Driven Flyway Deployments |
| 3 | +# ============================================================================= |
| 4 | +# Uses generate_pipeline.py to query a SQL Server registry database, |
| 5 | +# discover target databases, and produce a child pipeline with one |
| 6 | +# Flyway migrate job per target. |
| 7 | +# |
| 8 | +# CI/CD Variables required (Settings → CI/CD → Variables): |
| 9 | +# REGISTRY_SERVER = SQL Server hostname for the registry DB |
| 10 | +# REGISTRY_USER = Login for the registry DB |
| 11 | +# REGISTRY_PASSWORD = *** (Protected + Masked) |
| 12 | +# TARGET_DATABASE_USER = Login for target databases |
| 13 | +# TARGET_DATABASE_PASSWORD = *** (Protected + Masked) |
| 14 | +# FLYWAY_EMAIL = your@email.com |
| 15 | +# FLYWAY_TOKEN = *** (Protected + Masked) |
| 16 | +# |
| 17 | +# Optional CI/CD Variables: |
| 18 | +# REGISTRY_DATABASE = flyway_registry (default) |
| 19 | +# REGISTRY_PORT = 1433 (default) |
| 20 | +# JDBC_PORT = 1433 (default) |
| 21 | +# FILTER_LOCATION = all (default — or e.g. "London") |
| 22 | +# INCLUDE_REPLICAS = false (default) |
| 23 | +# FLYWAY_LOCATIONS = filesystem:./migrations (default) |
| 24 | +# RUNNER_TAG_MAP = JSON map of location → runner tag overrides |
| 25 | +# |
| 26 | +# Consumer repo structure: |
| 27 | +# my-flyway-project/ |
| 28 | +# ├── migrations/ |
| 29 | +# │ ├── V1__create_schema.sql |
| 30 | +# │ └── V2__add_users_table.sql |
| 31 | +# └── .gitlab-ci.yml ← this file |
| 32 | +# |
| 33 | +# Optional CI/CD Variables for template repo override: |
| 34 | +# TEMPLATE_PROJECT = root/templatized-with-parser (default) |
| 35 | +# TEMPLATE_REF = main (default) |
| 36 | +# ============================================================================= |
| 37 | + |
| 38 | +stages: |
| 39 | + - generate |
| 40 | + - deploy |
| 41 | + |
| 42 | +variables: |
| 43 | + TEMPLATE_PROJECT: "root/templatized-with-parser" |
| 44 | + TEMPLATE_REF: "main" |
| 45 | + |
| 46 | +# --------------------------------------------------------------------------- |
| 47 | +# Stage 1: Generate the child pipeline YAML from the registry |
| 48 | +# --------------------------------------------------------------------------- |
| 49 | +generate-pipeline: |
| 50 | + stage: generate |
| 51 | + image: python:3.12-slim |
| 52 | + script: |
| 53 | + - apt-get update -qq && apt-get install -y -qq git > /dev/null |
| 54 | + - git clone --depth 1 --branch "$TEMPLATE_REF" |
| 55 | + "http://gitlab-ci-token:${CI_JOB_TOKEN}@172.30.0.2/${TEMPLATE_PROJECT}.git" |
| 56 | + /tmp/templates |
| 57 | + - pip install --quiet -r /tmp/templates/scripts/requirements.txt |
| 58 | + - python /tmp/templates/scripts/generate_pipeline.py |
| 59 | + artifacts: |
| 60 | + paths: |
| 61 | + - dynamic-pipeline.yml |
| 62 | + expire_in: 1 hour |
| 63 | + rules: |
| 64 | + - if: $CI_COMMIT_BRANCH == "main" |
| 65 | + |
| 66 | +# --------------------------------------------------------------------------- |
| 67 | +# Stage 2: Trigger the generated child pipeline |
| 68 | +# --------------------------------------------------------------------------- |
| 69 | +deploy-targets: |
| 70 | + stage: deploy |
| 71 | + trigger: |
| 72 | + include: |
| 73 | + - artifact: dynamic-pipeline.yml |
| 74 | + job: generate-pipeline |
| 75 | + strategy: depend |
| 76 | + rules: |
| 77 | + - if: $CI_COMMIT_BRANCH == "main" |
0 commit comments