microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
175 stars 26 forks source link

CTC1000 Expected 'MappingStart', got 'SequenceStart' for 'depends_on' in VS 17.3.4 #356

Closed cjbush closed 1 month ago

cjbush commented 2 years ago

I have a docker-compose.yml file that's valid and works with using docker-compose up on the command line, but the Microsoft.VisualStudio.Docker.Compose.targets file is barfing on the DockerGetServiceReferences task with the following error:

Code Description Project File Line
CTC1000 (Line: 6, Col: 5, Idx: 97) - (Line: 6, Col: 6, Idx: 98): Expected 'MappingStart', got 'SequenceStart' (at Line: 6, Col: 5, Idx: 97). docker-compose Microsoft.VisualStudio.Docker.Compose.targets 201

The docker-compose.yml file is pretty basic, just spinning up a SQL server image and a RabbitMq image. I've isolated it to the depends_on clause. If I remove it, it builds correctly. If not, the build fails.

version: '3.4'

services:
  sql-data:
    image: mcr.microsoft.com/mssql/server:2017-CU24-ubuntu-16.04
    depends_on: 
      - rabbitmq

  rabbitmq:
    image: rabbitmq:3.8.20-management   

This behavior started when I upgraded Visual Studio to 17.3.4 and 17.3.5, but I believe I was on one of the 17.2.x releases, so I'm not sure exactly when it got introduced. Any insight is appreciated.

danegsta commented 2 years ago

We have a fix for this issue that will ship in VS 2022 17.4 preview 3, but you should also be able to work around it by switching your depends_on declaration from the short syntax version to the corresponding long syntax version (see: https://docs.docker.com/compose/compose-file/#depends_on). For the sample compose yaml you provided, that would look like:

version: '3.4'

services:
  sql-data:
    image: mcr.microsoft.com/mssql/server:2017-CU24-ubuntu-16.04
    depends_on: 
      rabbitmq:
        condition: service_started

  rabbitmq:
    image: rabbitmq:3.8.20-management
cjbush commented 2 years ago

Hi @danegsta thanks for the quick turnaround. I actually did try the long notation out of curiosity before I filed the issue, but I get the following error when I try it:

Code Description File Line
DT1001 services.sql-data.depends_on contains an invalid type, it should be an array Microsoft.VisualStudio.Docker.Compose.targets 201
danegsta commented 2 years ago

I believe that error is from compose due to the version of the specification set in your file; if you remove the top version declaration from your file, it should work with the long syntax. Docker has moved away from using the version specification in the current versions of the compose specification, but it is backwards compatible with the 3.x versions, so there shouldn't be any issues.

cjbush commented 2 years ago

@danegsta Thanks, I'm up and running again. In messing with the compose spec version I realized that I was actually running an older version of docker-compose (1.24.1) that didn't support the new spec. Upgrading that allowed me to use the new long syntax, but I also discovered it fixed the original issue I was experiencing with the shorter syntax. Do the container tools provide any sort of warning if you're using a version of docker or docker-compose that's older than what they're intended to work with?

danegsta commented 2 years ago

@cjbush Glad to hear that got you unblocked; we do some basic version checking for when certain features were introduced in docker/compose, but in general try to support as wide a range of versions as possible (although we do generally recommend trying to stay on newer releases due to bug fixes and reliability improvements over time). Our tooling should support both versions of the syntax as we generally try to maintain compatibility with older releases where possible.

dbreshears commented 1 month ago

Closing issue as this was fixed.