Skip to content

Commit e492989

Browse files
vkuttypCopilot
andcommitted
ci: replace service containers with frpc VPS tunnel
All three DB jobs now connect to the Mac's local databases via frpc tunnel (VPS 192.9.131.139) instead of ephemeral service containers. Changes: - Remove Docker service containers for mssql, postgres, mysql - Install sqlcmd (Go-based) on ubuntu-24.04 for MSSQL seeding - Install postgresql-client and default-mysql-client for seeding - Use DB_HOST / MSSQL_TEST_PASS / PG_TEST_PASS / MYSQL_TEST_PASS secrets - Make all three seed scripts idempotent (DROP before CREATE) Required GitHub Actions secrets: DB_HOST - VPS IP that frpc tunnels through (192.9.131.139) MSSQL_TEST_PASS - SQL Server sa password PG_TEST_PASS - PostgreSQL pguser password MYSQL_TEST_PASS - MySQL mysqluser password Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3afc54 commit e492989

5 files changed

Lines changed: 102 additions & 70 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,11 @@ jobs:
7070

7171
# ───────────────────────────────────────────────────────────────────────────
7272
# 2. SQL Server integration tests
73-
# Uses GitHub Actions service container — Linux only.
73+
# Connects to Mac via frpc tunnel on VPS (no service container).
7474
# ───────────────────────────────────────────────────────────────────────────
7575
test-mssql:
7676
name: SQL Server integration tests
7777
runs-on: ubuntu-24.04
78-
services:
79-
mssql:
80-
image: mcr.microsoft.com/mssql/server:2022-latest
81-
env:
82-
ACCEPT_EULA: "Y"
83-
SA_PASSWORD: "aBCD111!"
84-
MSSQL_PID: Developer
85-
ports:
86-
- 1433:1433
87-
options: >-
88-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'aBCD111!' -Q 'SELECT 1' -C"
89-
--health-interval 10s
90-
--health-timeout 5s
91-
--health-retries 15
9278
steps:
9379
- name: Checkout
9480
uses: actions/checkout@v4
@@ -101,6 +87,16 @@ jobs:
10187
- name: Install SQLite
10288
run: sudo apt-get install -y libsqlite3-dev
10389

90+
- name: Install sqlcmd
91+
run: |
92+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
93+
| sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
94+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] \
95+
https://packages.microsoft.com/ubuntu/24.04/prod noble main" \
96+
| sudo tee /etc/apt/sources.list.d/mssql-release.list
97+
sudo apt-get update -q
98+
sudo ACCEPT_EULA=Y apt-get install -y sqlcmd
99+
104100
- name: Cache SPM
105101
uses: actions/cache@v4
106102
with:
@@ -111,52 +107,33 @@ jobs:
111107
112108
- name: Create test database
113109
run: |
114-
container_id=$(docker ps --filter "ancestor=mcr.microsoft.com/mssql/server:2022-latest" \
115-
--format "{{.ID}}" | head -1)
116-
for i in $(seq 1 30); do
117-
docker exec "$container_id" /opt/mssql-tools18/bin/sqlcmd \
118-
-S localhost -U sa -P 'aBCD111!' -C \
119-
-Q "IF DB_ID('MSSQLNioTestDb') IS NULL CREATE DATABASE MSSQLNioTestDb" \
120-
2>/dev/null && echo "SQL Server ready." && break
121-
echo "Waiting for SQL Server... ($i/30)"; sleep 5
122-
done
110+
sqlcmd -S "${{ secrets.DB_HOST }},1433" -U sa \
111+
-P "${{ secrets.MSSQL_TEST_PASS }}" \
112+
--trust-server-certificate \
113+
-Q "IF DB_ID('MSSQLNioTestDb') IS NULL CREATE DATABASE MSSQLNioTestDb"
123114
124115
- name: Seed SQL Server database
125116
run: |
126-
container_id=$(docker ps --filter "ancestor=mcr.microsoft.com/mssql/server:2022-latest" \
127-
--format "{{.ID}}" | head -1)
128-
docker cp Tests/Resources/mssql_seed.sql "$container_id:/tmp/seed.sql"
129-
docker exec "$container_id" /opt/mssql-tools18/bin/sqlcmd \
130-
-S localhost -U sa -P 'aBCD111!' -C -i /tmp/seed.sql
117+
sqlcmd -S "${{ secrets.DB_HOST }},1433" -U sa \
118+
-P "${{ secrets.MSSQL_TEST_PASS }}" \
119+
--trust-server-certificate \
120+
-i Tests/Resources/mssql_seed.sql
131121
132122
- name: Run MSSQL tests
133123
env:
134-
MSSQL_TEST_HOST: "127.0.0.1"
135-
MSSQL_TEST_PASS: "aBCD111!"
124+
MSSQL_TEST_HOST: ${{ secrets.DB_HOST }}
125+
MSSQL_TEST_PASS: ${{ secrets.MSSQL_TEST_PASS }}
136126
MSSQL_TEST_DB: "MSSQLNioTestDb"
137127
MSSQL_TEST_USER: "sa"
138128
run: swift test --filter MSSQLNioTests 2>&1
139129

140130
# ───────────────────────────────────────────────────────────────────────────
141131
# 3. PostgreSQL integration tests
132+
# Connects to Mac via frpc tunnel on VPS (no service container).
142133
# ───────────────────────────────────────────────────────────────────────────
143134
test-postgres:
144135
name: PostgreSQL integration tests
145136
runs-on: ubuntu-24.04
146-
services:
147-
postgres:
148-
image: postgres:16-alpine
149-
env:
150-
POSTGRES_DB: PostgresNioTestDb
151-
POSTGRES_USER: pguser
152-
POSTGRES_PASSWORD: pgPass123
153-
ports:
154-
- 5432:5432
155-
options: >-
156-
--health-cmd "pg_isready -U pguser"
157-
--health-interval 5s
158-
--health-timeout 3s
159-
--health-retries 10
160137
steps:
161138
- name: Checkout
162139
uses: actions/checkout@v4
@@ -166,8 +143,8 @@ jobs:
166143
with:
167144
swift-version: ${{ env.SWIFT_VERSION }}
168145

169-
- name: Install SQLite
170-
run: sudo apt-get install -y libsqlite3-dev
146+
- name: Install SQLite and psql
147+
run: sudo apt-get install -y libsqlite3-dev postgresql-client
171148

172149
- name: Cache SPM
173150
uses: actions/cache@v4
@@ -179,38 +156,25 @@ jobs:
179156
180157
- name: Seed PostgreSQL database
181158
run: |
182-
PGPASSWORD=pgPass123 psql -h 127.0.0.1 -U pguser -d PostgresNioTestDb \
159+
PGPASSWORD="${{ secrets.PG_TEST_PASS }}" psql \
160+
-h "${{ secrets.DB_HOST }}" -U pguser -d PostgresNioTestDb \
183161
-f Tests/Resources/postgres_seed.sql
184162
185163
- name: Run PostgreSQL tests
186164
env:
187-
PG_TEST_HOST: "127.0.0.1"
165+
PG_TEST_HOST: ${{ secrets.DB_HOST }}
188166
PG_TEST_DB: PostgresNioTestDb
189167
PG_TEST_USER: pguser
190-
PG_TEST_PASS: pgPass123
168+
PG_TEST_PASS: ${{ secrets.PG_TEST_PASS }}
191169
run: swift test --filter PostgresNioTests 2>&1
192170

193171
# ───────────────────────────────────────────────────────────────────────────
194172
# 4. MySQL integration tests
173+
# Connects to Mac via frpc tunnel on VPS (no service container).
195174
# ───────────────────────────────────────────────────────────────────────────
196175
test-mysql:
197176
name: MySQL integration tests
198177
runs-on: ubuntu-24.04
199-
services:
200-
mysql:
201-
image: mysql:8
202-
env:
203-
MYSQL_DATABASE: MySQLNioTestDb
204-
MYSQL_USER: mysqluser
205-
MYSQL_PASSWORD: mysqlPass123
206-
MYSQL_ROOT_PASSWORD: root
207-
ports:
208-
- 3306:3306
209-
options: >-
210-
--health-cmd "mysqladmin ping -u mysqluser -pmysqlPass123"
211-
--health-interval 5s
212-
--health-timeout 3s
213-
--health-retries 15
214178
steps:
215179
- name: Checkout
216180
uses: actions/checkout@v4
@@ -220,8 +184,8 @@ jobs:
220184
with:
221185
swift-version: ${{ env.SWIFT_VERSION }}
222186

223-
- name: Install SQLite
224-
run: sudo apt-get install -y libsqlite3-dev
187+
- name: Install SQLite and mysql client
188+
run: sudo apt-get install -y libsqlite3-dev default-mysql-client
225189

226190
- name: Cache SPM
227191
uses: actions/cache@v4
@@ -233,14 +197,16 @@ jobs:
233197
234198
- name: Seed MySQL database
235199
run: |
236-
mysql -h 127.0.0.1 -u mysqluser -pmysqlPass123 MySQLNioTestDb < Tests/Resources/mysql_seed.sql
200+
mysql -h "${{ secrets.DB_HOST }}" \
201+
-u mysqluser -p"${{ secrets.MYSQL_TEST_PASS }}" \
202+
MySQLNioTestDb < Tests/Resources/mysql_seed.sql
237203
238204
- name: Run MySQL tests
239205
env:
240-
MYSQL_TEST_HOST: "127.0.0.1"
206+
MYSQL_TEST_HOST: ${{ secrets.DB_HOST }}
241207
MYSQL_TEST_DB: MySQLNioTestDb
242208
MYSQL_TEST_USER: mysqluser
243-
MYSQL_TEST_PASS: mysqlPass123
209+
MYSQL_TEST_PASS: ${{ secrets.MYSQL_TEST_PASS }}
244210
run: swift test --filter MySQLNioTests 2>&1
245211

