Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostname to MySQLConnection.connect() #317

Merged
merged 5 commits into from
Apr 12, 2023
Merged
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
124 changes: 49 additions & 75 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request: { branches: ['*'] }
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [ main ] }

env:
Expand All @@ -21,48 +24,15 @@ env:

jobs:

codecov:
strategy:
# For MySQL we have to run coverage baselines against multiple DB versions thanks to
# the driver's behavior changing notably depending on the server.
matrix: { dbimage: ['mysql:5.7', 'mysql:8.0', 'mariadb:10.7'] }
runs-on: ubuntu-latest
container: swift:5.7-jammy
services:
mysql-a:
image: ${{ matrix.dbimage }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_USER: test_username
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
steps:
- name: Save MySQL version to env
run: |
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
- name: Check out package
uses: actions/checkout@v3
- name: Run local tests with coverage
run: swift test --enable-code-coverage
- name: Submit coverage report to Codecov.io
uses: vapor/swift-codecov-action@v0.2
with:
cc_flags: 'unittests'
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION'
cc_fail_ci_if_error: true
cc_verbose: true
cc_dry_run: false

# Check for API breakage versus main
api-breakage:
if: github.event_name == 'pull_request'
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
runs-on: ubuntu-latest
container: swift:5.7-jammy
container: swift:5.8-jammy
steps:
- name: Check out package
uses: actions/checkout@v3
with:
fetch-depth: 0
with: { fetch-depth: 0 }
# https://github.com/actions/checkout/issues/766
- name: Mark the workspace as safe
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
Expand All @@ -71,7 +41,7 @@ jobs:

# Test integration with downstream Fluent driver
dependents:
if: github.event_name == 'pull_request'
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
services:
mysql-a:
Expand All @@ -88,52 +58,48 @@ jobs:
MYSQL_USER: test_username
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
container: swift:5.7-jammy
container: swift:5.8-jammy
strategy:
fail-fast: false
matrix:
# Same minimum all-behavior set as the code coverage runs
dbimage:
- mysql:5.7
- mysql:8.0
- mariadb:10.7
dependent:
- fluent-mysql-driver
- mariadb:10.11
- percona:8.0
steps:
- name: Check out package
uses: actions/checkout@v3
with:
path: package
with: { path: 'mysql-kit' }
- name: Check out dependent
uses: actions/checkout@v3
with:
repository: vapor/${{ matrix.dependent }}
path: dependent
ref: main
repository: vapor/fluent-mysql-driver
path: fluent-mysql-driver
- name: Use local package
run: swift package edit mysql-kit --path ../package
working-directory: dependent
run: swift package --package-path fluent-mysql-driver edit mysql-kit --path ./mysql-kit
- name: Run tests with Thread Sanitizer
run: swift test --sanitize=thread
working-directory: dependent
run: swift test --package-path fluent-mysql-driver --sanitize=thread

# Run unit tests (Linux)
# Run unit tests (Linux), do code coverage in same job to cut down on extra builds
linux-unit:
if: github.event_name == 'pull_request'
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
dbimage:
- mysql:5.7
- mysql:8.0
- mariadb:10.3
- mariadb:10.7
- mariadb:10.4
- mariadb:10.11
- percona:8.0
runner:
- swift:5.5-bionic
# List is deliberately incomplete; we want to avoid running 50 jobs on every commit
- swift:5.6-focal
- swift:5.7-jammy
- swiftlang/swift:nightly-main-jammy
#- swift:5.7-jammy
- swift:5.8-jammy
- swiftlang/swift:nightly-5.9-jammy
#- swiftlang/swift:nightly-main-jammy
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
Expand All @@ -145,24 +111,32 @@ jobs:
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
steps:
- name: Check out code
- name: Save MySQL version to env
run: |
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
- name: Check out package
uses: actions/checkout@v3
- name: Run tests with Thread Sanitizer
run: swift test --sanitize=thread
- name: Run local tests with coverage and TSan
run: swift test --enable-code-coverage --sanitize=thread
- name: Submit coverage report to Codecov.io
if: ${{ !contains(matrix.runner, '5.8') }}
uses: vapor/swift-codecov-action@v0.2
with:
cc_flags: 'unittests'
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION'
cc_fail_ci_if_error: true
cc_verbose: true
cc_dry_run: false

# Run unit tests (macOS). Don't bother with lots of variations, Linux will cover that.
macos-unit:
if: github.event_name == 'pull_request'
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
formula:
- mysql@8.0
macos:
- macos-11
- macos-12
xcode:
- latest-stable
formula: [ 'mysql@8.0' ]
macos: [ 'macos-12' ]
xcode: [ 'latest-stable' ]
runs-on: ${{ matrix.macos }}
steps:
- name: Select latest available Xcode
Expand All @@ -187,16 +161,16 @@ jobs:
uses: actions/checkout@v3
- name: Run tests with Thread Sanitizer
run: swift test --sanitize=thread
env:
MYSQL_HOSTNAME: '127.0.0.1'
env: { MYSQL_HOSTNAME: '127.0.0.1' }

test-exports:
if: ${{ !(github.event.pull_request.draft || false) }}
name: Test exports
runs-on: ubuntu-latest
container: swift:5.8-jammy
steps:
- name: Check out Vapor
- name: Check out package
uses: actions/checkout@v3
with:
fetch-depth: 0
with: { fetch-depth: 0 }
- name: Build
run: swift build -Xswiftc -DBUILDING_DOCC
12 changes: 10 additions & 2 deletions Sources/MySQLKit/MySQLConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import NIOSSL
import NIOCore
@_implementationOnly import NIOPosix // for inet_pton()

public struct MySQLConfiguration {
public var address: () throws -> SocketAddress
Expand Down Expand Up @@ -84,7 +85,14 @@ public struct MySQLConfiguration {
self.username = username
self.database = database
self.password = password
self.tlsConfiguration = tlsConfiguration
self._hostname = hostname
if let tlsConfiguration = tlsConfiguration {
self.tlsConfiguration = tlsConfiguration

// Temporary fix - this logic should be removed once MySQLNIO is updated
var n4 = in_addr(), n6 = in6_addr()
if inet_pton(AF_INET, hostname, &n4) != 1 && inet_pton(AF_INET6, hostname, &n6) != 1 {
self._hostname = hostname
}
}
}
}
1 change: 1 addition & 0 deletions Sources/MySQLKit/MySQLConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct MySQLConnectionSource: ConnectionPoolSource {
database: self.configuration.database ?? self.configuration.username,
password: self.configuration.password,
tlsConfiguration: self.configuration.tlsConfiguration,
serverHostname: self.configuration._hostname,
logger: logger,
on: eventLoop
)
Expand Down