Azure Pipeline 中的 DockerCompose@0

问题描述 投票:0回答:2

我正在为 Azure DevOps 中的 .net 项目开发一个新管道。过去,我曾在本地 Linux 代理(Ubuntu 服务器)上运行它。然而,我已经有一段时间没有这样做了,并且与我的代理有问题:

trigger: none

variables:
  - name: SourceTarget
    value: s/repo

pool:
  name: Default
  demands:
    - agent.name -equals azdevops-dev

stages:
  - stage: Build
    jobs:
      - job: "BuildJob"
        variables:
          solution: "**/*.sln"
          buildPlatform: "any cpu"
          buildConfiguration: "Release"
        pool:
          vmImage: "ubuntu-latest"
        steps:
          - checkout: self
            path: $(SourceTarget)
            displayName: "Pull Source"
        
          - task: DockerInstaller@0
            inputs:
              dockerVersion: '17.09.0-ce'

          - task: DockerCompose@0
            displayName: "Create Local Database"
            inputs:
             containerregistrytype: 'Container Registry'
             dockerComposeFile: '$(Pipeline.Workspace)/$(SourceTarget)/db/docker-compose-sql-server.yml'
             action: 'Run a Docker Compose command'
             dockerComposeCommand: 'up -d'

          - task: UseDotNet@2
            displayName: "Install .Net Core SDK"
            inputs:
              version: 7.0.306
              performMultiLevelLookup: true
            
          - task: NuGetAuthenticate@1
          - script: dotnet restore --no-cache --force
            displayName: "NuGet Package Restore"
            workingDirectory: $(Pipeline.Workspace)/$(SourceTarget)
          
          - task: DotNetCoreCLI@2
            displayName: "Dotnet Build"
            inputs:              
              projects: "**/*.csproj"
              arguments: "--configuration $(buildConfiguration)"
              workingDirectory: $(Pipeline.Workspace)/$(SourceTarget)
          
          - task: DotNetCoreCLI@2
            displayName: "Dotnet Test"
            inputs:
              command: test
              projects: "**/*[Tt]est/*.csproj"
              arguments: "--configuration $(buildConfiguration)"
            enabled: true
            env:
              ConnectionStrings__Primary: "Data Source=localhost; User Id=xxx; Password=xxx; Database=xxx_xxx;"

具体来说,我在

DockerCompose@0
步骤中遇到错误,因为它似乎无法找到它:

Docker Compose was not found. You can provide the path to docker-compose via 'dockerComposePath'

这是 Ubuntu 服务器的全新安装,我也遵循了 这些 在服务器上安装 Docker 的说明。

从管道运行

docker compose version
docker version
会产生以下结果:

docker compose version

docker version

也许与权限相关,但我对 Linux 不够熟悉,无法进一步排除故障。

.net docker docker-compose azure-devops azure-pipelines
2个回答
1
投票

这与此处报告的问题相关

我正在使用 Docker Compose 的下一个版本 V2,它使用 docker CLI 'compose' 命令而不是 docker-compose 可执行文件。

你可以尝试安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

0
投票

如果您使用 docker compose CLI 插件,您可以将

dockerComposePath
指定为
"/usr/libexec/docker/cli-plugins/docker-compose"
就像这样。

#etc...
      - job:
        steps:
          - task: DockerCompose@0
            inputs:
              containerregistrytype: "Container Registry"
              dockerRegistryEndpoint: "My company docker registry"
              dockerComposeFile: "**/docker-compose.yml"
              action: "Build services"
              #etc...
              dockerComposePath: "/usr/libexec/docker/cli-plugins/docker-compose"
#etc...
© www.soinside.com 2019 - 2024. All rights reserved.