Azure DevOps 自托管 Pipeline Agent,可以执行 docker 构建和推送命令

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

我正在尝试创建一个自托管代理来在 AKS 上构建和部署我的代码。

我的所有 JAVA 代码都位于 Azure DevOps git 存储库中。我创建了一个管道(您可以查看底部的 yaml),它执行 gradle ShadowJar 命令来构建我的代码,然后构建一个 docker 映像并将其推送到 docker hub 注册表,最后,它部署我的AKS 集群上的应用程序。
我想尝试使用部署在同一 AKS 集群上的自托管代理来运行有问题的管道。

我按照 Microsoft 页面上的说明创建了代理(https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#linuxhttps: //learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#configure-secrets-and-deploy-a-replica-set)并成功部署代理。
一开始,由于缺少 JAVA_HOME 变量,管道不断失败。我解决了这个问题,将必要的 jdk tar.gz (在本例中为 jdk 17)添加到存储库中,并使用 JavaToolInstaller 设置 JAVA_HOME 变量。 (也许这不是一个很好的解决方案,但我解决了问题,现在我的主要目标是让它发挥作用)

现在的主要问题是管道不断失败并出现此错误:

##\[error\]Unhandled: Unable to locate executable file: 'docker'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

我需要docker来执行docker登录/docker构建和推送命令,但我找不到在我的自托管代理中安装docker的解决方案。您能帮我解决吗?

谢谢您的帮助


我的管道:

trigger:
  batch: false
  branches:
    include:
      - main
pool:
  name: test-observability-pool
stages:
  - stage: Build
    jobs:
      - job: Build
        displayName: Build and Publish to Docker Hub
        steps:
          - task: JavaToolInstaller@0
            inputs:
              versionSpec: "17"
              jdkArchitectureOption: x64
              jdkSourceOption: LocalDirectory
              jdkFile: jdk-17_linux-x64_bin.tar.gz
              jdkDestinationDirectory: /builds/binaries/externals
              cleanDestinationDirectory: true
          - task: Gradle@3
            displayName: Gradle Build
            inputs:
              gradleWrapperFile: gradlew
              tasks: shadowJar
              publishJUnitResults: false
              javaHomeOption: JDKVersion
              sonarQubeRunAnalysis: false
              spotBugsAnalysis: false
          - task: Docker@2
            displayName: Docker Login
            inputs:
              containerRegistry: Docker Hub Connection
              command: login
          - task: Docker@2
            displayName: Docker BuildAndPush
            inputs:
              containerRegistry: Docker Hub Connection
              repository: elettrogewi/kubepublisher-otel
              command: buildAndPush
              Dockerfile: "**/Dockerfile"
              tags: latest
  - stage: Deploy
    jobs:
      - job: Deploy
        displayName: Deploy on AKSObservability01
        steps:
          - task: Kubernetes@1
            inputs:
              connectionType: Kubernetes Service Connection
              kubernetesServiceEndpoint: aks-observability02
              namespace: default
              command: apply
              arguments: -f publisher-otel.yaml --force
              secretType: dockerRegistry
              containerRegistryType: Azure Container Registry
              outputFormat: yaml
docker azure-devops azure-pipelines devops azure-aks
1个回答
0
投票

您可以添加一个 DockerInstaller@0 任务,在 docker login / docker build 和 push 命令之前在代理计算机上安装 Docker CLI。

- task: DockerInstaller@0
  displayName: Docker Installer
  inputs:
    dockerVersion: 17.09.0-ce
    releaseType: stable
© www.soinside.com 2019 - 2024. All rights reserved.