microsoft / DockerTools

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

Docker Compose project doest not support secrets in `docker-compose.yml` #395

Closed afscrome closed 1 year ago

afscrome commented 1 year ago

Trying to build a docker-compose file containing secrets results in the following error

services.foo.build contains unsupported option: 'secrets'

It looks like the visual studio integration is using docker-compose rather than docker compose. Starting the above compose file with docker compose up starts successfully, but docker-compose up fails with similar errors to visual studio

ERROR: The Compose file '.\docker-compose.yml' is invalid because: secrets.ado-accesstoken value 'environment' does not match any of the regexes: '^x-' services.foo.build contains unsupported option: 'secrets'

docker-compose.yml

version: "3.4"
secrets:
  ado-accesstoken:
    environment: SYSTEM_ACCESSTOKEN
services:
  foo:
    build:
      context: .
      dockerfile: Dockerfile
      secrets:
        - ado-accesstoken

VS Error

Severity    Code    Description Project File    Line    Suppression State
Error   DT1001  services.foo.build contains unsupported option: 'secrets'   docker-compose  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets  200 

MSBuild output

MSBuild version 17.7.2+d6990bcfa for .NET Framework
Build started 10/08/2023 13:04:43.

Project "C:\src\docker-compose.dcproj" on node 1 (default targets).
DockerPrepareForBuild:
  docker-compose  -f "C:\src\docker-compose.yml" -p dockercompose11872092466633603380
  --ansi never config
  The Compose file 'C:\src\docker-compose.yml' is invalid because:
  secrets.ado-accesstoken value 'environment' does not match any of the regexes: '^x-'
  services.foo.build contains unsupported option: 'secrets'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio
.Docker.Compose.targets(353,5): error DT1001: services.foo.build contains unsupported option: 'secrets' [c:\src\docker-
compose.dcproj]
Done Building Project "C:\src\docker-compose.dcproj" (default targets) -- FAILED.

Build FAILED.

"C:\src\docker-compose.dcproj" (default target) (1) ->
(DockerPrepareForBuild target) ->
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStud
io.Docker.Compose.targets(353,5): error DT1001: services.foo.build contains unsupported option: 'secrets' [c:\src\docker
-compose.dcproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.70
dbreshears commented 1 year ago

@afscrome, do you have "Use Docker Compose V2" in Docker Desktop settings checked?

afscrome commented 1 year ago

Nope, it was unchecked. Checking it fixed the issue.

Given that compose v1 is now deprecated, maybe the tooling could issue a warning if V1 compose is detected. (or migrate to use docker compose directly - https://docs.docker.com/compose/migrate/ )

dbreshears commented 1 year ago

Thanks. Nice to hear that resolved it. We may at some point migrate but for now it should be aliased if using V2 and still allows for compatibility with V1.

I do see this Warning in our the Container Tools output pane in Visual Studio when using V1

WARNING: Compose V1 is no longer supported and will be removed from Docker Desktop in an upcoming release. See https://docs.docker.com/go/compose-v1-eol/