|
1 | | -# Shared template for dynamic pipeline generation from the jdbc_table_store registry. |
2 | | -# Include this alongside flyway.yml to get the .generate_targets base job. |
| 1 | +# Shared templates for dynamic pipeline generation from the jdbc_table_store registry. |
| 2 | +# |
| 3 | +# Two job templates are provided to keep concerns separate: |
| 4 | +# |
| 5 | +# .fetch_targets -- queries the registry DB, writes targets.json artifact |
| 6 | +# .generate_pipeline -- reads targets.json, writes dynamic-pipeline.yml artifact |
| 7 | +# |
| 8 | +# Usage in your pipeline file: |
3 | 9 | # |
4 | | -# Usage: |
5 | 10 | # include: |
6 | | -# - local: '.gitlab/ci/flyway.yml' |
7 | | -# - local: '.gitlab/ci/generate.yml' |
| 11 | +# - local: ".gitlab/ci/flyway.yml" |
| 12 | +# - local: ".gitlab/ci/generate.yml" |
| 13 | +# |
| 14 | +# stages: [fetch, generate, deploy] |
8 | 15 | # |
9 | | -# Then extend .generate_targets and set: |
10 | | -# FILTER_LOCATION: 'London' | 'New York' | 'Tokyo' | 'all' |
11 | | -# OUTPUT_FILE: name of the generated YAML artifact |
| 16 | +# fetch:my-region: |
| 17 | +# extends: .fetch_targets |
| 18 | +# variables: |
| 19 | +# FILTER_LOCATION: "London" # or "New York" / "Tokyo" / "all" |
| 20 | +# |
| 21 | +# generate:my-region: |
| 22 | +# extends: .generate_pipeline |
| 23 | +# needs: |
| 24 | +# - job: fetch:my-region |
| 25 | +# artifacts: true |
| 26 | +# |
| 27 | +# deploy:my-region: |
| 28 | +# stage: deploy |
| 29 | +# trigger: |
| 30 | +# include: |
| 31 | +# - artifact: dynamic-pipeline.yml |
| 32 | +# job: generate:my-region |
| 33 | +# strategy: depend |
12 | 34 |
|
13 | 35 | # --------------------------------------------------------------------------- |
14 | | -# Base job: generates the child pipeline YAML from the registry database. |
15 | | -# Extend this job and override FILTER_LOCATION + OUTPUT_FILE as needed. |
| 36 | +# Stage 1 fetch |
| 37 | +# Queries the registry stored procedure and writes targets.json. |
16 | 38 | # --------------------------------------------------------------------------- |
17 | | -.generate_targets: |
18 | | - stage: generate |
| 39 | +.fetch_targets: |
| 40 | + stage: fetch |
19 | 41 | image: python:3.11-slim |
20 | 42 | before_script: |
21 | 43 | - pip install --quiet -r scripts/requirements.txt |
22 | 44 | script: |
23 | | - - echo "Generating pipeline for location: ${FILTER_LOCATION}" |
24 | | - - python scripts/generate_pipeline.py |
25 | | - - echo "--- Preview of generated pipeline ---" |
26 | | - - cat "${OUTPUT_FILE}" |
| 45 | + - echo "Fetching targets for location: ${FILTER_LOCATION}" |
| 46 | + - python scripts/fetch_targets.py |
| 47 | + - echo "--- targets.json ---" |
| 48 | + - cat targets.json |
27 | 49 | variables: |
28 | 50 | # ------------------------------------------------------------------------- |
29 | 51 | # Registry database connection |
30 | 52 | # Set REGISTRY_SERVER, REGISTRY_USER, REGISTRY_PASSWORD in |
31 | | - # GitLab Settings → CI/CD → Variables (mark password as Protected + Masked) |
| 53 | + # GitLab Settings -> CI/CD -> Variables (password: Protected + Masked) |
32 | 54 | # ------------------------------------------------------------------------- |
33 | | - REGISTRY_DATABASE: "flyway_registry" |
34 | | - REGISTRY_PORT: "1433" |
| 55 | + REGISTRY_DATABASE: "flyway_registry" |
| 56 | + REGISTRY_PORT: "1433" |
| 57 | + SQL_SERVER_PORT: "1433" |
| 58 | + INCLUDE_REPLICAS: "1" |
| 59 | + OUTPUT_FILE: "targets.json" |
35 | 60 |
|
36 | | - # ------------------------------------------------------------------------- |
37 | | - # Regional runner tags |
38 | | - # Override in GitLab Variables or at the top of your pipeline file |
39 | | - # to match the tag names configured on your actual GitLab runners. |
40 | | - # ------------------------------------------------------------------------- |
41 | | - RUNNER_TAG_LONDON: "runner-london" |
42 | | - RUNNER_TAG_NEW_YORK: "runner-new-york" |
43 | | - RUNNER_TAG_TOKYO: "runner-tokyo" |
| 61 | + # Subclasses must set this: |
| 62 | + # FILTER_LOCATION: all | London | New York | Tokyo |
| 63 | + artifacts: |
| 64 | + paths: |
| 65 | + - targets.json |
| 66 | + expire_in: never # keep so it can be reused across pipeline runs |
| 67 | + rules: |
| 68 | + - when: always |
| 69 | + |
| 70 | + |
| 71 | +# --------------------------------------------------------------------------- |
| 72 | +# Stage 2 generate |
| 73 | +# Reads targets.json and produces dynamic-pipeline.yml. |
| 74 | +# No database connection required. |
| 75 | +# --------------------------------------------------------------------------- |
| 76 | +.generate_pipeline: |
| 77 | + stage: generate |
| 78 | + image: python:3.11-slim |
| 79 | + before_script: |
| 80 | + - pip install --quiet -r scripts/requirements.txt |
| 81 | + script: |
| 82 | + - echo "Generating dynamic-pipeline.yml from targets.json" |
| 83 | + - python scripts/generate_pipeline.py |
| 84 | + - echo "--- dynamic-pipeline.yml ---" |
| 85 | + - cat dynamic-pipeline.yml |
| 86 | + variables: |
| 87 | + FLYWAY_LOCATIONS: "filesystem:./sql" |
| 88 | + TARGETS_FILE: "targets.json" |
| 89 | + OUTPUT_FILE: "dynamic-pipeline.yml" |
44 | 90 |
|
45 | 91 | # ------------------------------------------------------------------------- |
46 | | - # Target database defaults |
47 | | - # Credentials are resolved at runtime from GitLab CI/CD variables |
| 92 | + # Regional runner tags |
| 93 | + # Override to match the tag names on your actual GitLab runners. |
48 | 94 | # ------------------------------------------------------------------------- |
49 | | - SQL_SERVER_PORT: "1433" |
50 | | - FLYWAY_LOCATIONS: "filesystem:./sql" |
51 | | - INCLUDE_REPLICAS: "1" |
52 | | - |
53 | | - # Subclasses must set these: |
54 | | - # FILTER_LOCATION: all | London | New York | Tokyo |
55 | | - # OUTPUT_FILE: generated-<name>.yml |
| 95 | + RUNNER_TAG_LONDON: "runner-london" |
| 96 | + RUNNER_TAG_NEW_YORK: "runner-new-york" |
| 97 | + RUNNER_TAG_TOKYO: "runner-tokyo" |
56 | 98 | artifacts: |
57 | 99 | paths: |
58 | | - - "*.yml" # capture generated-*.yml files |
| 100 | + - dynamic-pipeline.yml |
59 | 101 | expire_in: 2 hours |
60 | 102 | rules: |
61 | 103 | - when: always |
0 commit comments