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

[DOP-15547] Use official MSSQL docker image #266

Merged
merged 1 commit into from
May 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions .env.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ MONGO_INITDB_ROOT_USERNAME=onetl
MONGO_INITDB_ROOT_PASSWORD=E4j7h!9A

# MSSQL
MSSQL_DB=onetl
MSSQL_USER=onetl
MSSQL_PASSWORD=7ellowEl7akey
ACCEPT_EULA=Y
SA_PASSWORD=2astazeY
MSSQL_SA_PASSWORD=2astazeY

# MySQL
MYSQL_ROOT_PASSWORD=ohbuz9Eochaj9saibooK3thooGa5aesh
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/data/mssql/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ latest: &latest

matrix:
small:
- mssql-version: v2017.CU24.0
- mssql-version: 2022-CU12-ubuntu-22.04
<<: *max
full:
- mssql-version: v2017.CU24.0
- mssql-version: 2017-GA-ubuntu
<<: *min
# v2019.CU4.0 is not very stable
- mssql-version: v2017.CU24.0
- mssql-version: 2022-CU12-ubuntu-22.04
<<: *max
nightly:
- mssql-version: v2017.CU24.0
- mssql-version: 2017-GA-ubuntu
<<: *min
- mssql-version: v2017.CU24.0
- mssql-version: latest
<<: *latest
26 changes: 14 additions & 12 deletions .github/workflows/test-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ jobs:
test-mssql:
name: Run MSSQL tests (server=${{ inputs.mssql-version }}, spark=${{ inputs.spark-version }}, pydantic=${{ inputs.pydantic-version }}, java=${{ inputs.java-version }}, python=${{ inputs.python-version }}, os=${{ inputs.os }})
runs-on: ${{ inputs.os }}
services:
mssql:
image: mcmoe/mssqldocker:${{ inputs.mssql-version }}
env:
TZ: UTC
MSSQL_DB: onetl
MSSQL_USER: onetl
MSSQL_PASSWORD: 7ellowEl7akey
ACCEPT_EULA: Y
SA_PASSWORD: 2astazeY
ports:
- 1433:1433

steps:
- name: Checkout code
Expand Down Expand Up @@ -84,13 +72,27 @@ jobs:
run: |
pip install -I -r requirements/core.txt -r requirements/tests/base.txt -r requirements/tests/mssql.txt -r requirements/tests/spark-${{ inputs.spark-version }}.txt -r requirements/tests/pydantic-${{ inputs.pydantic-version }}.txt

# Cannot use services because we need to mount config file from the repo, but services start before checkout.
# See https://github.com/orgs/community/discussions/25792
- name: Start MSSQL
run: |
docker compose down -v --remove-orphans
docker compose up -d mssql --wait --wait --wait-timeout 200
env:
MSSQL_IMAGE: mcr.microsoft.com/mssql/server:${{ inputs.mssql-version }}

- name: Run tests
run: |
mkdir reports/ || echo "Directory exists"
sed '/^$/d' ./.env.local | sed '/^#/d' | sed 's/^/export /' > ./env
source ./env
./pytest_runner.sh -m mssql

- name: Shutdown MSSQL
if: always()
run: |
docker compose down -v --remove-orphans

- name: Upload coverage results
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.11
python: python3.12

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ services:
- onetl

mssql:
image: ${MSSQL_IMAGE:-mcmoe/mssqldocker:latest}
image: ${MSSQL_IMAGE:-mcr.microsoft.com/mssql/server:latest}
restart: unless-stopped
env_file: .env.dependencies
ports:
- 1433:1433
volumes:
- ./docker/mssql/:/usr/config/
entrypoint: ["/usr/config/entrypoint.sh"]
networks:
- onetl
platform: linux/amd64
Expand Down
36 changes: 36 additions & 0 deletions docker/mssql/configure-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -o pipefail

# Wait 60 seconds for SQL Server to start up by ensuring that
# calling SQLCMD does not return an error code, which will ensure that sqlcmd is accessible
# and that system and user databases return "0" which means all databases are in an "online" state
# https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql?view=sql-server-2017

declare DBSTATUS
declare ERRCODE
TIMEOUT=60
START=$(date +%s)
echo "Configure DB script started at $(date)"

while true; do
DELTA=$(($(date +%s) - START))
if [[ $DELTA -gt $TIMEOUT ]]; then
echo "ERROR: SQL Server took more than ${TIMEOUT} seconds to START up or one or more databases are not in an ONLINE state"
exit 1
fi

DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P ${MSSQL_SA_PASSWORD} -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases" 2>/dev/null | sed -e 's/^[[:space:]]*//')
ERRCODE=$?
if [[ "$DBSTATUS" -eq "0" && "$ERRCODE" -eq "0" ]]; then
echo "INFO: Database ready."
break
else
echo "INFO: Waiting for database to be ready..."
sleep 1
fi
done

# Run the setup script to create the DB and the schema in the DB
echo "Running setup.sql";
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQL_SA_PASSWORD -d master -i /usr/config/setup.sql;
echo "Success";
7 changes: 7 additions & 0 deletions docker/mssql/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Start the script to create the DB and user
/usr/config/configure-db.sh &

# Start SQL Server
/opt/mssql/bin/sqlservr
20 changes: 20 additions & 0 deletions docker/mssql/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*

Enter custom T-SQL here that would run after SQL Server has started up.

*/

CREATE DATABASE onetl;
GO

USE onetl;
GO

CREATE LOGIN onetl WITH PASSWORD = '7ellowEl7akey';
GO

CREATE USER onetl FOR LOGIN onetl;
GO

GRANT CONTROL ON DATABASE::onetl TO onetl;
GO