Skip to content
Chris Bono edited this page Dec 21, 2023 · 3 revisions

MSSQL on Mac ARM64

There is currently no Microsoft SQL Server (MSSQL) readily available that can run on ARM64 architecture (Mac M1/M2). This makes it impossible for developers using these computers to exercise MSSQL functionality/tests locally. This guide show how to work around this limitation.

Overview

The solution is to run a tool (Colima) that allows you to spin up x86_64 software on Apple M chips and then start the container as you normally would (docker run or via Testcontainers).

Steps

Pre-requisites

Verify Homebrew

⚠️
If Homebrew is not installed properly for M1/M2 you will run into issues w/ Colima.

Execute which homebrew and…​

  • if the result is empty then install Homebrew

  • if the result is under /usr/local/bin then uninstall and then install Homebrew

  • if the result is under /opt/homebrew skip to next step

Install Colima

Execute brew install colima

Run Colima

No matter where you are running the container from, you must always have Colima started prior to running the container.

  • Run Colima w/ the following command:

    colima start --arch x86_64 --memory 4

Run MSSQL container in Docker

  • Ensure Colima is started (above)

  • Start the container w/ the following command:

    docker run --name test-mssql --hostname test-mssql -d -p 1433:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=MSSqlServer_RootPassword1 mcr.microsoft.com/mssql/server:2022-latest
  • Stop the container w/ the following command:

    docker stop test-mssql
  • Stop Colima w/ the following command:

    colima stop

Run container in Testcontainers

  • Ensure Colima is started (above)

  • Set the following environment variables:

    export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
    export DOCKER_HOST="unix://${HOME}/.colima/docker.sock"
  • Create and start an MSSQLServerContainer in your tests such as:

       MSSQLServerContainer container = new MSSQLServerContainer(
    DockerImageName.parse(MSSQLServerContainer.IMAGE).withTag("2022-latest"))
    		.acceptLicense();
       container.start();
  • Once you are finished running the container you can stop Colima w/ the following command:

    colima stop
💡
You can also simply implement one of the SqlServer_2017_ContainerSupport, SqlServer_2019_ContainerSupport, or SqlServer_2022_ContainerSupport interfaces in your test class which will handle the above setup.

Running Dataflow locally against MSSQL

  • Ensure MSSQL container running locally (above)

  • Include the MSSQL driver by building Dataflow w/ the local-dev-mssql profile as follows:

    ./mvnw clean install -DskipTests -s .settings.xml -Plocal-dev-mssql
  • Set the following env vars before running Dataflow:

    export SPRING_DATASOURCE_URL="jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true"
    export SPRING_DATASOURCE_USERNAME=sa
    export SPRING_DATASOURCE_PASSWORD="MSSqlServer_RootPassword1"
    export SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver
ℹ️
MSSQL does not allow bootstrap creation of a database via an env var, as such the master database is used and there is no database property set in the url
  • Run the Dataflow server either from w/in IDEA or java -jar

Useful aliases

Here are some useful aliases for starting/stopping an MSSQL database in Docker:

alias mssql-start="docker run --name test-mssql --hostname test-mssql -d -p 1433:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=MSSqlServer_RootPassword1 mcr.microsoft.com/mssql/server:2022-latest "

alias mssql-stop="docker stop test-mssql "

alias mssql-kill="docker stop test-mssql && docker rm test-mssql "

alias colima-start="colima start --arch x86_64 --memory 4 "

alias colima-stop="colima stop "