January 17, 2022: DataStation 0.6.0 is released! Read more
DataStation The Open-Source Data IDE

Running SQL Server in a container on Github Actions

Published on by

DataStation is an open-source data IDE for developers. It allows you to easily build graphs and tables with data pulled from SQL databases, logging databases, metrics databases, HTTP servers, and all kinds of text and binary files. Need to join or munge data? Write embedded scripts as needed in Python, JavaScript, Ruby, R, or Julia. All in one application.

In building out integration tests for DataStation recently I set up SQL Server. I didn't think this would be possible because Microsoft (and Oracle and IBM) normally require you to manually sign in to download their databases. However, Microsoft provides Docker images and allows you to accept their UELA in the command line.

So in my Github Actions run steps I added a call to Docker run:

    # Start up sqlserver
    - run: docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest

Now the Docker image docs say to set a SA_PASSWORD environment variable instead of MSSQL_SA_PASSWORD but I tried that and couldn't connect when setting that or both SA_PASSWORD and MSSQ_SA_PASSWORD.

Once this Docker image is running you'll be able to connect to the master database with the sa user and the above password. It's important that if you use a different password it fulfills all the complexity requirements listed on the Docker image documentation.

Now in Go code you can connect using go-mssqldb with the connection string sa:1StrongPwd!!@tcp(localhost:1433)/master.

The only difficult part of this recipe once is that it's hard to debug when you've set up the password incorrectly (not fulfilling complexity requirements) or if you mistype an environment variable. Maybe if I checked the Docker logs for the SQL Server container it would have given me useful information. Instead I stumbled toward a working setup through guess and check.


Questions? Feedback? Feel free to reach the author at phil@multiprocess.io.