Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/actions/codebuild-authorize-runner-ip/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Needs actions/checkout earlier in the job and AWS credentials in the environment. The caller
# uploads the ip-file output as artifact runner-ip-<id> for codebuild-revoke-runner-ips.
name: 'Authorize the CodeBuild runner egress IP address'
description: 'Discovers this job''s egress IPv4 address, opens TCP 3306 and 5432 from it in the default security group, and writes it to a file.'
inputs:
id:
description: 'Identifier unique to this job within the run. Names the file runner-ip-<id>.txt; use it in the artifact name runner-ip-<id> as well.'
required: true
outputs:
ipv4:
description: 'The egress IPv4 address that was authorized.'
value: ${{ steps.ip.outputs.ipv4 }}
ip-file:
description: 'Path of the file holding the address, to upload as artifact runner-ip-<id>.'
value: ${{ steps.ip.outputs.ip-file }}
runs:
using: 'composite'
steps:
- name: 'Discover this job''s egress IP address'
id: ip
shell: bash
env:
RUNNER_IP_FILE: ${{ runner.temp }}/runner-ip-${{ inputs.id }}.txt
run: |
if ! response=$(curl -fsS --max-time 10 https://checkip.amazonaws.com); then
echo "::error::checkip.amazonaws.com did not answer, so this job's egress IP address is unknown and the test databases would be unreachable."
exit 1
fi
ipv4=$(printf '%s' "$response" | tr -d '[:space:]')
octet='(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
ipv4_re="^($octet\.){3}$octet\$"
if ! [[ $ipv4 =~ $ipv4_re ]]; then
echo "::error::checkip.amazonaws.com did not return a dotted IPv4 address, so this job's egress IP address is unknown."
exit 1
fi
echo "Runner egress IP address: $ipv4"
echo "ipv4=$ipv4" >> "$GITHUB_OUTPUT"
echo "$ipv4" > "$RUNNER_IP_FILE"
echo "ip-file=$RUNNER_IP_FILE" >> "$GITHUB_OUTPUT"

# Only TCP 3306 and 5432 are opened, the ports the harness reaches (TestEnvironment.getPort()).
# Keep the description EXACTLY "Test run at " plus an ISO-8601 instant:
# AuroraTestUtility.securityGroupRulesCleanUp() calls Instant.parse on it
# and revokes the rule after 12 hours if revoke-runner-ip never ran.
# Appending anything opts the rule out.
# On InvalidPermission.Duplicate (shared address) the description is refreshed so the sweep keeps the rule.
# If 3306 succeeds and 5432 fails, nothing is recorded; the sweep reclaims it.
- name: 'Authorize this job''s egress IP address'
shell: bash
env:
RUNNER_IPV4: ${{ steps.ip.outputs.ipv4 }}
run: |
ipv4=$RUNNER_IPV4
description="Test run at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
for port in 3306 5432; do
permissions=$(printf \
'[{"IpProtocol":"tcp","FromPort":%s,"ToPort":%s,"IpRanges":[{"CidrIp":"%s/32","Description":"%s"}]}]' \
"$port" "$port" "$ipv4" "$description")
if output=$(aws ec2 authorize-security-group-ingress \
--group-name default --ip-permissions "$permissions" 2>&1); then
echo "Authorized TCP $port from $ipv4/32."
elif [ "${output#*InvalidPermission.Duplicate}" != "$output" ]; then
if ! output=$(aws ec2 update-security-group-rule-descriptions-ingress \
--group-name default --ip-permissions "$permissions" 2>&1); then
echo "$output"
exit 1
fi
echo "TCP $port from $ipv4/32 was already authorized; refreshed its description."
else
echo "$output"
exit 1
fi
done
50 changes: 50 additions & 0 deletions .github/actions/codebuild-revoke-runner-ips/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Needs actions/checkout, AWS credentials, and the runner-ip-* artifacts downloaded (merge-multiple) into ip-dir.
name: 'Revoke the CodeBuild runner egress IP addresses'
description: 'Revokes TCP 3306 and 5432 for every address recorded in ip-dir. Missing rules and an empty directory are not errors.'
inputs:
ip-dir:
description: 'Directory holding the downloaded runner-ip-*.txt files.'
required: true
runs:
using: 'composite'
steps:
- name: 'Revoke the recorded egress IP addresses'
shell: bash
env:
RUNNER_IP_DIR: ${{ inputs.ip-dir }}
run: |
shopt -s nullglob
files=("$RUNNER_IP_DIR"/runner-ip-*.txt)
if [ ${#files[@]} -eq 0 ]; then
echo "No matrix job recorded an authorized address; nothing to revoke."
exit 0
fi
octet='(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
ipv4_re="^($octet\.){3}$octet\$"
while IFS= read -r ipv4; do
if ! [[ $ipv4 =~ $ipv4_re ]]; then
echo "::warning::Skipping a recorded egress address that is not a dotted IPv4 address."
continue
fi
for port in 3306 5432; do
permissions=$(printf \
'[{"IpProtocol":"tcp","FromPort":%s,"ToPort":%s,"IpRanges":[{"CidrIp":"%s/32"}]}]' \
"$port" "$port" "$ipv4")
if output=$(aws ec2 revoke-security-group-ingress \
--group-name default --ip-permissions "$permissions" 2>&1); then
# In a default VPC an unmatched revoke is not an error: the rules that were not found
# come back under UnknownIpPermissions, so echo the response instead of claiming the
# rule was there. A non-default VPC raises InvalidPermission.NotFound, handled below.
echo "Revoke of TCP $port from $ipv4/32 accepted:"
echo "$output"
elif [ "${output#*InvalidPermission.NotFound}" != "$output" ]; then
# Already gone, e.g. revoked by hand or by the 12-hour sweep.
echo "TCP $port from $ipv4/32 was already revoked."
else
# Revoke the rest before failing.
echo "$output"
status=1
fi
done
done < <(cat "${files[@]}" | tr -d '\r' | awk 'NF' | sort -u)
exit "${status:-0}"
10 changes: 8 additions & 2 deletions .github/workflows/autoscaling_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ jobs:
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Set a random database password'
run: |
password=$(openssl rand -hex 16)
echo "::add-mask::$password"
echo "DB_PASSWORD=$password" >> "$GITHUB_ENV"

- name: 'Run Autoscaling Tests'
run: |
./gradlew --no-parallel --no-daemon test-autoscaling --info
env:
RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }}
AURORA_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }}

