I am trying to construct ci process to build, test and publish my .NET Core app using Docker-Compose and bash scripts.
I have UnitTests, IntegrationTests and XApi projects in a folder
and have created DockerFile
and docker-compose.yml
like below.
IntegrationTests
are dependent to mongointegration
, so I added links
and depends_on
attributes to testandpublish
service in docker-compose.yml
.
When I try to docker-compose up
or docker-compose up testandpublish
,
it fails to connect mongo. (DockerFile - step 10), mongo service has not been started yet (Don't understand why)
In step 10, if I change RUN
to CMD
, it can connect to mongo, docker-compose works fine. But this time I cannot detect tests are failed or succeed in my sh script, because now it does not break docker-compose up
command..
My question is: Why docker compose does not start service mongointegration
? And if it is impossible, how can I understand that service testandpublish
failed? Thanks.
Structure:
XProject
-src
-Tests
-UnitTests
-IntegrationTests
-Dockerfile
-docker-compose.yml
-XApi
My Dockerfile content is (I have added line numbers to explain problem here):
1.FROM microsoft/dotnet:1.1.0-sdk-projectjson
2.COPY . /app
3.WORKDIR /app/src/Tests/UnitTests
4.RUN ["dotnet", "restore"]
5.RUN ["dotnet", "build"]
6.RUN ["dotnet", "test"]
7.WORKDIR /app/src/Tests/IntegrationTests
8.RUN ["dotnet", "restore"]
9.RUN ["dotnet", "build"]
10.RUN ["dotnet", "test"]
11.WORKDIR /app/src/XApi
12.RUN ["dotnet", "restore"]
13.RUN ["dotnet", "build"]
14.CMD ["dotnet", "publish", "-c", "Release", "-o", "publish"]
and my docker-compose.yml
version: "3"
services:
testandpublish:
build: .
links:
- mongointegration
depends_on:
- mongointegration
mongointegration:
image: mongo
ports:
- "27017:27017"