forked from red-gate/Flyway-Sample-Pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab-sample-pipeline.yml
116 lines (101 loc) · 5.23 KB
/
gitlab-sample-pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# https://documentation.red-gate.com/fd/gitlab-dockerized-yml-pipeline-using-saas-runner-165740750.html
# Global Variables Section - These will be utilized throughout the pipeline #
variables:
RELEASE_PREVIEW: 'Release-Preview.sql'
BUILD_NAME: 'Build'
# FLYWAY_DOCKER_IMAGE: redgate/flyway-azure:latest-alpine #https://hub.docker.com/r/flyway/flyway
FLYWAY_DOCKER_IMAGE: redgate/flyway:latest #https://hub.docker.com/r/flyway/flyway
FLYWAY_DOCKER_CONTAINER_NAME: flyway-container #The name to provide to any Docker Container created
FLYWAY_MIGRATIONS_PATH: $CI_PROJECT_DIR/migrations
FLYWAY_CONFIG_FILES: $CI_PROJECT_DIR/conf
# userName and password remain environment specific because their values are evaluated at runtime
FLYWAY_DOCKER_RUN: 'docker run --rm -v $FLYWAY_MIGRATIONS_PATH:/flyway/sql -v $FLYWAY_CONFIG_FILES/$CI_JOB_STAGE:/flyway/conf $FLYWAY_DOCKER_IMAGE -user=$userName -password=$password -licenseKey=$FLYWAY_LICENSE_KEY'
# --- End of Global Variables Section --- #
# List of stages throughout the pipeline #
stages: # List of stages for jobs, and their order of execution
- build
- test
- production-pre-release
- production-deploy
# --- End of Stages list --- #
# Hidden definition (the prefix of . indicates the hidden aspect) for the Flyway Build and Release Runner - This can be called by future jobs, all re-using the same block of code. Reducing the locations that may require changes #
.flyway_job:
image: docker:latest
services:
- docker:dind #This enables Docker in Docker mode. Which allows for the Flyway Container to be created within the G
before_script:
- pwd
- ls
- echo "${FLYWAY_DOCKER_RUN}"
- docker pull redgate/flyway:latest
artifacts:
paths:
expire_in: 1 week
# --- End of Flyway_Job hidden definition --- #
# Build Stage Definition #
build-stage: # This job runs in the build stage, which runs first.
extends: .flyway_job # The extends command reuses configuration sections - See https://docs.gitlab.com/ee/ci/yaml/#extends
stage: build # Indicates which stage this job is part of
rules:
- when: always #Change always to never to skip this job (or vice versa)
environment:
name: build
variables: # Definition of job stage variables
databaseName: 'Database_Build'
JDBC: 'jdbc:sqlserver://localhost:1433;encrypt=true;databaseName=Database_Build'
pauseForCodeReview: 'false'
script:
- $FLYWAY_DOCKER_RUN info clean info -url=${JDBC} -cleanDisabled='false'
- $FLYWAY_DOCKER_RUN info migrate info -url=${JDBC} -cleanDisabled='true'
- echo "The job completed successfully with Flyway in the Build environment"
artifacts:
paths:
- ${CI_PROJECT_DIR}/migrations # Consume all of the migration scripts used during the build process as an artifact
test-stage: # This job also runs in the test stage.
extends: .flyway_job # The extends command reuses configuration sections - See https://docs.gitlab.com/ee/ci/yaml/#extends
stage: test # Indicates which stage this job is part of
rules:
- when: never #Change always to never to skip this job (or vice versa)
environment:
name: build
variables: # Definition of job stage variables
databaseName: 'Database_Test'
JDBC: 'jdbc:sqlserver://localhost:1433;encrypt=true;databaseName=Database_Test'
pauseForCodeReview: 'false'
script:
- $FLYWAY_DOCKER_RUN info clean info -url=${JDBC} -cleanDisabled='false'
- $FLYWAY_DOCKER_RUN info migrate info -url=${JDBC} -cleanDisabled='true'
- echo "The job completed successfully with Flyway in the Test environment"
prod-pre-release:
extends: .flyway_job # The extends command reuses configuration sections - See https://docs.gitlab.com/ee/ci/yaml/#extends
stage: production-pre-release # Indicates which stage this job is part of
rules:
- when: always #Change always to never to skip this job (or vice versa)
environment:
name: prod
variables: # Definition of job stage variables
databaseName: 'Eastwind_Prod'
JDBC: 'jdbc:sqlserver://localhost:1433;encrypt=true;databaseName=Database_Prod'
pauseForCodeReview: 'false'
script:
- $FLYWAY_DOCKER_RUN migrate -outOfOrder=true -dryRunOutput=${CI_PROJECT_DIR}/${CI_JOB_STAGE}-${RELEASE_PREVIEW} -url=${JDBC} -cleanDisabled='true'
- echo "The job completed successfully with Flyway in the Prod environment"
- pwd
- ls
artifacts:
paths:
- ${CI_PROJECT_DIR}/${CI_JOB_STAGE}-${RELEASE_PREVIEW} # Consume all of the migration scripts used during the build process as an artifact
expire_in: 1 week
prod-deploy:
extends: .flyway_job # The extends command reuses configuration sections - See https://docs.gitlab.com/ee/ci/yaml/#extends
stage: production-deploy # Indicates which stage this job is part of
when: manual
environment:
name: prod
variables: # Definition of job stage variables
databaseName: 'Database_Prod'
JDBC: 'jdbc:sqlserver://localhost:1433;encrypt=true;databaseName=Database_Prod'
pauseForCodeReview: 'false'
script:
- $FLYWAY_DOCKER_RUN info migrate info -url=${JDBC} -cleanDisabled='true'
- echo "The job completed successfully with Flyway in the Prod environment"