How to run SQL Server on GitHub Action

88 views Asked by At

I'm working on a small Sinatra app that needs to read data from a SQL Server database. As part of my tests, I have replicated the two tables I care about locally by running SQL Server on Docker.

Now, I'm defining a GitHub Action to run my RSpec suite. The action looks like

name: continuous-integration

on:
  pull_request:
    branches:
      - '*'
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-22.04

    services:
      mssql:
        image: mcr.microsoft.com/mssql/server:2017-CU29-ubuntu-16.04
        env:
          SA_PASSWORD: TestPassword
          ACCEPT_EULA: 'Y'
        ports:
          - 1433:1433

    steps:
      - uses: actions/checkout@v3

      - name: Install dependencies
        run: |
          sudo apt-get -y install wget build-essential libc6-dev
          sudo wget http://www.freetds.org/files/stable/freetds-1.1.24.tar.gz
          sudo tar -xzf freetds-1.1.24.tar.gz
          cd freetds-1.1.24
          sudo ./configure --prefix=/usr/local --with-tdsver=7.3
          sudo make
          sudo make install

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          # ruby-version: from .ruby-version
          bundler-cache: true

      - name: Run RSpec
        run: |
          bin/rspec spec --fail-fast --format progress
        env:
          RUBYOPT: -W0
          APP_ENV: test
          CI: "true"
          SQLSERVER_DATASERVER: localhost
          SQLSERVER_USERNAME: sa
          SQLSERVER_PASSWORD: TestPassword

But, when it runs, I get

TinyTds::Error: Unable to connect: Adaptive Server is unavailable or does not exist (localhost)

UPDATE - After some troubleshooting, I found that the database isn't accessible.

Before the Run RSpec step, I have added

- name: Check connectivity
  run: |
    echo -n | telnet 0.0.0.0 1433

And I get

telnet: Unable to connect to remote host: Connection refused Trying 0.0.0.0... Error: Process completed with exit code 1.

This is the log from the mssql service

1433/tcp -> 0.0.0.0:1433 1433/tcp -> [::]:1433 Waiting for all services to be ready /usr/bin/docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" c61a4604c354409a929d2052c3b3b2e2598b13408bb3f9801794c1d0a40cd98d mssql service is healthy.

UPDATE 2 - I have tried to replace the mssql service with the potatoqualitee/[email protected] action by adding the following step (and removing the services part)

 - name: Install a SQL Server suite of tools
   uses: potatoqualitee/[email protected]
   with:
     install: sqlengine
     sa-password: TestPassword
     version: 2017

which logs

docker container running - sql server accessible at localhost

But, still, telnet can't connect to port 1433.

I'm really running out of options :(.

Why Isn't the database accessible?

UPDATE 3 - I discovered that the issue is related to the sa password. If using the "suggested" yourStrong(!)Password I'm able to connect to the database.

0

There are 0 answers