Skip to content

Commit ce92762

Browse files
work in progress templatized. current python builds out the pipeline
1 parent b13f742 commit ce92762

21 files changed

Lines changed: 3019 additions & 127 deletions

Gitlab-Templatized/.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# .gitignore for GitLab Flyway Pipeline Project
2+
3+
# Active pipeline file (users create this by copying an example)
4+
# Uncomment the line below if you want to keep .gitlab-ci.yml local
5+
# and not commit it to the repository
6+
#.gitlab-ci.yml
7+
8+
# User-specific SQL migrations (optional - comment out if you want to track them)
9+
# sql/*.sql
10+
11+
# Flyway metadata
12+
flyway.conf
13+
14+
# Environment files (if used)
15+
.env
16+
.env.local
17+
*.env
18+
19+
# IDE and Editor files
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
.DS_Store
26+
27+
# OS specific files
28+
Thumbs.db
29+
Desktop.ini
30+
31+
# Build artifacts
32+
dist/
33+
build/
34+
*.log
35+
36+
# Temporary files
37+
tmp/
38+
temp/
39+
*.tmp
40+
41+
# Personal notes (users might create these)
42+
notes.md
43+
TODO.md
44+
scratch.txt
45+
46+
# Backup files
47+
*.bak
48+
*.backup
49+
50+
# GitLab Runner specific
51+
.gitlab-runner/
52+
53+
# Docker volumes (if testing locally)
54+
gitlab-config/
55+
gitlab-logs/
56+
gitlab-data/
57+
rancher-data/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# =============================================================================
2+
# Pipeline: Deploy ALL regions at once (London + New York + Tokyo)
3+
# =============================================================================
4+
# This pipeline queries the jdbc_table_store registry and generates
5+
# a single child pipeline containing jobs for EVERY available database across
6+
# all three regions. Each job is automatically tagged to run on the runner
7+
# serving that region.
8+
#
9+
# SETUP REQUIRED – GitLab Settings → CI/CD → Variables
10+
# -------------------------------------------------------
11+
# Registry database (used by the Python generator):
12+
# REGISTRY_SERVER = <hostname of your flyway_registry SQL Server>
13+
# REGISTRY_USER = <login on that server>
14+
# REGISTRY_PASSWORD = <password> ← Protected + Masked
15+
#
16+
# Target databases (used by Flyway jobs at runtime):
17+
# TARGET_DATABASE_USER = flyway_user
18+
# TARGET_DATABASE_PASSWORD = <password> ← Protected + Masked
19+
#
20+
# RUNNER TAGS – change these to match your actual runner tag names
21+
# The defaults below follow the convention set in .gitlab/ci/generate.yml
22+
# =============================================================================
23+
24+
include:
25+
- local: '.gitlab/ci/generate.yml' # .generate_targets base job
26+
- local: '.gitlab/ci/flyway.yml' # Flyway templates (used by child pipeline)
27+
28+
stages:
29+
- generate
30+
- deploy
31+
32+
# ---------------------------------------------------------------------------
33+
# Configurable runner tags
34+
# Change these values to match the tags registered on your GitLab runners.
35+
# One-line change per region – that's all you need.
36+
# ---------------------------------------------------------------------------
37+
variables:
38+
RUNNER_TAG_LONDON: "runner-london"
39+
RUNNER_TAG_NEW_YORK: "runner-new-york"
40+
RUNNER_TAG_TOKYO: "runner-tokyo"
41+
42+
# Registry connection (set sensitive values in GitLab CI/CD Variables)
43+
REGISTRY_DATABASE: "flyway_registry"
44+
REGISTRY_PORT: "1433"
45+
SQL_SERVER_PORT: "1433"
46+
47+
# Set to "0" to target primary databases only (skip replicas)
48+
INCLUDE_REPLICAS: "1"
49+
50+
# ---------------------------------------------------------------------------
51+
# Stage 1 – generate: build the child pipeline YAML from the registry
52+
# ---------------------------------------------------------------------------
53+
generate:all-regions:
54+
extends: .generate_targets
55+
stage: generate
56+
variables:
57+
FILTER_LOCATION: "all"
58+
OUTPUT_FILE: "generated-all-regions.yml"
59+
artifacts:
60+
paths:
61+
- generated-all-regions.yml
62+
expire_in: 2 hours
63+
only:
64+
- main
65+
- tags
66+
67+
# ---------------------------------------------------------------------------
68+
# Stage 2 – deploy: trigger the generated child pipeline
69+
# strategy: depend → parent waits for all child jobs to finish
70+
# ---------------------------------------------------------------------------
71+
deploy:all-regions:
72+
stage: deploy
73+
trigger:
74+
include:
75+
- artifact: generated-all-regions.yml
76+
job: generate:all-regions
77+
strategy: depend
78+
only:
79+
- main
80+
- tags

Gitlab-Templatized/.gitlab-ci-example-dev.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Example Pipeline 1: Development Environment
22
# This pipeline validates and deploys migrations to the DEV database
3+
#
4+
# SETUP REQUIRED:
5+
# Configure these CI/CD variables in GitLab (Settings → CI/CD → Variables):
6+
# - TARGET_DATABASE_JDBC = jdbc:postgresql://dev-db.example.com:5432/myapp_dev
7+
# - TARGET_DATABASE_USER = flyway_user
8+
# - TARGET_DATABASE_PASSWORD = your-password (mark as Protected and Masked)
39

410
include:
511
- local: '.gitlab/ci/flyway.yml'
@@ -8,10 +14,7 @@ stages:
814
- validate
915
- deploy
1016

11-
variables:
12-
DB_URL: "jdbc:postgresql://dev-db.example.com:5432/myapp_dev"
13-
DB_USER: "flyway_user"
14-
# DB_PASSWORD should be set as a CI/CD variable in GitLab UI
17+
# No additional variables needed - uses TARGET_DATABASE_* from GitLab CI/CD settings
1518

1619
# Validate migrations on every commit
1720
validate:dev:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Example Pipeline 4: Matrix-Based Multi-Database Deployment
2+
# This pipeline uses GitLab's parallel:matrix feature to deploy to N databases
3+
# Best for: 10-100 databases where explicit jobs become impractical
4+
#
5+
# SETUP REQUIRED:
6+
# Configure numbered CI/CD variables in GitLab (Settings → CI/CD → Variables):
7+
# - TARGET_DATABASE_JDBC_1 through TARGET_DATABASE_JDBC_N
8+
# - TARGET_DATABASE_USER_1 through TARGET_DATABASE_USER_N
9+
# - TARGET_DATABASE_PASSWORD_1 through TARGET_DATABASE_PASSWORD_N
10+
#
11+
# Example for 50 databases:
12+
# TARGET_DATABASE_JDBC_1 = jdbc:postgresql://tenant1-db:5432/app
13+
# TARGET_DATABASE_USER_1 = flyway
14+
# TARGET_DATABASE_PASSWORD_1 = secret1
15+
# ...
16+
# TARGET_DATABASE_JDBC_50 = jdbc:postgresql://tenant50-db:5432/app
17+
# TARGET_DATABASE_USER_50 = flyway
18+
# TARGET_DATABASE_PASSWORD_50 = secret50
19+
20+
include:
21+
- local: '.gitlab/ci/flyway.yml'
22+
23+
stages:
24+
- validate
25+
- deploy
26+
27+
# Validate once using first database
28+
validate:matrix:
29+
extends: .flyway_validate
30+
stage: validate
31+
variables:
32+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_1}"
33+
FLYWAY_USER: "${TARGET_DATABASE_USER_1}"
34+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_1}"
35+
36+
# Deploy to N databases in parallel
37+
# Update the DB_NUMBER list to match your database count
38+
migrate:all-databases:
39+
extends: .flyway_migrate
40+
stage: deploy
41+
parallel:
42+
matrix:
43+
- DB_NUMBER: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
44+
# Add more numbers as needed: "11", "12", ..., "100"
45+
variables:
46+
# GitLab will create separate jobs for each DB_NUMBER
47+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_${DB_NUMBER}}"
48+
FLYWAY_USER: "${TARGET_DATABASE_USER_${DB_NUMBER}}"
49+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_${DB_NUMBER}}"
50+
only:
51+
- main
52+
environment:
53+
name: database-${DB_NUMBER}
54+
# Optional: Control parallelism to avoid overwhelming database servers
55+
# Maximum 50 jobs run concurrently by default
56+
57+
# Alternative: Named databases instead of numbered
58+
# Uncomment and modify if you prefer named databases like "users", "orders", etc.
59+
#
60+
# migrate:named-databases:
61+
# extends: .flyway_migrate
62+
# stage: deploy
63+
# parallel:
64+
# matrix:
65+
# - DB_NAME: ["users", "orders", "products", "analytics", "reports"]
66+
# variables:
67+
# FLYWAY_URL: "${TARGET_DATABASE_JDBC_${DB_NAME}}"
68+
# FLYWAY_USER: "${TARGET_DATABASE_USER_${DB_NAME}}"
69+
# FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_${DB_NAME}}"
70+
# environment:
71+
# name: database-${DB_NAME}
72+
73+
# Note: For 100+ databases, consider using dynamic child pipelines
74+
# See SETUP_GUIDE.md "Scenario 3: Deploy to 100+ Databases"
Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
1-
# Example Pipeline 3: Multi-Database Deployment
2-
# This pipeline deploys to multiple databases using the same shared template
1+
# Example Pipeline 3: Multi-Database Deployment (Explicit Jobs)
2+
# This pipeline deploys to multiple databases using shared templates
3+
# Best for: 2-10 databases that you want to deploy explicitly
4+
#
5+
# SETUP REQUIRED:
6+
# Configure these CI/CD variables in GitLab (Settings → CI/CD → Variables):
7+
# Database 1:
8+
# - TARGET_DATABASE_JDBC_1 = jdbc:postgresql://db1.example.com:5432/users_db
9+
# - TARGET_DATABASE_USER_1 = flyway_user
10+
# - TARGET_DATABASE_PASSWORD_1 = password1
11+
# Database 2:
12+
# - TARGET_DATABASE_JDBC_2 = jdbc:postgresql://db2.example.com:5432/orders_db
13+
# - TARGET_DATABASE_USER_2 = flyway_user
14+
# - TARGET_DATABASE_PASSWORD_2 = password2
15+
# Database 3:
16+
# - TARGET_DATABASE_JDBC_3 = jdbc:postgresql://db3.example.com:5432/analytics_db
17+
# - TARGET_DATABASE_USER_3 = flyway_user
18+
# - TARGET_DATABASE_PASSWORD_3 = password3
319

