Last active
December 12, 2024 14:28
Setting up a MSSQL database server as part of a GitHub workflow to run tests using RSpec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Things that didn't work: | |
I started by adding a service to the test | |
step, using the same Docker image and passing the env vars the test used. | |
```yml | |
name: Tests | |
runs-on: ubuntu-latest | |
services: | |
mssql: | |
image: mcr.microsoft.com/mssql/server:2022-latest | |
env: | |
MSSQL_SA_PASSWORD: yourStrongPassword1 | |
ACCEPT_EULA: "Y" | |
ports: | |
- 1433:1433 | |
steps: - name: Checkout code | |
uses: actions/checkout@v3 | |
.... | |
``` | |
The test step was already installing FreeTDS, which TinyTDS depends on. When I | |
originally set it up, all the documentation I found pointed me toward [getting | |
the source and building and installing it](https://github.com/rails-sqlserver/tiny_tds?tab=readme-ov-file#install). I followed advice in documentation | |
and ended up installing it like this: | |
```yml | |
- name: Install freetds | |
run: | | |
sudo apt-get install -y build-essential wget \ | |
&& wget http://www.freetds.org/files/stable/freetds-1.1.24.tar.gz \ | |
&& tar -xzf freetds-1.1.24.tar.gz \ | |
&& cd freetds-1.1.24 \ | |
&& ./configure --prefix=/usr/local --with-tdsver=7.3 \ | |
&& sudo make \ | |
&& sudo make install | |
``` | |
Now when I ran specs on CI, I got an error saying that the connection failed. I | |
first confirmed the host and port I was using to connect to the local service. | |
When I changed either of these, I got a new error message saying that the | |
database server could not be found, so I was confident the host and port were | |
correct. After a bunch of googling, I found a [related GitHub | |
issue](https://github.com/rails-sqlserver/tiny_tds/issues/441) which points to a | |
[problem with the TLS handshake on | |
FreeTDS](https://github.com/FreeTDS/freetds/issues/299). [This | |
comment](https://github.com/FreeTDS/freetds/issues/299#issuecomment-620729458) | |
suggested using GnuTLS instead of OpenSSL for FreeTDS. I added a step to install | |
GnuTLS in the GitHub workflow for running tests: | |
```yml | |
- name: Install gnutls | |
run: | | |
wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.16.tar.xz \ | |
&& tar -xf gnutls-3.6.16.tar.xz \ | |
&& cd gnutls-3.6.16 \ | |
&& ./configure --prefix=/usr/local \ | |
&& sudo make \ | |
&& sudo make install | |
``` | |
This failed because it needed Libnettle 3.4.1. So I added a step to install nettle: | |
```yml | |
- name: Install nettle | |
run: | | |
wget https://ftp.gnu.org/gnu/nettle/nettle-3.4.1.tar.gz \ | |
&& tar -xzf nettle-3.4.1.tar.gz \ | |
&& cd nettle-3.4.1 \ | |
&& ./configure --prefix=/usr/local --disable-openssl --enable-shared \ | |
&& sudo make \ | |
&& sudo make install | |
``` | |
What finally did work: | |
Nettle installed successfully, but I still got the error `Libnettle 3.4.1 was | |
not found.` when installing GnuTLS. At this point, I had exhausted my limited | |
understanding of package management on unix and reached out for help. | |
[Mike](https://thoughtbot.com/blog/authors/mike-burns) jumped in to help and | |
noted that the FreeTDS package on Debian stable is version 1.3.17, and it uses | |
GnuTLS by default. This means that I could replace all the messy wget/tar/make | |
attempts with calls to apt-get: | |
```yml | |
- name: Install gnutls | |
run: | | |
sudo apt-get install gnutls-bin | |
- name: Install freetds | |
run: | | |
sudo apt-get install -y freetds-bin freetds-common freetds-dev libct4 libsybdb5 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment