3

For my projects I sometimes need to unittest my code against a ms sql server. At the moment, I created a monstrous docker image, containing all the tools I need, including the sql server. Now this image got to about 15 GB in size, which is really not cool.

So I'm trying to use the GitLab CICD Service part (as described here https://docs.gitlab.com/ee/ci/services/index.html). But when I'm trying to add my (custom) image as a service I keep getting the health check issue:

*** WARNING: Service runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.lcaol__windowsdockerimages__mssql-0 probably didn't start properly.
Health check error:
service "runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.local__windowsdockerimages__mssql-0-wait-for-service" health check: exit code 1
Health check container logs:
2023-01-19T09:58:09.913696500Z FATAL: No HOST or PORT found                      
Service container logs:
*********

Now I found something online about needing to expose the ports of the service in the Dockerfile, so I tried that, but that did not help.

This is what my MSSQL DockerFile currently looks like:

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Download Links: 
ENV exe "https://go.microsoft.com/fwlink/?linkid=840945"
ENV box "https://go.microsoft.com/fwlink/?linkid=840944"

ENV sa_password="_" \
   attach_dbs="[]" \
   ACCEPT_EULA="Y" \
   sa_password_path="C:\ProgramData\Docker\secrets\sa-password"

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# make install files accessible
COPY start.ps1 /
WORKDIR /

RUN Invoke-WebRequest -Uri $env:box -OutFile SQL.box ; \
    Invoke-WebRequest -Uri $env:exe -OutFile SQL.exe ; \
    Start-Process -Wait -FilePath .\SQL.exe -ArgumentList /qs, /x:setup ; \
    .\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS ; \
    Remove-Item -Recurse -Force SQL.exe, SQL.box, setup

RUN stop-service MSSQLSERVER ; \
    set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
    set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
    set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\' -name LoginMode -value 2 ;

HEALTHCHECK CMD [ "sqlcmd", "-Q", "select 1" ]

EXPOSE 1433/tcp
EXPOSE 4022/tcp
EXPOSE 135/tcp
EXPOSE 1434/tcp
EXPOSE 1434/udp

CMD .\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \"$env:attach_dbs\" -Verbose

And this is is my .gitlab-ci.yml file:

default:
  image:
    name: gitlab.mydomain.local:4567/windowsdockerimages/basicnetframeworkimage:latest
  tags:
    - windows
    - docker

# The stages during this build
stages:
  - build

build:
  stage: build
  script:
  - echo "Hello world"
  - ping mssql
  - dotnet run
  services:
  - name: gitlab.mydomain.local:4567/windowsdockerimages/mssql
    alias: mssql

Anyone who can help me get closer to the solution? *Note, the ping mssql also fails, the container in which we run cannot find the DNS entry

Foitn
  • 604
  • 6
  • 25
  • Looks like your MSSQL container logs are empty. Did you test this image locally to make sure it starts properly with a command like `docker run gitlab.mydomain.local:4567/windowsdockerimages/mssql` ? Maybe the service just didn't start – Pierre B. Feb 07 '23 at 07:58

2 Answers2

1

I eventually got it up and running, by editing my configuration of my gitlab runner.

After a lot of fiddling around I found the issue. By adding this to my configuration, my issue was gone:

environment = ["FF_NETWORK_PER_BUILD=1"]   

If anyone finds this post, this fixed it for me.

Foitn
  • 604
  • 6
  • 25
0

I would use an existing official image for MSSQL server (https://hub.docker.com/_/microsoft-mssql-server) and run unit tests in one container and the database in another one.

Slava Kuravsky
  • 2,702
  • 10
  • 16
  • Sadly my container runs on windows, so these images from microsoft are not an option for me. – Foitn Feb 06 '23 at 09:06
  • In that case try this: https://github.com/Microsoft/mssql-docker/tree/master/windows - should be sufficient for unit testing. Update: ah you already use a derived version of it. – Slava Kuravsky Feb 06 '23 at 10:15
  • So in that case I suggest you to search through issues and/or raise new one https://github.com/microsoft/mssql-docker/issues – Slava Kuravsky Feb 06 '23 at 10:24
  • Such an issue already exists: https://github.com/microsoft/mssql-docker/issues/799 But that is besides the point. My GitLab CICD cannot properly host such a container – Foitn Feb 08 '23 at 10:50