Skip to content

Commit

Permalink
use custom Docker MS SQL server img
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebruyn committed Sep 13, 2022
1 parent f6ded44 commit 49f9ff0
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 218 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
msodbc_version: ["17", "18"]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}:${{ matrix.python_version }}-msodbc${{ matrix.msodbc_version }}
image: ghcr.io/${{ github.repository }}:CI-${{ matrix.python_version }}-msodbc${{ matrix.msodbc_version }}
steps:
- name: AZ CLI login
run: az login --service-principal --username="${AZURE_CLIENT_ID:}" --password="${AZURE_CLIENT_SECRET:}" --tenant="${AZURE_TENANT_ID:}"
Expand All @@ -41,7 +41,7 @@ jobs:
DBT_AZURESQL_DB: ${{ secrets.DBT_AZURESQL_DB }}
DBT_AZURESQL_UID: ${{ secrets.DBT_AZURESQL_UID }}
DBT_AZURESQL_PWD: ${{ secrets.DBT_AZURESQL_PWD }}
run: python devops/wakeup_azure.py
run: python devops/scripts/wakeup_azure.py

- name: Configure test users
run: sqlcmd -b -I -i devops/create_sql_users.sql
Expand Down
20 changes: 8 additions & 12 deletions .github/workflows/integration-tests-sqlserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,25 @@ jobs:
sqlserver_version: ["2017", "2019", "2022"]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}:${{ matrix.python_version }}-msodbc${{ matrix.msodbc_version }}
image: ghcr.io/${{ github.repository }}:CI-${{ matrix.python_version }}-msodbc${{ matrix.msodbc_version }}
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:${{ matrix.sqlserver_version }}-latest
image: ghcr.io/${{ github.repository }}:server-${{ matrix.sqlserver_version }}
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: 5atyaNadella
steps:
- uses: actions/checkout@v3

- name: Configure test users
run: sqlcmd -b -I -i devops/create_sql_users.sql
env:
DBT_TEST_USER_1: DBT_TEST_USER_1
DBT_TEST_USER_2: DBT_TEST_USER_2
DBT_TEST_USER_3: DBT_TEST_USER_3
SQLCMDUSER: SA
SQLCMDPASSWORD: 5atyaNadella
SQLCMDSERVER: sqlserver
SQLCMDDBNAME: msdb
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: pip install -r dev_requirements.txt

- name: Run functional tests
run: pytest tests/functional --profile "${{ matrix.profile }}"
env:
DBT_TEST_USER_1: DBT_TEST_USER_1
DBT_TEST_USER_2: DBT_TEST_USER_2
DBT_TEST_USER_3: DBT_TEST_USER_3
39 changes: 34 additions & 5 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ name: Publish Docker images for CI/CD
on: # yamllint disable-line rule:truthy
push:
paths:
- 'devops/Dockerfile'
- 'devops/**'
- '.github/workflows/publish-docker.yml'
branches:
- 'master'

jobs:
publish-docker:
publish-docker-client:
strategy:
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10"]
Expand All @@ -29,13 +29,42 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker images
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
build-args: PYTHON_VERSION=${{ matrix.python_version }}
file: devops/Dockerfile
file: devops/CI.Dockerfile
push: true
platforms: linux/amd64
target: ${{ matrix.docker_target }}
tags: ghcr.io/${{ github.repository }}:${{ matrix.python_version }}-${{ matrix.docker_target }}
tags: ghcr.io/${{ github.repository }}:CI-${{ matrix.python_version }}-${{ matrix.docker_target }}

publish-docker-server:
strategy:
matrix:
mssql_version: ["2017", "2019", "2022"]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
build-args: MSSQL_VERSION=${{ matrix.mssql_version }}
file: devops/server.Dockerfile
push: true
platforms: linux/amd64
tags: ghcr.io/${{ github.repository }}:server-${{ matrix.mssql_version }}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
IF NOT EXISTS(SELECT * FROM sys.database_principals WHERE name = '$(DBT_TEST_USER_1)')
CREATE USER [$(DBT_TEST_USER_1)] WITHOUT LOGIN;

IF NOT EXISTS(SELECT * FROM sys.database_principals WHERE name = '$(DBT_TEST_USER_2)')
CREATE USER [$(DBT_TEST_USER_2)] WITHOUT LOGIN;

IF NOT EXISTS(SELECT * FROM sys.database_principals WHERE name = '$(DBT_TEST_USER_3)')
CREATE USER [$(DBT_TEST_USER_3)] WITHOUT LOGIN;
3 changes: 3 additions & 0 deletions devops/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

/opt/init_scripts/init_db.sh & /opt/mssql/bin/sqlservr
14 changes: 14 additions & 0 deletions devops/scripts/init_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

for i in {1..50};
do
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${SA_PASSWORD}" -d msdb -I -i create_sql_users.sql
if [ $? -eq 0 ]
then
echo "create_sql_users.sql completed"
break
else
echo "not ready yet..."
sleep 1
fi
done
File renamed without changes.
10 changes: 10 additions & 0 deletions devops/server.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG MSSQL_VERSION="2022"
FROM mcr.microsoft.com/mssql/server:${MSSQL_VERSION}-latest

USER root
RUN mkdir -p /opt/init_scripts
WORKDIR /opt/init_scripts
COPY scripts/* /opt/init_scripts/

USER mssql
ENTRYPOINT /bin/bash ./entrypoint.sh
182 changes: 0 additions & 182 deletions devops/wait-for-it.sh

This file was deleted.

24 changes: 7 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
build:
context: devops
dockerfile: server.Dockerfile
args:
MSSQL_VERSION: "2022"
environment:
SA_PASSWORD: "L0calTesting!"
ACCEPT_EULA: "Y"
ports:
- "1433:1433"

init-db:
image: mcr.microsoft.com/mssql/server:2022-latest
depends_on:
- sqlserver
restart: 'no'
volumes:
- ./devops:/mnt/scripts
environment:
SQLCMDUSER: SA
SQLCMDPASSWORD: "L0calTesting!"
SQLCMDSERVER: sqlserver
SQLCMDDBNAME: msdb
env_file:
- test.env
command: sh -c "/mnt/scripts/wait-for-it.sh sqlserver:1433 -t 60 -- sleep 5 && /opt/mssql-tools/bin/sqlcmd -b -I -i /mnt/scripts/create_sql_users.sql"
ports:
- "1433:1433"

0 comments on commit 49f9ff0

Please sign in to comment.