246212
# ───────────────────────────────────────────────────────────────────────────

Tests/Resources/mssql_seed.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
USE MSSQLNioTestDb;
55
GO
66

7+
-- ─── Drop existing objects ────────────────────────────────────────────────────
8+
9+
IF OBJECT_ID('dbo.sp_GetEmployeesAsJSON', 'P') IS NOT NULL DROP PROCEDURE sp_GetEmployeesAsJSON;
10+
IF OBJECT_ID('dbo.sp_GetDepartmentSummary', 'P') IS NOT NULL DROP PROCEDURE sp_GetDepartmentSummary;
11+
IF OBJECT_ID('dbo.sp_InsertEmployee', 'P') IS NOT NULL DROP PROCEDURE sp_InsertEmployee;
12+
IF OBJECT_ID('dbo.sp_GetEmployeesByDepartment', 'P') IS NOT NULL DROP PROCEDURE sp_GetEmployeesByDepartment;
13+
IF OBJECT_ID('dbo.sp_GetEmployeeById', 'P') IS NOT NULL DROP PROCEDURE sp_GetEmployeeById;
14+
IF OBJECT_ID('dbo.BulkTestTable', 'U') IS NOT NULL DROP TABLE BulkTestTable;
15+
IF OBJECT_ID('dbo.TypesTable', 'U') IS NOT NULL DROP TABLE TypesTable;
16+
IF OBJECT_ID('dbo.Employees', 'U') IS NOT NULL DROP TABLE Employees;
17+
IF OBJECT_ID('dbo.Departments', 'U') IS NOT NULL DROP TABLE Departments;
18+
GO
19+
720
-- ─── Departments ─────────────────────────────────────────────────────────────
821

922
CREATE TABLE Departments (

Tests/Resources/mysql_seed.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
-- MySQL seed data for sql-nio integration tests
22
-- Run against MySQLNioTestDb before executing MySQLNioTests
3+
-- Idempotent: drops all objects before recreating
4+
5+
-- ─── Drop existing objects ────────────────────────────────────────────────────
6+
7+
DROP TABLE IF EXISTS order_items;
8+
DROP TABLE IF EXISTS orders;
9+
DROP TABLE IF EXISTS type_samples;
10+
DROP TABLE IF EXISTS employees;
11+
DROP TABLE IF EXISTS products;
12+
DROP TABLE IF EXISTS departments;
13+
DROP PROCEDURE IF EXISTS add_numbers;
14+
DROP PROCEDURE IF EXISTS get_department_budget;
15+
DROP PROCEDURE IF EXISTS get_employee_count;
316

417
-- ─── Schema ───────────────────────────────────────────────────────────────────
518

Tests/Resources/postgres_seed.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
-- PostgreSQL seed data for sql-nio integration tests
22
-- Run against PostgresNioTestDb before executing PostgresNioTests
3+
-- Idempotent: drops all objects before recreating
4+
5+
-- ─── Drop existing objects ────────────────────────────────────────────────────
6+
7+
DROP TABLE IF EXISTS order_items CASCADE;
8+
DROP TABLE IF EXISTS orders CASCADE;
9+
DROP TABLE IF EXISTS type_samples CASCADE;
10+
DROP TABLE IF EXISTS employees CASCADE;
11+
DROP TABLE IF EXISTS products CASCADE;
12+
DROP TABLE IF EXISTS departments CASCADE;
13+
DROP FUNCTION IF EXISTS add_numbers(INTEGER, INTEGER);
14+
DROP FUNCTION IF EXISTS get_department_budget(INTEGER);
15+
DROP FUNCTION IF EXISTS get_employee_count(INTEGER);
316

417
-- ─── Schema ───────────────────────────────────────────────────────────────────
518

frpc.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
serverAddr = "192.9.131.139"
2+
serverPort = 7000
3+
4+
auth.method = "token"
5+
auth.token = "mV+utY4BtKQRBR33+MhF3wi3LTooQh3oSMq0FeQojSM="
6+
7+
8+
[[proxies]]
9+
name = "sqldb"
10+
type = "tcp"
11+
localIP = "localhost"
12+
localPort = 1433
13+
remotePort = 1433
14+
15+
[[proxies]]
16+
name = "postgresdb"
17+
type = "tcp"
18+
localIP = "localhost"
19+
localPort = 5432
20+
remotePort = 5432
21+
22+
[[proxies]]
23+
name = "mysqldb"
24+
type = "tcp"
25+
localIP = "localhost"
26+
localPort = 3306
27+
remotePort = 3306

0 commit comments

Comments
 (0)