diff --git a/.github/workflows/sqlx.yml b/.github/workflows/sqlx.yml index 5162d034b9..332bb62ab2 100644 --- a/.github/workflows/sqlx.yml +++ b/.github/workflows/sqlx.yml @@ -6,6 +6,12 @@ on: branches: - main +# Tests and the ODBC DSN use these fixed ports; local Compose runs use random ports. +env: + SQLX_POSTGRES_PORT: "5432" + SQLX_MYSQL_PORT: "3306" + SQLX_MSSQL_PORT: "1433" + jobs: format: name: Format @@ -167,8 +173,7 @@ jobs: RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} - run: | - docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }} postgres_${{ matrix.postgres }} - docker exec postgres_${{ matrix.postgres }} bash -c "until pg_isready; do sleep 1; done" + docker compose -f tests/docker-compose.yml up --wait --wait-timeout 120 postgres_${{ matrix.postgres }} - run: | cargo test --no-default-features --features any,postgres,macros,all-types,${{ matrix.tls }} @@ -185,6 +190,9 @@ jobs: # FIXME: needed to disable `ltree` tests in Postgres 9.6 # but `PgLTree` should just fall back to text format RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 postgres_ssl_client_cert: name: Postgres with SSL client cert @@ -197,11 +205,14 @@ jobs: prefix-key: v1-sqlx shared-key: postgres-rustls save-if: ${{ false }} - - run: docker compose up --wait postgres_16 + - run: docker compose up --wait --wait-timeout 120 postgres_16 working-directory: tests - run: cargo test --no-default-features --features any,postgres,macros,all-types,rustls env: DATABASE_URL: postgres://postgres@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=./tests/certs/ca.crt&sslcert=./tests/certs/client.crt&sslkey=./tests/keys/client.key + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 mysql: name: MySQL @@ -230,8 +241,7 @@ jobs: --features mysql,all-types,${{ matrix.tls }},macros,migrate \ -- -D warnings - - run: docker compose -f tests/docker-compose.yml run -d -p 3306:3306 mysql_${{ matrix.mysql }} - - run: sleep 60 + - run: docker compose -f tests/docker-compose.yml up --wait --wait-timeout 120 mysql_${{ matrix.mysql }} - run: | cargo test --no-default-features --features any,mysql,macros,migrate,all-types,${{ matrix.tls }} @@ -244,6 +254,9 @@ jobs: if: ${{ !(matrix.mysql == '5_7' && matrix.tls == 'rustls') }} env: DATABASE_URL: mysql://root:password@localhost:3306/sqlx + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 mariadb: name: MariaDB @@ -272,13 +285,15 @@ jobs: --features mysql,${{ matrix.tls }},macros,migrate \ -- -D warnings - - run: docker compose -f tests/docker-compose.yml run -d -p 3306:3306 mariadb_${{ matrix.mariadb }} - - run: sleep 30 + - run: docker compose -f tests/docker-compose.yml up --wait --wait-timeout 120 mariadb_${{ matrix.mariadb }} - run: | cargo test --no-default-features --features any,mysql,macros,migrate,${{ matrix.tls }} env: DATABASE_URL: mysql://root:password@localhost:3306/sqlx + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 mssql: name: MSSQL @@ -307,13 +322,15 @@ jobs: --features mssql,all-types,${{ matrix.tls }},macros,migrate \ -- -D warnings - - run: docker compose -f tests/docker-compose.yml run -d -p 1433:1433 mssql_${{ matrix.mssql }} - - run: sleep 80 # MSSQL takes a "bit" to startup + - run: docker compose -f tests/docker-compose.yml up --wait --wait-timeout 120 mssql_${{ matrix.mssql }} - run: | cargo test --no-default-features --features any,mssql,macros,migrate,all-types,${{ matrix.tls }} env: DATABASE_URL: mssql://sa:Password123!@localhost/sqlx + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 odbc: name: ODBC (PostgreSQL and SQLite) @@ -329,8 +346,7 @@ jobs: save-if: ${{ github.ref == 'refs/heads/main' }} - name: Start Postgres (no SSL) run: | - docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_16_no_ssl postgres_16_no_ssl - docker exec postgres_16_no_ssl bash -c "until pg_isready; do sleep 1; done" + docker compose -f tests/docker-compose.yml up --wait --wait-timeout 120 postgres_16_no_ssl - name: Install unixODBC and ODBC drivers (PostgreSQL, SQLite) run: | sudo apt-get update @@ -349,3 +365,6 @@ jobs: run: cargo test --no-default-features --features any,odbc,macros,all-types,rustls env: DATABASE_URL: Driver={SQLite3};Database=./tests/odbc/sqlite.db + - name: Show database logs on failure + if: failure() + run: docker compose -f tests/docker-compose.yml logs --tail 100 diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index ee394cbda5..f3c9ebb6ec 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -5,22 +5,28 @@ services: # mysql_8: + healthcheck: &mysql-health + test: ["CMD", "mysql", "--protocol=TCP", "-h", "127.0.0.1", "-uroot", "-ppassword", "sqlx", "-e", "SELECT 1 FROM tweet LIMIT 0"] + interval: 2s + timeout: 5s + retries: 60 image: mysql:8 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_HOST: '%' MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: sqlx mysql_5_7: + healthcheck: *mysql-health image: mysql:5.7 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_HOST: '%' MYSQL_ROOT_PASSWORD: password @@ -31,41 +37,45 @@ services: # mariadb_10_6: + healthcheck: *mysql-health image: mariadb:10.6 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: sqlx mariadb_10_5: + healthcheck: *mysql-health image: mariadb:10.5 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: sqlx mariadb_10_4: + healthcheck: *mysql-health image: mariadb:10.4 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: sqlx mariadb_10_3: + healthcheck: *mysql-health image: mariadb:10.3 volumes: - "./mysql/setup.sql:/docker-entrypoint-initdb.d/setup.sql" ports: - - 3306 + - "127.0.0.1:${SQLX_MYSQL_PORT:-}:3306" environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: sqlx @@ -76,6 +86,11 @@ services: # postgres_16: # Test postgres 16 with required client cert + healthcheck: &postgres-health + test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "postgres", "-d", "sqlx"] + interval: 2s + timeout: 5s + retries: 60 build: context: . dockerfile: postgres/Dockerfile @@ -87,21 +102,20 @@ services: POSTGRES_DB: sqlx POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_INITDB_ARGS: --auth-host=trust - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] volumes: - "./postgres/setup.sql:/docker-entrypoint-initdb.d/setup.sql" command: > -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key -c ssl_ca_file=/var/lib/postgresql/ca.crt -c hba_file=/var/lib/postgresql/pg_hba.conf postgres_14: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 14 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -114,13 +128,14 @@ services: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key postgres_13: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 13 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -133,13 +148,14 @@ services: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key postgres_12: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 12 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -152,13 +168,14 @@ services: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key postgres_11: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 11 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -171,13 +188,14 @@ services: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key postgres_10: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 10 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -190,13 +208,14 @@ services: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key postgres_16_no_ssl: + healthcheck: *postgres-health build: context: . dockerfile: postgres/Dockerfile args: VERSION: 16 ports: - - 5432 + - "127.0.0.1:${SQLX_POSTGRES_PORT:-}:5432" environment: POSTGRES_DB: sqlx POSTGRES_USER: postgres @@ -213,25 +232,36 @@ services: # mssql_2019: + healthcheck: &mssql-health + test: + - CMD-SHELL + - >- + /opt/mssql-tools18/bin/sqlcmd -S tcp:127.0.0.1,1433 + -U sa -P "$$SA_PASSWORD" -d sqlx + -Q 'SELECT TOP 0 * FROM dbo.tweet' -b -C -l 2 + interval: 2s + timeout: 5s + retries: 60 build: context: . dockerfile: mssql/Dockerfile args: VERSION: 2019-latest ports: - - 1433 + - "127.0.0.1:${SQLX_MSSQL_PORT:-}:1433" environment: ACCEPT_EULA: "Y" SA_PASSWORD: Password123! mssql_2022: + healthcheck: *mssql-health build: context: . dockerfile: mssql/Dockerfile args: VERSION: 2022-latest ports: - - 1433 + - "127.0.0.1:${SQLX_MSSQL_PORT:-}:1433" volumes: - "./mssql/mssql.conf:/var/opt/mssql/mssql.conf" environment: