Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions test/docker/Dockerfile.mysql-native-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mysql:8.0

# See Dockerfile.mysql-plain for the rationale. This variant pins mysql:8.0 and
# the mysql_native_password auth plugin to cover the legacy-auth code path.
ENV MYSQL_ROOT_PASSWORD=bun \
MYSQL_DATABASE=bun_sql_test \
MYSQL_ROOT_HOST=% \
MYSQL_INITDB_SKIP_TZINFO=1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

RUN set -e; \
docker-entrypoint.sh mysqld \
--datadir=/var/lib/mysql-init \
--default-authentication-plugin=mysql_native_password & pid=$!; \
for i in $(seq 60); do \
mysql -h127.0.0.1 -uroot -pbun -e 'SELECT 1' >/dev/null 2>&1 && break; \
sleep 1; \
done; \
mysql -h127.0.0.1 -uroot -pbun -e 'SELECT 1'; \
mysqladmin -h127.0.0.1 -uroot -pbun shutdown; \
wait "$pid"

CMD ["mysqld", "--datadir=/var/lib/mysql-init", "--default-authentication-plugin=mysql_native_password"]
24 changes: 24 additions & 0 deletions test/docker/Dockerfile.mysql-plain
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM mysql:8.4

Check warning on line 1 in test/docker/Dockerfile.mysql-plain

View check run for this annotation

Claude / Claude Code Review

README Architecture tree missing new mysql Dockerfiles

Nit: `test/docker/README.md`'s Architecture file tree (lines 172-187) enumerates every Dockerfile in this directory but doesn't list the two new `Dockerfile.mysql-*` files this PR adds. Not blocking — the tree already has minor pre-existing drift (`prepare-ci.sh` vs actual `prepare-ci.ts`) — but worth adding two lines while you're here so the directory map stays accurate.
Comment thread
robobun marked this conversation as resolved.
Resolved

# Bake a fully initialized data directory into the image so cold container
# start skips `mysqld --initialize` and the temp-server dance entirely and is
# just `exec mysqld` (~2-3s instead of ~60s). The base image declares
# `VOLUME /var/lib/mysql`, which discards build-time writes there, so
# initialize into a sibling path and point mysqld at it via CMD; at runtime the
# entrypoint sees `$DATADIR/mysql` exists and goes straight to exec. tzinfo
# loading is skipped since no test uses MySQL's named-timezone tables.
ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes \
MYSQL_DATABASE=bun_sql_test \
MYSQL_INITDB_SKIP_TZINFO=1

RUN set -e; \
docker-entrypoint.sh mysqld --datadir=/var/lib/mysql-init & pid=$!; \
for i in $(seq 60); do \
mysql -h127.0.0.1 -uroot -e 'SELECT 1' >/dev/null 2>&1 && break; \
sleep 1; \
done; \
mysql -h127.0.0.1 -uroot -e 'SELECT 1'; \
mysqladmin -h127.0.0.1 -uroot shutdown; \
wait "$pid"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

CMD ["mysqld", "--datadir=/var/lib/mysql-init"]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
54 changes: 26 additions & 28 deletions test/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand All @@ -43,7 +43,7 @@ services:
- /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand All @@ -70,52 +70,55 @@ services:
- /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
start_interval: 1s

# MySQL Services
# These images bake a pre-initialized data dir so cold container start is
# `exec mysqld` (~2-3s) instead of the stock entrypoint's first-boot init
# (`mysqld --initialize` + temp server + tzinfo load, ~60s on loaded CI
# hosts). State lives on the container's CoW layer, so a fresh container is a
# fresh database.
mysql_plain:
image: mysql:8.4
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: bun_sql_test
build:
context: .
dockerfile: Dockerfile.mysql-plain
image: bun-mysql-plain:local
ports:
- target: 3306
published: 0
protocol: tcp
tmpfs:
- /var/lib/mysql
healthcheck:
# 127.0.0.1 (not localhost) forces TCP — `localhost` would use the unix
# socket, which is up during the entrypoint's temporary init server and
# passes the check before the real TCP listener exists. Auth + SELECT 1
# so we don't go healthy until the real server is accepting connections.
test: ["CMD", "mysql", "-h", "127.0.0.1", "-uroot", "-e", "SELECT 1"]
interval: 1h # Effectively disable after startup
# Once start_period elapses the engine probes at `interval`, not
# `start_interval`, so a long interval would wedge health at "starting"
# if init overshot the window; keep interval short so an overshoot on any
# service recovers within one probe.
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
start_interval: 1s

