Skip to content

Commit c42dea8

Browse files
gitlab templatized pipeline v1.0
1 parent 963d3c7 commit c42dea8

20 files changed

Lines changed: 1182 additions & 369 deletions

Gitlab-Templatized/.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Local GitLab environment configuration
2+
# These values are for the local Docker-based GitLab instance only.
3+
# Copy this file to .env and fill in your values.
4+
5+
GITLAB_RUNNER_REGISTRATION_TOKEN=your_runner_registration_token
6+
GITLAB_URL=http://172.17.0.2
7+
GITLAB_EXTERNAL_URL=http://localhost:8080
8+
9+
# SQL Server (SQLEXPRESS) — used by Flyway CI/CD variables
10+
# From Docker containers, use host.docker.internal (Rancher Desktop VM)
11+
SQL_HOST=host.docker.internal
12+
SQL_PORT=1433
13+
SQL_USER=sa
14+
SQL_PASSWORD=your_sql_password
15+
16+
# Flyway Enterprise licensing (Personal Access Token)
17+
# See: https://documentation.red-gate.com/fd/licensing-164167730.html#Licensing-AccessToken(PAT)
18+
FLYWAY_EMAIL=your_email@example.com
19+
FLYWAY_TOKEN=your_flyway_personal_access_token

Gitlab-Templatized/.gitignore

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,2 @@
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)
151
.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/
2+
!.env.example

Gitlab-Templatized/.gitlab-ci-example-all-regions.yml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
# =============================================================================
2323

2424
include:
25-
- local: '.gitlab/ci/generate.yml' # .fetch_targets and .generate_pipeline templates
25+
- local: '.gitlab/ci/generate.yml' # .generate_pipeline template
2626
- local: '.gitlab/ci/flyway.yml' # Flyway templates (used by child pipeline)
2727

2828
stages:
29-
- fetch
3029
- generate
3130
- deploy
3231

@@ -43,37 +42,20 @@ variables:
4342
# Registry connection (set sensitive values in GitLab CI/CD Variables)
4443
REGISTRY_DATABASE: "flyway_registry"
4544
REGISTRY_PORT: "1433"
46-
SQL_SERVER_PORT: "1433"
47-
48-
# Set to "0" to target primary databases only (skip replicas)
49-
INCLUDE_REPLICAS: "1"
50-
51-
# ---------------------------------------------------------------------------
52-
# Stage 1 – fetch: query the registry, write targets.json artifact
53-
# ---------------------------------------------------------------------------
54-
fetch:all-regions:
55-
extends: .fetch_targets
56-
variables:
57-
FILTER_LOCATION: "all"
58-
only:
59-
- main
60-
- tags
6145

6246
# ---------------------------------------------------------------------------
63-
# Stage 2 – generate: read targets.json, write dynamic-pipeline.yml artifact
64-
# No database connection required at this stage.
47+
# Stage 1 – generate: query registry, build JDBCs, write dynamic-pipeline.yml
6548
# ---------------------------------------------------------------------------
6649
generate:all-regions:
6750
extends: .generate_pipeline
68-
needs:
69-
- job: fetch:all-regions
70-
artifacts: true
71-
only:
72-
- main
73-
- tags
51+
variables:
52+
FILTER_LOCATION: "all"
53+
rules:
54+
- if: $CI_COMMIT_BRANCH == "main"
55+
- if: $CI_COMMIT_TAG
7456

