Skip to content

Commit

Permalink
Add unixodbc docker to test on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrainman committed Aug 10, 2024
1 parent 1b0af60 commit bcbcb68
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
47 changes: 45 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ help:

MSSQL_CONTAINER_NAME=mssql_test
MSSQL_SA_PASSWORD=$(PASSWORD)
MSSQL_NETWORK=mssqlnetwork
MSSQL_DRIVER_NAME=ODBC Driver 17 for SQL Server

start-mssql:
docker network create ${MSSQL_NETWORK}
docker run \
--name $(MSSQL_CONTAINER_NAME) \
--hostname $(MSSQL_CONTAINER_NAME) \
-e 'ACCEPT_EULA=Y' \
-e 'MSSQL_SA_PASSWORD=$(MSSQL_SA_PASSWORD)' \
-d \
-p 1433:1433 \
--network=${MSSQL_NETWORK} \
mcr.microsoft.com/mssql/server:2022-latest
echo -n "starting $(MSSQL_CONTAINER_NAME) "; \
while ! \
Expand All @@ -34,15 +38,54 @@ start-mssql:
-Q 'create database $(DB_NAME)' >/dev/null 2>&1 ; \
do echo -n .; sleep 2; done; echo " done"

build-unixodbc:
docker build \
-t unixodbc \
-f unixodbc.Dockerfile \
.

test-mssql:
go test -v -mssrv=localhost -msdb=$(DB_NAME) -msuser=sa -mspass=$(MSSQL_SA_PASSWORD) -run=TestMSSQL
docker run \
-it \
--network=${MSSQL_NETWORK} \
-v .:/src \
unixodbc \
sh /src/mssqltest.sh \
"$(MSSQL_DRIVER_NAME)" \
"$(MSSQL_CONTAINER_NAME)" \
"$(DB_NAME)" \
"$(MSSQL_SA_PASSWORD)"

test-mssql-freetds:
docker run \
-it \
--network=${MSSQL_NETWORK} \
-v .:/src \
unixodbc \
sh /src/mssqltest.sh \
"freetds" \
"$(MSSQL_CONTAINER_NAME)" \
"$(DB_NAME)" \
"$(MSSQL_SA_PASSWORD)"


test-mssql-race:
go test -v -mssrv=localhost -msdb=$(DB_NAME) -msuser=sa -mspass=$(MSSQL_SA_PASSWORD) -run=TestMSSQL --race
docker run \
-it \
--network=${MSSQL_NETWORK} \
-v .:/src \
unixodbc \
sh /src/mssqltest.sh \
"$(MSSQL_DRIVER_NAME)" \
"$(MSSQL_CONTAINER_NAME)" \
"$(DB_NAME)" \
"$(MSSQL_SA_PASSWORD)" \
"--race"

stop-mssql:
docker stop $(MSSQL_CONTAINER_NAME)
docker rm $(MSSQL_CONTAINER_NAME)
docker network rm ${MSSQL_NETWORK}

# MySQL

Expand Down
49 changes: 49 additions & 0 deletions mssqltest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
#set -e

MSSQL_DRIVER_NAME="$1"
MSSQL_CONTAINER_NAME="$2"
DB_NAME="$3"
MSSQL_SA_PASSWORD="$4"
RACE="$5"

pwd

echo $PATH

go version

#sqlcmd -S localhost
#sqlcmd -?

# install freetds driver
cat << EOF > tds.driver.template
[FreeTDS]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
EOF
odbcinst -i -d -f tds.driver.template
cat tds.driver.template
rm tds.driver.template

# install microsoft driver
odbcinst -q -d -n "${MSSQL_DRIVER_NAME}" > tds.driver.template
odbcinst -i -d -f tds.driver.template
cat tds.driver.template
rm tds.driver.template

echo "MSSQL_DRIVER_NAME=${MSSQL_DRIVER_NAME}"
echo "MSSQL_CONTAINER_NAME=${MSSQL_CONTAINER_NAME}"
echo "DB_NAME=${DB_NAME}"
echo "MSSQL_SA_PASSWORD=${MSSQL_SA_PASSWORD}"
echo "RACE=${RACE}"

# add 1433 to mssrv parameter so we do not skip TestMSSQLReconnect

go test -v \
-msdriver="${MSSQL_DRIVER_NAME}" \
-mssrv=${MSSQL_CONTAINER_NAME},1433 \
-msdb=${DB_NAME} \
-msuser=sa \
-mspass=${MSSQL_SA_PASSWORD} \
${RACE} \
-run=TestMSSQL
31 changes: 31 additions & 0 deletions unixodbc.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ubuntu:18.04

RUN apt update -y && apt upgrade -y && apt-get update
RUN apt install -y curl python3.7 git python3-pip openjdk-8-jdk unixodbc-dev

# Add SQL Server ODBC Driver 17 for Ubuntu 18.04
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
ENV PATH ${PATH}:/opt/mssql-tools/bin

# download freetds driver
RUN apt-get install -y unixodbc freetds-dev freetds-bin tdsodbc

# download go tar
RUN curl --location https://go.dev/dl/go1.20.linux-amd64.tar.gz | tar -C /usr/local -xzf -
RUN echo 'export PATH="/usr/local/go/bin:$PATH"' >> ~/.bash_profile
RUN echo 'export PATH="/usr/local/go/bin:$PATH"' >> ~/.bashrc
ENV PATH /usr/local/go/bin:${PATH}

WORKDIR /src

#COPY mssqltest.sh /
#RUN chmod +x /mssqltest.sh
#ENTRYPOINT ["sh","/mssqltest.sh"]
#ENTRYPOINT ["sh"]
CMD ["sh"]

0 comments on commit bcbcb68

Please sign in to comment.