2
votes

I have a .net core app that i want to run on docker. I used VS Docker Tools to 'add container support' and it added a docker-compose project.

When i build it, i get the container built using my re-compiled .net core app and my dockerfile.

Here is the docker-compose.dcproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectVersion>2.0</ProjectVersion>
    <DockerTargetOS>Linux</DockerTargetOS>
    <ProjectGuid>a7cb971b-57ac-4704-851d-a322cf4f9e3f</ProjectGuid>
  </PropertyGroup>
  <ItemGroup>
    <None Include="docker-compose.ci.build.yml" />
    <None Include="docker-compose.override.yml">
      <DependentUpon>docker-compose.yml</DependentUpon>
    </None>
    <None Include="docker-compose.yml" />
  </ItemGroup>
</Project>

Here are the files: docker-compose.yml

version: '3'

services:
  coresandbox:
    image: coresandbox
    build:
      context: ./CoreSandbox
      dockerfile: Dockerfile

docker-compose.override.yml

version: '3'

docker-compose.ci.build.yml

version: '3'

services:
  ci-build:
    image: microsoft/aspnetcore-build:2.0
    volumes:
      - .:/src
    working_dir: /src
    command: /bin/bash -c "dotnet restore ./CoreSandbox.sln && dotnet publish ./CoreSandbox.sln -c Release -o ./obj/Docker/publish"

Now i have configured VSTS with the following tasks: 1. Get sources 2. Build Services - Docker Compose The task looks fairly basic, i left all defaults in place VSTS task screenshot

Then i get this log from the build

/usr/local/bin/docker-compose -f /home/alex/testagent/_work/2/s/docker-compose.yml -f /home/alex/testagent/_work/2/s/docker-compose.ci.build.yml -f /home/alex/testagent/.docker-compose.1505284937228.yml -p newsroomly/CoreSandbox build
Building coresandbox
Step 1/10 : FROM microsoft/dotnet:2.0-runtime
 ---> a2f5b3f42c0c
Step 2/10 : ARG source
 ---> Using cache
 ---> 7a707828214b
Step 3/10 : WORKDIR /app
 ---> Using cache
 ---> ff4262616387
Step 4/10 : COPY ${source:-obj/Docker/publish} .
Service 'coresandbox' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder666656323/obj/Docker/publish: no such file or directory
Building coresandbox
Service 'coresandbox' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder666656323/obj/Docker/publish: no such file or directory
/usr/local/bin/docker-compose failed with return code: 1

Clearly the issue is that the dotnet build task is not run BEFORE compose tries to build the container.

I have also tried dotnet build my.sln but as per this issue: https://github.com/dotnet/cli/issues/6178 this is not supported, i get error MSB4236: The SDK 'Microsoft.Docker.Sdk' specified could not be found.

It seems that the docker-compose.ci.build.yml implies you do docker-compose -f docker-compose.ci.build.yml up and then you do docker-compose -f docker-compose.yml build

However, when i did that, i got the same error about a missing SDK

/src/docker-compose.dcproj : error MSB4236: The SDK 'Microsoft.Docker.Sdk' specified could not be found.

So back to my question - how can i build my dcproj on VSTS

2
How about not using the docker-compose.ci.build.yml at all, does that help? - Tarun Lalwani
Do you user a hosted agent or private agent? And do you run the build on a Mac or Linux build agent? - Eddie Chen - MSFT
Linux, private. I have found a workaround will post it here later. - zaitsman
What workaround for this issue? You need to specify docker-compose.ci.build.yml file first (Docker Compose file), then specify docker-compose.yml in additional docker compose file, try it and check the result. - starian chen-MSFT
@starain-MSFT em i did specify it, that just kept failing. Also, the ci yaml implies that we want to build inside another container (who knows why). So the workaround in a nutshell is - build yourself, using ./obj/Docker as -o path and then the image creation inside the compose can find the files and it all works. - zaitsman

2 Answers

0
votes

Here is the solution - VSTS CI/CD with docker and .NET Core 2.0 - Copy failed

I encounter exactly same issue when using .Net framework app. I used another solution, in the VS solution build step, I had to build with Release configuration, otherwise the publish folder won't show up.

One thing you can do is to change this line in your dockerfile, I think this helped me. Command:

/bin/bash -c "dotnet restore ./CoreSandbox.sln && dotnet publish ./CoreSandbox.sln -c Release -o ./obj/Docker/publish"

to command:

/bin/bash -c "dotnet restore ./CoreSandbox.sln && dotnet publish ./CoreSandbox.sln -c Release -o ./obj/Docker"

I spin up my private build agent, and it saves me alot of time instead of downloading the docker images on hosted agent in VSTS.

0
votes

The fix for /src/docker-compose.dcproj : error MSB4236: The SDK 'Microsoft.Docker.Sdk' specified could not be found. is to use the microsoft/aspnetcore-build:1.0-2.0 image instead of microsoft/aspnetcore-build:2.0.

The 2.0 image is missing the Microsoft.Docker.Sdk. This will be fixed in 2.1 starting with preview 2.