7557
# ---------------------------------------------------------------------------
76-
# Stage 3 – deploy: trigger the generated child pipeline
58+
# Stage 2 – deploy: trigger the generated child pipeline
7759
# strategy: depend → parent waits for all child jobs to finish
7860
# ---------------------------------------------------------------------------
7961
deploy:all-regions:
@@ -83,6 +65,6 @@ deploy:all-regions:
8365
- artifact: dynamic-pipeline.yml
8466
job: generate:all-regions
8567
strategy: depend
86-
only:
87-
- main
88-
- tags
68+
rules:
69+
- if: $CI_COMMIT_BRANCH == "main"
70+
- if: $CI_COMMIT_TAG

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,34 @@ stages:
2020
validate:dev:
2121
extends: .flyway_validate
2222
stage: validate
23-
only:
24-
- dev
25-
- merge_requests
23+
rules:
24+
- if: $CI_COMMIT_BRANCH == "dev"
25+
- if: $CI_MERGE_REQUEST_IID
2626

2727
# Show migration info
2828
info:dev:
2929
extends: .flyway_info
3030
stage: validate
31-
only:
32-
- dev
33-
- merge_requests
31+
rules:
32+
- if: $CI_COMMIT_BRANCH == "dev"
33+
- if: $CI_MERGE_REQUEST_IID
3434

3535
# Deploy migrations to DEV
3636
migrate:dev:
3737
extends: .flyway_migrate
3838
stage: deploy
39-
only:
40-
- dev
4139
environment:
4240
name: development
4341
url: https://dev.myapp.com
42+
rules:
43+
- if: $CI_COMMIT_BRANCH == "dev"
4444

4545
# Manual repair option
4646
repair:dev:
4747
extends: .flyway_repair
4848
stage: deploy
49-
only:
50-
- dev
5149
environment:
5250
name: development
51+
rules:
52+
- if: $CI_COMMIT_BRANCH == "dev"
53+
when: manual

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ migrate:all-databases:
4747
FLYWAY_URL: "${TARGET_DATABASE_JDBC_${DB_NUMBER}}"
4848
FLYWAY_USER: "${TARGET_DATABASE_USER_${DB_NUMBER}}"
4949
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_${DB_NUMBER}}"
50-
only:
51-
- main
5250
environment:
5351
name: database-${DB_NUMBER}
52+
rules:
53+
- if: $CI_COMMIT_BRANCH == "main"
5454
# Optional: Control parallelism to avoid overwhelming database servers
5555
# Maximum 50 jobs run concurrently by default
5656

Gitlab-Templatized/.gitlab-ci-example-multi-db.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ migrate:users-db:
4141
FLYWAY_URL: "${TARGET_DATABASE_JDBC_1}"
4242
FLYWAY_USER: "${TARGET_DATABASE_USER_1}"
4343
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_1}"
44-
# Optional: Use separate SQL folder for this database
45-
# FLYWAY_LOCATIONS: "filesystem:./sql/users"
46-
only:
47-
- main
44+
# Optional: Use separate migrations folder for this database
45+
# FLYWAY_LOCATIONS: "filesystem:./migrations/users"
4846
environment:
4947
name: users-database
48+
rules:
49+
- if: $CI_COMMIT_BRANCH == "main"
5050

5151
# Database 2: Orders DB
5252
migrate:orders-db:
@@ -56,11 +56,11 @@ migrate:orders-db:
5656
FLYWAY_URL: "${TARGET_DATABASE_JDBC_2}"
5757
FLYWAY_USER: "${TARGET_DATABASE_USER_2}"
5858
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_2}"
59-
# FLYWAY_LOCATIONS: "filesystem:./sql/orders"
60-
only:
61-
- main
59+
# FLYWAY_LOCATIONS: "filesystem:./migrations/orders"
6260
environment:
6361
name: orders-database
62+
rules:
63+
- if: $CI_COMMIT_BRANCH == "main"
6464

6565
# Database 3: Analytics DB
6666
migrate:analytics-db:
@@ -70,11 +70,11 @@ migrate:analytics-db:
7070
FLYWAY_URL: "${TARGET_DATABASE_JDBC_3}"
7171
FLYWAY_USER: "${TARGET_DATABASE_USER_3}"
7272
FLYWAY_PASSWORD: "${TARGET_DATABASE_PASSWORD_3}"
73-
# FLYWAY_LOCATIONS: "filesystem:./sql/analytics"
74-
only:
75-
- main
73+
# FLYWAY_LOCATIONS: "filesystem:./migrations/analytics"
7674
environment:
7775
name: analytics-database
78-
when: manual # Analytics can be deployed separately if needed
76+
rules:
77+
- if: $CI_COMMIT_BRANCH == "main"
78+
when: manual # Analytics can be deployed separately if needed
7979

