Skip to content

Commit 5c520c5

Browse files
authored
Add hostname to MySQLConnection.connect() (#317)
* Add `hostname` to `MySQLConnection.connect()` * Temporary fix to support both plain IPs and SNI * Apply CI updates
1 parent 6245a07 commit 5c520c5

File tree

3 files changed

+60
-77
lines changed

3 files changed

+60
-77
lines changed

.github/workflows/test.yml

Lines changed: 49 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: test
2+
concurrency:
3+
group: ${{ github.workflow }}-${{ github.ref }}
4+
cancel-in-progress: true
25
on:
3-
pull_request: { branches: ['*'] }
6+
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
47
push: { branches: [ main ] }
58

69
env:
@@ -21,48 +24,15 @@ env:
2124

2225
jobs:
2326

24-
codecov:
25-
strategy:
26-
# For MySQL we have to run coverage baselines against multiple DB versions thanks to
27-
# the driver's behavior changing notably depending on the server.
28-
matrix: { dbimage: ['mysql:5.7', 'mysql:8.0', 'mariadb:10.7'] }
29-
runs-on: ubuntu-latest
30-
container: swift:5.7-jammy
31-
services:
32-
mysql-a:
33-
image: ${{ matrix.dbimage }}
34-
env:
35-
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
36-
MYSQL_USER: test_username
37-
MYSQL_PASSWORD: test_password
38-
MYSQL_DATABASE: test_database
39-
steps:
40-
- name: Save MySQL version to env
41-
run: |
42-
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
43-
- name: Check out package
44-
uses: actions/checkout@v3
45-
- name: Run local tests with coverage
46-
run: swift test --enable-code-coverage
47-
- name: Submit coverage report to Codecov.io
48-
uses: vapor/swift-codecov-action@v0.2
49-
with:
50-
cc_flags: 'unittests'
51-
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION'
52-
cc_fail_ci_if_error: true
53-
cc_verbose: true
54-
cc_dry_run: false
55-
5627
# Check for API breakage versus main
5728
api-breakage:
58-
if: github.event_name == 'pull_request'
29+
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
5930
runs-on: ubuntu-latest
60-
container: swift:5.7-jammy
31+
container: swift:5.8-jammy
6132
steps:
6233
- name: Check out package
6334
uses: actions/checkout@v3
64-
with:
65-
fetch-depth: 0
35+
with: { fetch-depth: 0 }
6636
# https://github.com/actions/checkout/issues/766
6737
- name: Mark the workspace as safe
6838
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
@@ -71,7 +41,7 @@ jobs:
7141

7242
# Test integration with downstream Fluent driver
7343
dependents:
74-
if: github.event_name == 'pull_request'
44+
if: ${{ !(github.event.pull_request.draft || false) }}
7545
runs-on: ubuntu-latest
7646
services:
7747
mysql-a:
@@ -88,52 +58,48 @@ jobs:
8858
MYSQL_USER: test_username
8959
MYSQL_PASSWORD: test_password
9060
MYSQL_DATABASE: test_database
91-
container: swift:5.7-jammy
61+
container: swift:5.8-jammy
9262
strategy:
9363
fail-fast: false
9464
matrix:
95-
# Same minimum all-behavior set as the code coverage runs
9665
dbimage:
9766
- mysql:5.7
9867
- mysql:8.0
99-
- mariadb:10.7
100-
dependent:
101-
- fluent-mysql-driver
68+
- mariadb:10.11
69+
- percona:8.0
10270
steps:
10371
- name: Check out package
10472
uses: actions/checkout@v3
105-
with:
106-
path: package
73+
with: { path: 'mysql-kit' }
10774
- name: Check out dependent
10875
uses: actions/checkout@v3
10976
with:
110-
repository: vapor/${{ matrix.dependent }}
111-
path: dependent
112-
ref: main
77+
repository: vapor/fluent-mysql-driver
78+
path: fluent-mysql-driver
11379
- name: Use local package
114-
run: swift package edit mysql-kit --path ../package
115-
working-directory: dependent
80+
run: swift package --package-path fluent-mysql-driver edit mysql-kit --path ./mysql-kit
11681
- name: Run tests with Thread Sanitizer
117-
run: swift test --sanitize=thread
118-
working-directory: dependent
82+
run: swift test --package-path fluent-mysql-driver --sanitize=thread
11983

120-
# Run unit tests (Linux)
84+
# Run unit tests (Linux), do code coverage in same job to cut down on extra builds
12185
linux-unit:
122-
if: github.event_name == 'pull_request'
86+
if: ${{ !(github.event.pull_request.draft || false) }}
12387
strategy:
12488
fail-fast: false
12589
matrix:
12690
dbimage:
12791
- mysql:5.7
12892
- mysql:8.0
129-
- mariadb:10.3
130-
- mariadb:10.7
93+
- mariadb:10.4
94+
- mariadb:10.11
13195
- percona:8.0
13296
runner:
133-
- swift:5.5-bionic
97+
# List is deliberately incomplete; we want to avoid running 50 jobs on every commit
13498
- swift:5.6-focal
135-
- swift:5.7-jammy
136-
- swiftlang/swift:nightly-main-jammy
99+
#- swift:5.7-jammy
100+
- swift:5.8-jammy
101+
- swiftlang/swift:nightly-5.9-jammy
102+
#- swiftlang/swift:nightly-main-jammy
137103
container: ${{ matrix.runner }}
138104
runs-on: ubuntu-latest
139105
services:
@@ -145,24 +111,32 @@ jobs:
145111
MYSQL_PASSWORD: test_password
146112
MYSQL_DATABASE: test_database
147113
steps:
148-
- name: Check out code
114+
- name: Save MySQL version to env
115+
run: |
116+
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
117+
- name: Check out package
149118
uses: actions/checkout@v3
150-
- name: Run tests with Thread Sanitizer
151-
run: swift test --sanitize=thread
119+
- name: Run local tests with coverage and TSan
120+
run: swift test --enable-code-coverage --sanitize=thread
121+
- name: Submit coverage report to Codecov.io
122+
if: ${{ !contains(matrix.runner, '5.8') }}
123+
uses: vapor/swift-codecov-action@v0.2
124+
with:
125+
cc_flags: 'unittests'
126+
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION'
127+
cc_fail_ci_if_error: true
128+
cc_verbose: true
129+
cc_dry_run: false
152130

153131
# Run unit tests (macOS). Don't bother with lots of variations, Linux will cover that.
154132
macos-unit:
155-
if: github.event_name == 'pull_request'
133+
if: ${{ !(github.event.pull_request.draft || false) }}
156134
strategy:
157135
fail-fast: false
158136
matrix:
159-
formula:
160-
- mysql@8.0
161-
macos:
162-
- macos-11
163-
- macos-12
164-
xcode:
165-
- latest-stable
137+
formula: [ 'mysql@8.0' ]
138+
macos: [ 'macos-12' ]
139+
xcode: [ 'latest-stable' ]
166140
runs-on: ${{ matrix.macos }}
167141
steps:
168142
- name: Select latest available Xcode
@@ -187,16 +161,16 @@ jobs:
187161
uses: actions/checkout@v3
188162
- name: Run tests with Thread Sanitizer
189163
run: swift test --sanitize=thread
190-
env:
191-
MYSQL_HOSTNAME: '127.0.0.1'
164+
env: { MYSQL_HOSTNAME: '127.0.0.1' }
192165

193166
test-exports:
167+
if: ${{ !(github.event.pull_request.draft || false) }}
194168
name: Test exports
195169
runs-on: ubuntu-latest
170+
container: swift:5.8-jammy
196171
steps:
197-
- name: Check out Vapor
172+
- name: Check out package
198173
uses: actions/checkout@v3
199-
with:
200-
fetch-depth: 0
174+
with: { fetch-depth: 0 }
201175
- name: Build
202176
run: swift build -Xswiftc -DBUILDING_DOCC

Sources/MySQLKit/MySQLConfiguration.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import NIOSSL
33
import NIOCore
4+
@_implementationOnly import NIOPosix // for inet_pton()
45

56
public struct MySQLConfiguration {
67
public var address: () throws -> SocketAddress
@@ -84,7 +85,14 @@ public struct MySQLConfiguration {
8485
self.username = username
8586
self.database = database
8687
self.password = password
87-
self.tlsConfiguration = tlsConfiguration
88-
self._hostname = hostname
88+
if let tlsConfiguration = tlsConfiguration {
89+
self.tlsConfiguration = tlsConfiguration
90+
91+
// Temporary fix - this logic should be removed once MySQLNIO is updated
92+
var n4 = in_addr(), n6 = in6_addr()
93+
if inet_pton(AF_INET, hostname, &n4) != 1 && inet_pton(AF_INET6, hostname, &n6) != 1 {
94+
self._hostname = hostname
95+
}
96+
}
8997
}
9098
}

Sources/MySQLKit/MySQLConnectionSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public struct MySQLConnectionSource: ConnectionPoolSource {
2323
database: self.configuration.database ?? self.configuration.username,
2424
password: self.configuration.password,
2525
tlsConfiguration: self.configuration.tlsConfiguration,
26+
serverHostname: self.configuration._hostname,
2627
logger: logger,
2728
on: eventLoop
2829
)

0 commit comments

Comments
 (0)