mysql_native_password:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: bun
MYSQL_DATABASE: bun_sql_test
MYSQL_ROOT_HOST: "%"
command: --default-authentication-plugin=mysql_native_password
build:
context: .
dockerfile: Dockerfile.mysql-native-password
image: bun-mysql-native-password:local
ports:
- target: 3306
published: 0
protocol: tcp
tmpfs:
- /var/lib/mysql
healthcheck:
test: ["CMD", "mysql", "-h", "127.0.0.1", "-uroot", "-pbun", "-e", "SELECT 1"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand All @@ -128,18 +131,13 @@ services:
args:
MYSQL_VERSION: 8.4
image: bun-mysql-tls:local
environment:
MYSQL_ROOT_PASSWORD: bun
MYSQL_DATABASE: bun_sql_test
ports:
- target: 3306
published: 0
protocol: tcp
tmpfs:
- /var/lib/mysql
healthcheck:
test: ["CMD", "mysql", "-h", "127.0.0.1", "-uroot", "-pbun", "-e", "SELECT 1"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand Down Expand Up @@ -195,7 +193,7 @@ services:
- /data
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 1h # Effectively disable after startup
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand All @@ -220,7 +218,7 @@ services:
# healthcheck `up --wait` returns at "running" and the test's
# /getCaseCount fetch can hit before the listener exists.
test: ["CMD", "python", "-c", "import socket; socket.create_connection(('127.0.0.1', 9002), 1).close()"]
interval: 1h
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand All @@ -241,7 +239,7 @@ services:
- "host.docker.internal:host-gateway"
healthcheck:
test: ["CMD-SHELL", "pgrep squid > /dev/null"]
interval: 1h
interval: 5s
timeout: 5s
retries: 30
start_period: 60s
Expand Down
12 changes: 7 additions & 5 deletions test/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,13 @@ class DockerComposeHelper {
}

// Start the service and wait for it to be healthy.
// --wait-timeout: without it `--wait` blocks until the engine reports
// healthy, which with `interval: 1h` and an engine that doesn't honor the
// 5s start_interval default means "hang until the test's beforeAll times
// out with no error message". 60 covers cold mysql init on tmpfs.
const { exitCode, stderr } = await this.exec(["up", "-d", "--wait", "--wait-timeout", "60", service]);
// --wait-timeout bounds how long `--wait` blocks for a health transition.
// All services are expected to go healthy within a few seconds (mysql
// images bake a pre-initialized data dir so first boot is just `exec
// mysqld`); 180 is generous headroom so a slow host or a service whose
// init regresses surfaces as a single diagnosable failure here rather than
// cascading through every test file that asks for it.
Comment thread
robobun marked this conversation as resolved.
Resolved
const { exitCode, stderr } = await this.exec(["up", "-d", "--wait", "--wait-timeout", "180", service]);

if (exitCode !== 0) {
const ps = await this.exec(["ps", "-a", service]);
Expand Down
4 changes: 2 additions & 2 deletions test/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,11 @@ export async function describeWithContainer(
_port = info.ports[servicePort];
console.log(`Container ready via docker-compose: ${image} at ${_host}:${_port}`);
readyResolver!();
// Cold container start is bounded by `compose up --wait-timeout 60` plus
// Cold container start is bounded by `compose up --wait-timeout 180` plus
// a `compose build` step; the default 5s hook timeout fires first and the
// runner's auto-killer then SIGTERMs the in-flight compose subprocesses,
// surfacing as bogus `Failed to start service X: ... Creating` errors.
}, 120_000);
}, 240_000);

