2021-09-09 10:59:04 +03:00
|
|
|
#!/usr/bin/env bash
|
2021-04-08 18:02:56 +03:00
|
|
|
### This file is not meant to be run directly, but to be sourced from
|
|
|
|
### the dev script. It defines all the functions required to run an
|
|
|
|
### MSSQL docker container.
|
|
|
|
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Configuration #
|
|
|
|
######################
|
|
|
|
|
|
|
|
if [ "$MODE" = "test" ]; then
|
|
|
|
MSSQL_PORT=31433
|
|
|
|
else
|
|
|
|
MSSQL_PORT=21433
|
|
|
|
fi
|
|
|
|
|
2021-11-25 13:22:55 +03:00
|
|
|
MSSQL_HOST=127.0.0.1
|
2021-04-08 18:02:56 +03:00
|
|
|
MSSQL_PASSWORD=hasuraMSSQL1
|
2022-08-04 13:08:54 +03:00
|
|
|
MSSQL_VOLUME_NAME='hasura-dev-mssql'
|
2021-04-08 18:02:56 +03:00
|
|
|
MSSQL_CONTAINER_NAME="hasura-dev-mssql-$MSSQL_PORT"
|
2022-08-04 13:08:54 +03:00
|
|
|
# shellcheck disable=SC2034 # this variable is used in scripts sourcing this one
|
2021-11-25 13:22:55 +03:00
|
|
|
MSSQL_CONN_STR="DRIVER={ODBC Driver 17 for SQL Server};SERVER=$MSSQL_HOST,$MSSQL_PORT;Uid=sa;Pwd=$MSSQL_PASSWORD;"
|
2021-06-14 10:30:52 +03:00
|
|
|
MSSQL_DOCKER="docker exec -it $MSSQL_CONTAINER_NAME sqlcmd -S localhost -U sa -P $MSSQL_PASSWORD"
|
2021-04-08 18:02:56 +03:00
|
|
|
|
2022-08-04 13:08:54 +03:00
|
|
|
if [[ "$(uname -m)" == 'arm64' ]]; then
|
2021-11-24 12:58:10 +03:00
|
|
|
MSSQL_PLATFORM=linux/arm64
|
|
|
|
MSSQL_CONTAINER_IMAGE=mcr.microsoft.com/azure-sql-edge
|
|
|
|
else
|
|
|
|
MSSQL_PLATFORM=linux/amd64
|
|
|
|
MSSQL_CONTAINER_IMAGE=hasura/mssql-server-2019-cu10-ubuntu-20.04:latest
|
|
|
|
fi
|
2021-04-08 18:02:56 +03:00
|
|
|
|
|
|
|
######################
|
|
|
|
# Functions #
|
|
|
|
######################
|
|
|
|
|
2022-08-04 13:08:54 +03:00
|
|
|
function mssql_launch_container {
|
2021-04-08 18:02:56 +03:00
|
|
|
echo_pretty "Launching MSSQL container: $MSSQL_CONTAINER_NAME"
|
2022-08-04 13:08:54 +03:00
|
|
|
docker volume create "$MSSQL_VOLUME_NAME"
|
|
|
|
docker run \
|
|
|
|
--name $MSSQL_CONTAINER_NAME \
|
2021-11-24 12:58:10 +03:00
|
|
|
--platform "$MSSQL_PLATFORM" \
|
2022-08-04 13:08:54 +03:00
|
|
|
--publish="${MSSQL_HOST}:${MSSQL_PORT}:1433" \
|
|
|
|
--volume="${MSSQL_VOLUME_NAME}:/var/opt/mssql" \
|
|
|
|
--env=ACCEPT_EULA=1 \
|
|
|
|
--env="MSSQL_SA_PASSWORD=$MSSQL_PASSWORD" \
|
|
|
|
--detach \
|
|
|
|
"$MSSQL_CONTAINER_IMAGE"
|
2021-04-08 18:02:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function mssql_wait {
|
|
|
|
echo -n "Waiting for mssql to come up"
|
|
|
|
until ( $MSSQL_DOCKER -Q 'SELECT 1' ) &>/dev/null; do
|
|
|
|
echo -n '.' && sleep 0.2
|
|
|
|
done
|
|
|
|
echo " Ok"
|
|
|
|
}
|
|
|
|
|
2022-08-04 13:08:54 +03:00
|
|
|
function mssql_cleanup {
|
2021-04-08 18:02:56 +03:00
|
|
|
echo_pretty "Removing $MSSQL_CONTAINER_NAME and its volumes in 5 seconds!"
|
|
|
|
echo_pretty " PRESS CTRL-C TO ABORT removal of all containers, or ENTER to clean up right away"
|
2021-09-09 10:59:04 +03:00
|
|
|
read -rt5 || true
|
2021-04-08 18:02:56 +03:00
|
|
|
docker stop "$MSSQL_CONTAINER_NAME"
|
|
|
|
docker rm -v "$MSSQL_CONTAINER_NAME"
|
2022-08-04 13:08:54 +03:00
|
|
|
docker volume rm "$MSSQL_VOLUME_NAME"
|
2021-04-08 18:02:56 +03:00
|
|
|
}
|