My container has a shell script that runs after the container starts. It was working before but when I push it to Gitlab and ran it with a pipeline it doesn't start. Here's my Dockerfile.
Dockerfile
# Setup SQL Server 2019
FROM mcr.microsoft.com/mssql/server:2019-latest
ENV SA_PASSWORD=Banana100
ENV ACCEPT_EULA=Y
ENV MSSQL_PID=Developer
USER mssql
#Copy test database and create DB script to image working directory
WORKDIR /usr/src/app
COPY . /usr/src/app
EXPOSE 1433
ENTRYPOINT /bin/bash ./entrypoint.sh
What's weird is that whenever I delete the /bin/bash ./entrypoint.sh
, retype it, then run docker compose --force-recreate --build -d
on my local machine, the shell script is executed just fine. But if the pipeline do it, it doesn't work. I have nothing to push on my repo, Git thinks I didn't make any changes at all.
This post here suggest that it could be an issue with the line endings. It probably worked on most people but I have tried these with no luck:
My entrypoint.sh
is a shell script that runs an SQL file to create and restore database. Please see the codes below.
entrypoint.sh
# /opt/mssql/bin/sqlservr & /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P FBuilder*09 -d master -i createDB.sql
/opt/mssql/bin/sqlservr & /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -i createDB.sql
while true; do sleep 1000; done
docker-compose.yml
version: "3"
services:
fb_db:
container_name: test_fbdb
build: ./test.environment
ports:
- "5002:1433"
gitlab-ci.yml
.ci_server:
tags:
- ci
stages:
- build
- test
variables:
SOLUTION_NAME: FBSVC.sln
before_script:
- Set-Variable -Name "time" -Value (date -Format "%H:%m")
- echo ${time}
- echo "started by ${GITLAB_USER_NAME}"
build:
stage: build
extends:
- .ci_server
script:
- echo "Restoring project dependencies..."
- $Env:Path += ";C:\nuget"
- nuget restore
- echo "Preparing development environment"
- copy "D:\CI_TestDB\FormulaBuilder\FormulaBuilder.bak" "D:\Project Files\Gitlab-Runner\builds\_1ZgTgcF\0\water-utilities\formula-builder\test.environment"
- docker compose up --force-recreate --build -d
- echo "Publishing project..."
- $Env:Path += ";C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
- msbuild FBSVC.sln /p:DeployOnBuild=true /p:PublishProfile=CI_IntegrationTest
- echo "Build stage completed successfully!"
only:
- merge_requests
test:
stage: test
variables:
GIT_STRATEGY: clone
extends:
- .ci_server
script:
- echo "Installing dev dependencies..."
- npm ci
- echo "Running tests..."
- npm run cy:test
dependencies:
- build
only:
- merge_requests
The Gitlab Runner is running on my physical local machine, it is not a Shared Runner. Any help would be appreciated. Thanks!
UPDATE (June 24, 2022)
I have replaced the ENTRYPOINT on the Dockerfile to ENTRYPOINT [ "/bin/bash", "-c", "./entrypoint.sh"]
, it is still do the same issue. Looking at the "Select End Line Sequence" menu on VS Code found at the bottom-right corner, it is set to "LF". I checked the Dockerfile being pulled by the pipeline it is now set to "CRLF". Does this matter?
I have ran git config --global core.autocrlf input
multiple times but if the file is being pulled from the repo, it automatically does this. Hence, I decided to detach the folder containing my files that builds my database environment for the time being. Doing this requires rewriting the whole ENTRYPOINT
line on my Dockerfile to work properly again. If you have any advice, please let me know.