fn(containerDescriptor);
});
Expand Down
24 changes: 22 additions & 2 deletions test/js/sql/mysql-tls/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# Dockerfile
ARG MYSQL_VERSION=8.4
FROM mysql:${MYSQL_VERSION}

# Bake a fully initialized data directory into the image so cold container
# start is just `exec mysqld` (~2-3s instead of ~60s); see
# test/docker/Dockerfile.mysql-plain for the rationale. This runs before the
# TLS config is copied in so the readiness poll can use plain TCP (the runtime
# config sets require_secure_transport=ON, which would reject it).
ENV MYSQL_ROOT_PASSWORD=bun \
MYSQL_DATABASE=bun_sql_test \
MYSQL_INITDB_SKIP_TZINFO=1

RUN set -e; \
docker-entrypoint.sh mysqld --datadir=/var/lib/mysql-init & pid=$!; \
for i in $(seq 60); do \
mysql -h127.0.0.1 -uroot -pbun -e 'SELECT 1' >/dev/null 2>&1 && break; \
sleep 1; \
done; \
mysql -h127.0.0.1 -uroot -pbun -e 'SELECT 1'; \
mysqladmin -h127.0.0.1 -uroot -pbun shutdown; \
wait "$pid"

# Copy TLS materials + config
# Expect these in the build context:
# ssl/ca.pem
Expand All @@ -18,5 +36,7 @@ RUN chown -R mysql:mysql /etc/mysql/ssl /etc/mysql/conf.d \
&& find /etc/mysql/ssl -type f -name "*.pem" -exec chmod 640 {} \; \
&& printf "[mysqld]\nrequire_secure_transport=ON\n" > /etc/mysql/conf.d/force_tls.cnf

CMD ["mysqld", "--datadir=/var/lib/mysql-init"]

# Expose MySQL
EXPOSE 3306
EXPOSE 3306
4 changes: 2 additions & 2 deletions test/js/valkey/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ if (isEnabled) {
// if (!context.initialized) {
// console.warn("Test initialization failed - tests may be skipped");
// }
// Cold container start is bounded by `compose up --wait-timeout 60` plus
// Cold container start is bounded by `compose up --wait-timeout 180` plus
// a `compose build` step; the default 5s hook timeout fires long before
// that on a cold cache.
}, 120_000);
}, 240_000);
}

if (isEnabled) {
Expand Down
4 changes: 2 additions & 2 deletions test/js/valkey/valkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ for (const connectionType of [ConnectionType.TLS, ConnectionType.TCP]) {
ctx.redis = createClient(connectionType);
}
// setupDockerContainer() may cold-start the redis_unified container
// (compose up --wait-timeout 60); shielded by the file-level beforeAll's
// (compose up --wait-timeout 180); shielded by the file-level beforeAll's
// cached promise once that has run, but match its timeout for safety.
}, 120_000);
}, 240_000);

beforeEach(async () => {
if (!ctx.redis) {
Expand Down
4 changes: 2 additions & 2 deletions test/js/web/websocket/autobahn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ describe.skipIf(!isDockerEnabled())("autobahn", () => {
wsOptions = process.env.BUN_AUTOBAHN_HOST_HEADER
? { headers: { Host: process.env.BUN_AUTOBAHN_HOST_HEADER } }
: undefined;
// Cold container start is bounded by `compose up --wait-timeout 60` plus
// Cold container start is bounded by `compose up --wait-timeout 180` plus
// a `compose build` step; the default 5s hook timeout fires long before
// that on a cold cache.
}, 120_000);
}, 240_000);

function getCaseStatus(testID: number) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion test/js/web/websocket/websocket-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe.skipIf(!isDockerEnabled())("WebSocket through Squid proxy (Docker)", ()
console.log("Starting squid proxy container...");
squidInfo = await dockerCompose.ensure("squid");
console.log(`Squid proxy ready at: ${squidInfo.host}:${squidInfo.ports[3128]}`);
}, 120_000);
}, 240_000);

afterAll(async () => {
if (!process.env.BUN_KEEP_DOCKER) {
Expand Down
Loading