Skip to content

Commit 363f09f

Browse files
authored
Merge pull request #1 from RG-AutoPilot/release
Initial State Based Autopilot Repository Setup
2 parents ec9f2c6 + 9472002 commit 363f09f

File tree

62 files changed

+3206
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3206
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: GitHub-Autopilot-Simple-State-Pipeline-Linux
4+
5+
on:
6+
# pull_request:
7+
# branches:
8+
# - release
9+
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
workflow_call: # This enables the workflow to be called from other workflows
13+
env:
14+
15+
# Enable this for additional debug logging
16+
ACTIONS_RUNNER_DEBUG: false
17+
18+
### Step 1: Define Environment Secrets ###
19+
### Environment Secrets - Create Environment Secrets ###
20+
### Navigate to Settings > Secrets & Variables > Actions
21+
# FLYWAY_EMAIL: Enter the email address linked to the Redgate Account that created the PAT
22+
# FLYWAY_TOKEN: Enter the PAT Value (This should be treated like a password and thus as a secure variable.
23+
# FLYWAY_AUTH_DISABLED: (Optional) - Create and set to true to skip the auth check stage
24+
# TARGET_DATABASE_USERNAME: Leave blank if using integratedSecurity (default).
25+
# TARGET_DATABASE_PASSWORD: Leave blank if using integratedSecurity (default).
26+
# CUSTOM_PARAMS: Optional - Used for passing custom Flyway Parameters to each Flyway command
27+
### End of Environment Variables ###
28+
29+
# Step 3: Authenticate Flyway with Personal Access Tokens (PATs)
30+
# Details on how to do this can be found here: https://documentation.red-gate.com/flyway/flyway-cli-and-api/tutorials/tutorial-personal-access-tokens
31+
# Documentation on all available Authentication methods can be found here: https://documentation.red-gate.com/fd/flyway-licensing-263061944.html
32+
FLYWAY_EMAIL: "${{ secrets.FLYWAY_EMAIL }}" # Enter the email address linked to the Redgate Account that created the PAT
33+
FLYWAY_TOKEN: "${{ secrets.FLYWAY_TOKEN }}" # Enter the PAT Value (This should be treated like a password and thus as a secure variable.
34+
FLYWAY_AUTH_DISABLED: "${{ secrets.FLYWAY_AUTH_DISABLED }}" # Create and set to true to skip the auth check stage, useful when Offline Permits are in use instead.
35+
36+
BASELINE_VERSION: "001" # This should match the version number of your baseline script
37+
FIRST_UNDO_SCRIPT: "002" # This should match the first undo version in your project
38+
39+
# Optional - Validate Flyway CLI installation for ephemeral agents
40+
FLYWAY_CLI_INSTALL_CHECK: "${{ secrets.FLYWAY_CLI_INSTALL_CHECK }}" # Setting to false will skip the Flyway CLI check step
41+
FLYWAY_VERSION: "Latest" # This outlines the version of Flyway CLI that will be downloaded if no Flyway CLI is detected on the target agent (Examples - '11.0.0' for specific version. Or 'Latest' for latest version)
42+
FLYWAY_INSTALL_DIRECTORY: "" # The path on the agent machine where Flyway CLI will be installed
43+
44+
# Optional: Side Quest #1 - Setup Flyway Pipeline Integration - https://flyway.red-gate.com/ For More Details
45+
FLYWAY_PUBLISH_RESULT: "true" # Set this value to true to enable Flyway Pipelines and track your releases centrally!
46+
FLYWAY_DRIFT_ON_MIGRATE: "true" # Set this value to true to enable Flyway Pipelines drift detection and track your drift centrally!
47+
48+
### DO NOT EDIT BELOW THIS LINE - All variables set in the above section will be consumed by the jobs below and therefore do not require any updates to function ###
49+
50+
jobs:
51+
# This workflow contains a single job called "build"
52+
build:
53+
name: Deploy Build
54+
# The type of runner that the job will run on
55+
runs-on: "self-hosted" # Options - self-hosted/ubuntu-latest/windows-latest (See here for more details on GitHub hosted runners - https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners)
56+
environment: 'build'
57+
env:
58+
stage: 'Build'
59+
displayName: 'Build'
60+
DATABASE_NAME: 'AutoPilotBuild'
61+
ENVIRONMENT: 'Build' # This variable refers to the environment name present in the Flyway Projects TOML file.
62+
TARGET_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}"
63+
TARGET_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}"
64+
CUSTOM_PARAMS: "${{ secrets.CUSTOM_PARAMS }}" # Secure method of adding custom Flyway Parameters (Example -X for debug)
65+
EXECUTE_BUILD: 'true' # Turn to false to skip the build stage tasks
66+
publishArtifacts: 'true' # Turn to false to skip the artifact upload
67+
steps:
68+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
69+
- uses: actions/checkout@v4
70+
# Optional - If Enabled, Flyway CLI will be validated and installed if not present
71+
- name: Flyway - CLI Automatic Validation and Install
72+
run: bash ${{ GITHUB.WORKSPACE }}/Scripts/Flyway_DownloadAndInstallCLI_Unix.sh
73+
if: env.FLYWAY_CLI_INSTALL_CHECK == 'true'
74+
# Step 1 - Flyway License Authentication #
75+
- name: Flyway Authentication
76+
if: ${{ env.EXECUTE_BUILD == 'true' && env.FLYWAY_AUTH_DISABLED != 'true' && success() }}
77+
run: |
78+
flyway auth -IAgreeToTheEula -email="${{ env.FLYWAY_EMAIL }}" -token="${{ env.FLYWAY_TOKEN }}"
79+
# Step 2 - Ensure the Build Database is cleaned of all objects, meaning the build starts from scratch
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: GitHub-Autopilot-Simple-State-Pipeline-Windows
4+
5+
on:
6+
# Triggers the workflow on push or pull request events but only for the "release" branch
7+
#push:
8+
#branches:
9+
#- release
10+
#- 'migrations/**'
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
env:
15+
# Enable this for additional debug logging
16+
ACTIONS_RUNNER_DEBUG: false
17+
18+
### Step 1: Define Environment Secrets ###
19+
### Environment Secrets - Create Environment Secrets ###
20+
### Navigate to Settings > Secrets & Variables > Actions
21+
# FLYWAY_EMAIL: Enter the email address linked to the Redgate Account that created the PAT
22+
# FLYWAY_TOKEN: Enter the PAT Value (This should be treated like a password and thus as a secure variable.
23+
# FLYWAY_AUTH_DISABLED: (Optional) - Create and set to true to skip the auth check stage
24+
# TARGET_DATABASE_USERNAME: Leave blank if using integratedSecurity (default).
25+
# TARGET_DATABASE_PASSWORD: Leave blank if using integratedSecurity (default).
26+
# CUSTOM_PARAMS: Optional - Used for passing custom Flyway Parameters to each Flyway command
27+
### End of Environment Variables ###
28+
29+
# Step 3: Authenticate Flyway with Personal Access Tokens (PATs)
30+
# Details on how to do this can be found here: https://documentation.red-gate.com/flyway/flyway-cli-and-api/tutorials/tutorial-personal-access-tokens
31+
# Documentation on all available Authentication methods can be found here: https://documentation.red-gate.com/fd/flyway-licensing-263061944.html
32+
FLYWAY_EMAIL: "${{ secrets.FLYWAY_EMAIL }}" # Enter the email address linked to the Redgate Account that created the PAT
33+
FLYWAY_TOKEN: "${{ secrets.FLYWAY_TOKEN }}" # Enter the PAT Value (This should be treated like a password and thus as a secure variable.
34+
FLYWAY_AUTH_DISABLED: "${{ secrets.FLYWAY_AUTH_DISABLED }}" # Create and set to true to skip the auth check stage, useful when Offline Permits are in use instead.
35+
36+
37+
BASELINE_VERSION: "001" # This should match the version number of your baseline script
38+
FIRST_UNDO_SCRIPT: "002" # This should match the first undo version in your project
39+
40+
# Optional: Validate Flyway CLI installation for ephemeral agents.
41+
FLYWAY_CLI_INSTALL_CHECK: "${{ secrets.FLYWAY_CLI_INSTALL_CHECK }}" # Setting to false will skip the Flyway CLI check step
42+
FLYWAY_VERSION: "Latest" # This outlines the version of Flyway CLI that will be downloaded if no Flyway CLI is detected on the target agent (Examples - '11.0.0' for specific version. Or 'Latest' for latest version)
43+
FLYWAY_INSTALL_DIRECTORY: "C:\\FlywayCLI\\" # The path on the agent machine where Flyway CLI will be installed
44+
45+
# Optional: Side Quest #1 - Enable Flyway Pipeline Integration for tracking releases and drift. - https://flyway.red-gate.com/
46+
FLYWAY_PUBLISH_RESULT: "true" # Set this value to true to enable Flyway Pipelines and track your releases centrally!
47+
FLYWAY_DRIFT_ON_MIGRATE: "true" # Set this value to true to enable Flyway Pipelines drift detection and track your drift centrally!
48+
49+
### DO NOT EDIT BELOW THIS LINE - All variables set in the above section will be consumed by the jobs below and therefore do not require any updates to function ###
50+
51+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: GitHub - Pipeline Validation Workflow
2+
3+
on:
4+
# Allows you to run this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
pull_request:
7+
branches:
8+
- release
9+
schedule:
10+
- cron: "0 3 * * *" # Runs at 3 AM UTC every night
11+
12+
jobs:
13+
setup-validation-environment:
14+
name: Spin Up RGClone Validation Container
15+
runs-on: "self-hosted"
16+
env:
17+
DATA_IMAGE_NAME: "Autopilot-Flyway-MSSQL"
18+
DATA_CONTAINER_NAME: "Autopilot-GitHub-Actions-StateBased-Build-Validatation_MSSQL-${{ github.run_number }}"
19+
PROXY_PORT: "1433"
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
24+
- name: Install rgclone CLI
25+
id: installCLI
26+
env:
27+
RGCLONE_API_ENDPOINT: ${{ secrets.RGCLONE_API_ENDPOINT }}
28+
RGCLONE_ACCESS_TOKEN: ${{ secrets.RGCLONE_ACCESS_TOKEN }}
29+
run: |
30+
# Check if rgclone is already installed
31+
if command -v rgclone &> /dev/null; then
32+
echo "rgclone is already installed. Skipping installation."
33+
rgclone version
34+
exit 0
35+
fi
36+
37+
echo "rgclone not found. Installing..."
38+
39+
# Define install location
40+
INSTALL_DIR="/usr/local/bin"
41+
TEMP_DIR=$(mktemp -d)
42+
43+
# Download and extract rgclone
44+
curl $RGCLONE_API_ENDPOINT/cloning-api/download/cli/linux-amd64 | tar xz -C "$TEMP_DIR"
45+
46+
# Move rgclone to the install directory
47+
sudo mv "$TEMP_DIR/rgclone" "$INSTALL_DIR/"
48+
sudo chmod +x "$INSTALL_DIR/rgclone"
49+
50+
# Verify installation
51+
echo "rgclone installed successfully."
52+
rgclone version
53+
54+
- name: Validate Data Image
55+
id: createDataImage
56+
env:
57+
RGCLONE_API_ENDPOINT: ${{ secrets.RGCLONE_API_ENDPOINT }}
58+
RGCLONE_ACCESS_TOKEN: ${{ secrets.RGCLONE_ACCESS_TOKEN }}
59+
run: |
60+
output=$(rgclone get di "$DATA_IMAGE_NAME" --ignore-not-found -o json)
61+
62+
if [[ -z "$output" ]]; then
63+
echo "Image does not exist. Creating image..."
64+
else
65+
echo "Image already exists. Moving on..."
66+
fi
67+
68+
- name: Create data container
69+
id: createDc
70+
env:
71+
RGCLONE_API_ENDPOINT: ${{ secrets.RGCLONE_API_ENDPOINT }}
72+
RGCLONE_ACCESS_TOKEN: ${{ secrets.RGCLONE_ACCESS_TOKEN }}
73+
run: |
74+
# Spin up a Data Container for chosen Image
75+
echo "Check if Data Container Already Exists"
76+
77+
if ! rgclone get data-container "$DATA_CONTAINER_NAME" &> /dev/null ; then
78+
echo "Creating container for $DATA_CONTAINER_NAME"
79+
output=$(rgclone create dc -n "$DATA_CONTAINER_NAME" -i "$DATA_IMAGE_NAME" -t 20m -o json)
80+
fi
81+
82+
# Parse JSON output using jq
83+
dbUser=$(echo "$output" | jq -r '.user')
84+
dbPassword=$(echo "$output" | jq -r '.password')
85+
sqlhost=$(echo "$output" | jq -r '.host')
86+
sqlport=$(echo "$output" | jq -r '.port')
87+
instance="${sqlhost},${sqlport}"
88+
89+
echo "Data container created successfully and available at: $instance"
90+
91+
# Set output values for use in subsequent steps
92+
echo "dbUser=$dbUser" >> "$GITHUB_ENV"
93+
echo "dbPassword=$dbPassword" >> "$GITHUB_ENV"
94+
echo "instance=$instance" >> "$GITHUB_ENV"
95+
96+
- name: Create Local Proxy for Container
97+
id: createProxy
98+
env:
99+
RGCLONE_API_ENDPOINT: ${{ secrets.RGCLONE_API_ENDPOINT }}
100+
RGCLONE_ACCESS_TOKEN: ${{ secrets.RGCLONE_ACCESS_TOKEN }}
101+
run: |
102+
# Kill any pending RGClone processes
103+
echo "Killing any pending RGClone processes"
104+
pkill -f rgclone || true # the `|| true` ensures the script doesn't fail if no process is found
105+
106+
# Create Data Container Proxy
107+
echo "Creating Data Container Proxy"
108+
RUNNER_TRACKING_ID="" && rgclone proxy dc "$DATA_CONTAINER_NAME" -p "$PROXY_PORT" & # Run the proxy in the background
109+
110+
echo "RGClone Proxy Enabled"
111+
112+
# Validate-Flyway-Pipeline:
113+
# name: Run Flyway Pipeline
114+
# needs: setup-validation-environment
115+
# uses: ./.github/workflows/GitHub-Flyway-CICD-StateBased-Pipeline_Linux.yml
116+
# secrets: inherit # Inherit existing secrets but allow environment overrides
117+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# Flyway ignores
3+
*.user.toml
4+
*.artifact
5+
report.html
6+
report.json

0 commit comments

Comments
 (0)