- name: 'Archive results'
if: always()
Expand Down
19 changes: 8 additions & 11 deletions .github/workflows/blue_green_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
name: Blue/Green Integration Tests

on:
# The push trigger is in blue_green_integration_tests_codebuild.yml, which runs these tests on CodeBuild runners.
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- '**/*.jpg'
- '**/README.txt'
- '**/LICENSE.txt'
- 'docs/**'
- 'ISSUE_TEMPLATE/**'
- '**/remove-old-artifacts.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -60,13 +50,20 @@ jobs:
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Set a random database password'
run: |
password=$(openssl rand -hex 16)
echo "::add-mask::$password"
echo "DB_PASSWORD=$password" >> "$GITHUB_ENV"

- name: 'Run Blue/Green Integration Tests'
run: |
./gradlew --no-parallel --no-daemon test-bgd-${{ matrix.task }} --info
env:
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
MYSQL_VERSION: default
PG_VERSION: default
SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }}

- name: 'Archive Blue/Green results'
if: always()
Expand Down
130 changes: 130 additions & 0 deletions .github/workflows/blue_green_integration_tests_codebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Blue/Green Integration Tests (CodeBuild)

on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- '**/*.jpg'
- '**/README.txt'
- '**/LICENSE.txt'
- 'docs/**'
- 'ISSUE_TEMPLATE/**'
- '**/remove-old-artifacts.yml'

concurrency:
# Shared with the other CodeBuild workflow: jobs share outbound IPs, and each run's last job revokes their database rules.
group: rds-integration-tests-codebuild
cancel-in-progress: false

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

