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
|
2022-10-21 19:23:01 +03:00
|
|
|
MSSQL_CONN_STR="DRIVER={ODBC Driver 18 for SQL Server};SERVER=$MSSQL_HOST,$MSSQL_PORT;Uid=sa;Pwd=$MSSQL_PASSWORD;Encrypt=optional"
|
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
|
2022-10-06 18:48:51 +03:00
|
|
|
MSSQL_CONTAINER_IMAGE=mcr.microsoft.com/mssql/server:2019-latest
|
2021-11-24 12:58:10 +03:00
|
|
|
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"
|
2022-12-08 12:59:09 +03:00
|
|
|
until ( docker run --rm -it --net=host mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd -S "${MSSQL_HOST},${MSSQL_PORT}" -U SA -P "$MSSQL_PASSWORD" -Q 'SELECT 1' ) &>/dev/null; do
|
2021-04-08 18:02:56 +03:00
|
|
|
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
|
|
|
}
|