Running SQL Server in a container on Github Actions
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.
Share
New blog post! A step-by-step guide to running Microsoft's SQL Server in a Docker container on Github Actions.https://t.co/SJv3M4KOAw pic.twitter.com/CNAX2Hbchk
— DataStation (@multiprocessio) December 16, 2021
With questions, criticism or ideas, email or Tweet me.
Also, check out DataStation and dsq.