420
include:
521
- local: '.gitlab/ci/flyway.yml'
622

723
stages:
824
- validate
9-
- deploy-db1
10-
- deploy-db2
11-
- deploy-db3
25+
- deploy
1226

13-
# Validate all migrations
27+
# Validate all migrations once (using default variables or DB1)
1428
validate:all:
1529
extends: .flyway_validate
1630
stage: validate
31+
variables:
32+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_1}"
33+
FLYWAY_USER: "${TARGET_DATABASE_USER_1}"
34+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_1}"
1735

1836
# Database 1: Users DB
1937
migrate:users-db:
2038
extends: .flyway_migrate
21-
stage: deploy-db1
39+
stage: deploy
2240
variables:
23-
FLYWAY_URL: "${DB_URL_USERS}"
24-
FLYWAY_LOCATIONS: "filesystem:./sql/users"
41+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_1}"
42+
FLYWAY_USER: "${TARGET_DATABASE_USER_1}"
43+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_1}"
44+
# Optional: Use separate SQL folder for this database
45+
# FLYWAY_LOCATIONS: "filesystem:./sql/users"
2546
only:
2647
- main
2748
environment:
@@ -30,10 +51,12 @@ migrate:users-db:
3051
# Database 2: Orders DB
3152
migrate:orders-db:
3253
extends: .flyway_migrate
33-
stage: deploy-db2
54+
stage: deploy
3455
variables:
35-
FLYWAY_URL: "${DB_URL_ORDERS}"
36-
FLYWAY_LOCATIONS: "filesystem:./sql/orders"
56+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_2}"
57+
FLYWAY_USER: "${TARGET_DATABASE_USER_2}"
58+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_2}"
59+
# FLYWAY_LOCATIONS: "filesystem:./sql/orders"
3760
only:
3861
- main
3962
environment:
@@ -42,12 +65,16 @@ migrate:orders-db:
4265
# Database 3: Analytics DB
4366
migrate:analytics-db:
4467
extends: .flyway_migrate
45-
stage: deploy-db3
68+
stage: deploy
4669
variables:
47-
FLYWAY_URL: "${DB_URL_ANALYTICS}"
48-
FLYWAY_LOCATIONS: "filesystem:./sql/analytics"
70+
FLYWAY_URL: "${TARGET_DATABASE_JDBC_3}"
71+
FLYWAY_USER: "${TARGET_DATABASE_USER_3}"
72+
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_3}"
73+
# FLYWAY_LOCATIONS: "filesystem:./sql/analytics"
4974
only:
5075
- main
5176
environment:
5277
name: analytics-database
53-
when: manual # Analytics can be deployed separately
78+
when: manual # Analytics can be deployed separately if needed
79+
80+
# Add more databases by copying the pattern above and incrementing the number

0 commit comments

Comments
 (0)