microsoft / mssql-docker

Official Microsoft repository for SQL Server in Docker resources
MIT License
1.73k stars 757 forks source link

flaky Build: Login failed for user 'SA' . Repeatable Test Included #748

Open Warfront1 opened 2 years ago

Warfront1 commented 2 years ago

Running on a CircleCI Build Container(Linux Large): ubuntu-2004:202201-02

This issue occurs ~50% of the time when building with the provided Dockerfile on the above system: docker build --no-cache --progress=plain --tag test

Error Message is always from the sqlcmd, providing the following error message: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..

The Dockerfile:

FROM mcr.microsoft.com/mssql/server:2017-CU29-ubuntu-16.04

# Create "errorlog" to prevent race conditions and Create test sql script
RUN mkdir -p "/var/opt/mssql/log/" && touch "/var/opt/mssql/log/errorlog" && \
  echo "select 1" > test.sql

# Create primary setup/test bash script
RUN echo '#!/bin/bash' >> ~/setup.sh && \
  echo 'until grep -Fq "SQL Server is now ready for client connections" /var/opt/mssql/log/errorlog; do sleep 1s; done' >> ~/setup.sh && \
  echo 'sqlcmd_output=$( (/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P P@nkM0n123 -i "test.sql") 2>&1) && echo "$sqlcmd_output"' >> ~/setup.sh && \
  echo 'if [[ "$sqlcmd_output" == *Error*  ]]; then echo "Error Running SQL Scripts during container build: $sqlcmd_output" && exit 1; fi' >> ~/setup.sh && \
  cat ~/setup.sh && chmod +x ~/setup.sh

ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=P@nkM0n123

RUN /opt/mssql/bin/sqlservr --accept-eula & ~/setup.sh && pkill sqlserv

Note All data in the Dockerfile is test data; the password, and commands are just an MRE of the issue I am receiving.

Warfront1 commented 2 years ago

I've dug through this repository a bit, and found an included example (that was partially broken), but gave me some incite into why the above may be flaky. I believe the DB state may be non-zero (not-ready), even though the SQL Log is saying SQL Server is now ready for client connections.

I've fixed the example script and published a PR to get the example working again.