env:
# CodeBuild runners share outbound addresses, and Docker Hub limits anonymous pulls per address.
TEST_CONTAINER_REGISTRY: ecr
# Each job authorizes its address and one job revokes them all, so the harness must not revoke
# a rule that other jobs on the same address still use.
SKIP_IP_AUTHORIZATION: true

jobs:
blue-green-integration-tests:
name: Run Blue/Green Integration Tests
runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }}
timeout-minutes: 120
strategy:
fail-fast: false
max-parallel: 2
matrix:
task: [ "mysql-aurora-sync", "mysql-aurora-async", "pg-aurora-sync", "pg-aurora-async" ]

steps:
- name: 'Clone repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- name: 'Set up JDK 8'
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: 'corretto'
java-version: 8

- name: 'Configure AWS Credentials'
uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }}
role-session-name: python_bg_integration_tests
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Authorize the runner IP address'
id: ip
uses: ./.github/actions/codebuild-authorize-runner-ip
with:
id: bgd-${{ matrix.task }}

- name: 'Record the runner IP address'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: runner-ip-bgd-${{ matrix.task }}
path: ${{ steps.ip.outputs.ip-file }}
if-no-files-found: error
retention-days: 1

- name: 'Set a random database password'
run: |
password=$(openssl rand -hex 16)
echo "::add-mask::$password"
echo "DB_PASSWORD=$password" >> "$GITHUB_ENV"

- name: 'Run Blue/Green Integration Tests'
run: |
./gradlew --no-parallel --no-daemon test-bgd-${{ matrix.task }} --info
env:
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
MYSQL_VERSION: default
PG_VERSION: default
SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }}

- name: 'Archive Blue/Green results'
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pytest-integration-report-bgd-${{ matrix.task }}
path: ./tests/integration/container/reports
retention-days: 5

revoke-runner-ip:
name: 'Revoke runner IP'
runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }}
timeout-minutes: 30
needs: blue-green-integration-tests
if: always()

steps:
- name: 'Clone repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1

- name: 'Configure AWS Credentials'
uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }}
role-session-name: python_bg_integration_tests
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Download the recorded runner IP addresses'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: runner-ip-*
merge-multiple: true
path: ${{ runner.temp }}/runner-ips

- name: 'Revoke the recorded runner IP addresses'
uses: ./.github/actions/codebuild-revoke-runner-ips
with:
ip-dir: ${{ runner.temp }}/runner-ips
36 changes: 19 additions & 17 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
name: Integration Tests

on:
# The push trigger is in integration_tests_codebuild.yml, which runs these tests on CodeBuild runners.
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- '**/*.jpg'
- '**/README.txt'
- '**/LICENSE.txt'
- 'docs/**'
- 'ISSUE_TEMPLATE/**'
- '**/remove-old-artifacts.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -59,14 +49,20 @@ jobs:
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Set a random database password'
run: |
password=$(openssl rand -hex 16)
echo "::add-mask::$password"
echo "DB_PASSWORD=$password" >> "$GITHUB_ENV"

- name: 'Run LTS Integration Tests'
run: |
./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info
env:
RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }}
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AURORA_MYSQL_DB_ENGINE_VERSION: lts
AURORA_PG_ENGINE_VERSION: lts
MYSQL_VERSION: default
PG_VERSION: default
SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }}

- name: 'Archive LTS results'
if: always()
Expand Down Expand Up @@ -113,14 +109,20 @@ jobs:
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: 'Set a random database password'
run: |
password=$(openssl rand -hex 16)
echo "::add-mask::$password"
echo "DB_PASSWORD=$password" >> "$GITHUB_ENV"

- name: 'Run Latest Integration Tests'
run: |
./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info
env:
RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }}
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AURORA_MYSQL_DB_ENGINE_VERSION: latest
AURORA_PG_ENGINE_VERSION: latest
MYSQL_VERSION: latest
PG_VERSION: latest
SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }}

- name: 'Archive Latest results'
if: always()
Expand Down
Loading