From 0ae9e288841bbc2c5e131569736819c01d5dd8a6 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Wed, 24 Nov 2021 19:08:36 +0100 Subject: [PATCH] Use Azure SQL Edge for development (#1709) --- dev/.env.example | 2 ++ dev/docker-compose.yml | 8 ++++---- dev/helpers/mssql/run_migrations.sh | 8 ++++---- dev/migrate.ps1 | 16 +++++++++++++++- 4 files changed, 25 insertions(+), 9 deletions(-) mode change 100644 => 100755 dev/helpers/mssql/run_migrations.sh mode change 100644 => 100755 dev/migrate.ps1 diff --git a/dev/.env.example b/dev/.env.example index 68d33e07f..7cfd5bb79 100644 --- a/dev/.env.example +++ b/dev/.env.example @@ -1,3 +1,5 @@ COMPOSE_PROJECT_NAME=BitwardenServer +# Ensure the MSSQL_PASSWORD is complex and follows the password policy defined at +# https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 MSSQL_PASSWORD=SET_A_PASSWORD_HERE_123 MAILCATCHER_PORT=1080 diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index 27a90c668..5e7381cf3 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -2,14 +2,14 @@ version: "3.9" services: mssql: - image: mcr.microsoft.com/mssql/server:2017-latest + image: mcr.microsoft.com/azure-sql-edge:latest restart: always environment: ACCEPT_EULA: Y - SA_PASSWORD: ${MSSQL_PASSWORD} + MSSQL_SA_PASSWORD: ${MSSQL_PASSWORD} MSSQL_PID: Developer volumes: - - mssql_dev_data:/var/opt/mssql/data + - edgesql_dev_data:/var/opt/mssql - ../util/Migrator:/mnt/migrator/ - ./helpers/mssql:/mnt/helpers - ./.data/mssql:/mnt/data @@ -40,4 +40,4 @@ services: - mail volumes: - mssql_dev_data: + edgesql_dev_data: diff --git a/dev/helpers/mssql/run_migrations.sh b/dev/helpers/mssql/run_migrations.sh old mode 100644 new mode 100755 index 069252706..97cd4b69a --- a/dev/helpers/mssql/run_migrations.sh +++ b/dev/helpers/mssql/run_migrations.sh @@ -7,10 +7,10 @@ sleep 0.1; MIGRATE_DIRECTORY="/mnt/migrator/DbScripts" LAST_MIGRATION_FILE="/mnt/data/last_migration" -SERVER='localhost' +SERVER='mssql' DATABASE="vault_dev" USER="SA" -PASSWD=$SA_PASSWORD +PASSWD=$MSSQL_PASSWORD if [ ! -f "$LAST_MIGRATION_FILE" ]; then echo "$LAST_MIGRATION_FILE not found!" @@ -43,9 +43,9 @@ if [ -n "$RERUN" ]; then fi # Create database if it does not already exist -QUERY="IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'vault_dev') +QUERY="IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '$DATABASE') BEGIN - CREATE DATABASE vault_dev; + CREATE DATABASE $DATABASE; END;" /opt/mssql-tools/bin/sqlcmd -S $SERVER -d master -U $USER -P $PASSWD -I -Q "$QUERY" diff --git a/dev/migrate.ps1 b/dev/migrate.ps1 old mode 100644 new mode 100755 index 3100869cc..46a2aa412 --- a/dev/migrate.ps1 +++ b/dev/migrate.ps1 @@ -1,4 +1,18 @@ #!/usr/bin/env pwsh # Creates the vault_dev database, and runs all the migrations. -docker-compose --profile mssql exec mssql bash /mnt/helpers/run_migrations.sh @args +# Due to azure-edge-sql not containing the mssql-tools on ARM, we manually use +# the mssql-tools container which runs under x86_64. We should monitor this +# in the future and investigate if we can migrate back. +# docker-compose --profile mssql exec mssql bash /mnt/helpers/run_migrations.sh @args + +docker run ` + -v "$(pwd)/helpers/mssql:/mnt/helpers" ` + -v "$(pwd)/../util/Migrator:/mnt/migrator/" ` + -v "$(pwd)/.data/mssql:/mnt/data" ` + --env-file .env ` + --network=bitwardenserver_default ` + --rm ` + -it ` + mcr.microsoft.com/mssql-tools ` + /mnt/helpers/run_migrations.sh @args