Unable to use MsSql database container as Resource Inside Azure Pipeline

Viewed 234

I try to setup a pipeline to run E2E tests using selenium for a small blazor app. Locally everything works well, even with containers on a windows maschine. But in a azure pipeline I didn't get the app connected to the db. According to my configurations below I tried the following connection strings:

Server=localhost,1433; Database=Master; User ID=sa; Password=Password!1;
Server=docker.host.internal,1433; Database=Master; User ID=sa; Password=Password!1;
Server=db,1433; Database=Master; User ID=sa; Password=Password!1;

Nothing worked :-(

All I have is a small blazor frontend and a mssql database. I have created a docker compose file which creates the db container as well as building the app and running the container as well. Here is the docker compose file.

version: "3.9"
services:

  ms-sql-db:
    image: mcr.microsoft.com/mssql/server:2017-latest
    container_name: SqlDataBase
    ports:
      - "1433:1433"
    healthcheck:
        test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-Usa", "-P", "Password!1", "-Q", "select 1"]
        interval: 1s
        retries: 20
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=Password!1
    volumes: #needed to persist the data on local disk
      - ~/.aspnet/mssql/data:/var/opt/mssql/data
      - ~/.aspnet/mssql/log:/var/opt/mssql/log
      - ~/.aspnet/mssql/secrets:/var/opt/mssql/secrets

  authfrontend:
    container_name: AuthFrontend
    build: 
        context: ../../../../src/AuthFrontend
        dockerfile: ./Dockerfile
    ports:
      - "5000:80"
      - "5001:443"
    environment:
      - ASPNETCORE_ENVIRONMENT=LocalE2ETest
      - ASPNETCORE_HTTPS_PORT=5001
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_Kestrel__Certificates__Default__Password=Password!1
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
    volumes:
      - ~/.aspnet/https:/https
    depends_on:
        ms-sql-db:
            condition: service_healthy

Locally on my windows maschine, the frontend is able to connect to the db when using the connection string

Server=localhost,1433; Database=Master; User ID=sa; Password=Password!1;

Inside the pipeline a create the db container as resource like so:

...
resources:
    containers:
      - container: SqlDataBase
        image: mcr.microsoft.com/mssql/server:2017-latest
        ports:
          - 1433:1433
        options: -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password!1' -e 'MSSQL_PID=Express'
...
- stage: E2ETest
  jobs:  
  - job: Run E2E tests
    services:
      db: SqlDataBase
    steps:
    - powershell: docker-compose -f ./docker-compose.Frontend.yml build
      displayName: 'build app'
    - powershell: docker-compose -f ./docker-compose.Frontend.yml up -d
      displayName: 'run app'
    - script: dotnet test --collect:"XPlat Code Coverage" -l:trx;LogFileName=../../../out/TestResults/testresult.trx
      displayName: 'dotnet test and collect code coverage'
0 Answers
Related