8080
# Add more databases by copying the pattern above and incrementing the number

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,33 @@ stages:
2929
validate:prod:
3030
extends: .flyway_validate
3131
stage: validate
32-
only:
33-
- main
34-
- tags
32+
rules:
33+
- if: $CI_COMMIT_BRANCH == "main"
34+
- if: $CI_COMMIT_TAG
3535

3636
# Deploy to STAGING first
3737
migrate:staging:
3838
extends: .flyway_migrate
3939
stage: staging
40-
only:
41-
- main
4240
environment:
4341
name: staging
4442
url: https://staging.myapp.com
43+
rules:
44+
- if: $CI_COMMIT_BRANCH == "main"
4545

4646
# Show production info before migration
4747
info:production:
4848
extends: .flyway_info
4949
stage: production
50-
only:
51-
- tags
5250
environment:
5351
name: production
52+
rules:
53+
- if: $CI_COMMIT_TAG
5454

5555
# Deploy to PRODUCTION (manual approval required)
5656
migrate:production:
5757
extends: .flyway_migrate
5858
stage: production
59-
only:
60-
- tags
61-
when: manual
6259
environment:
6360
name: production
6461
url: https://myapp.com
@@ -69,13 +66,18 @@ migrate:production:
6966
- echo "Database URL: ${FLYWAY_URL}"
7067
- echo "This requires manual approval. Click 'Play' button to proceed."
7168
- echo "==========================================="
69+
rules:
70+
- if: $CI_COMMIT_TAG
71+
when: manual
7272

7373
# Manual repair for production (use with caution)
7474
repair:production:
7575
extends: .flyway_repair
7676
stage: production
77-
only:
78-
- main
79-
- tags
8077
environment:
8178
name: production
79+
rules:
80+
- if: $CI_COMMIT_BRANCH == "main"
81+
when: manual
82+
- if: $CI_COMMIT_TAG
83+
when: manual

Gitlab-Templatized/.gitlab-ci-example-region-london.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ include:
2424
- local: '.gitlab/ci/flyway.yml'
2525

2626
stages:
27-
- fetch
2827
- generate
2928
- deploy
3029

@@ -39,28 +38,17 @@ variables:
3938

4039
REGISTRY_DATABASE: "flyway_registry"
4140
REGISTRY_PORT: "1433"
42-
SQL_SERVER_PORT: "1433"
43-
INCLUDE_REPLICAS: "1"
4441

4542
# ---------------------------------------------------------------------------
46-
# Stage 1 – fetch: query the registry for London targets only
47-
# ---------------------------------------------------------------------------
48-
fetch:london:
49-
extends: .fetch_targets
50-
variables:
51-
FILTER_LOCATION: "London"
52-
53-
# ---------------------------------------------------------------------------
54-
# Stage 2 – generate: produce dynamic-pipeline.yml from targets.json
43+
# Stage 1 – generate: query registry, build JDBCs, write dynamic-pipeline.yml
5544
# ---------------------------------------------------------------------------
5645
generate:london:
5746
extends: .generate_pipeline
58-
needs:
59-
- job: fetch:london
60-
artifacts: true
47+
variables:
48+
FILTER_LOCATION: "London"
6149

6250
# ---------------------------------------------------------------------------
63-
# Stage 3 – deploy
51+
# Stage 2 – deploy: trigger the generated child pipeline
6452
# ---------------------------------------------------------------------------
6553
deploy:london:
6654
stage: deploy

0 commit comments

Comments
 (0)