首页 > 解决方案 > 为什么找不到 chmod 和 doctl?

问题描述

我创建了一个包含以下内容的 docker 镜像:

FROM ubuntu:20.10

RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git

RUN curl -L https://github.com/digitalocean/doctl/releases/download/v1.43.0/doctl-1.43.0-linux-amd64.tar.gz  | tar xz
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN curl -L https://github.com/argoproj/argo-cd/releases/download/v1.5.5/argocd-linux-amd64 -o argocd
RUN curl -L https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz | tar xz


RUN chmod +x ./argocd
RUN chmod +x ./kubectl
RUN chmod +x ./linux-amd64/helm

RUN mv ./argocd /usr/local/bin/
RUN mv ./kubectl /usr/local/bin/
RUN mv ./doctl /usr/local/bin/
RUN mv ./linux-amd64/helm /usr/local/bin/

WORKDIR /sh

COPY test.sh /sh
RUN chmod +x /sh/test.sh

然后我在我的计算机上本地测试了图像,如果图像有效:

docker pull hub.databaker.io/devops/argcd-cli:0.1.22
docker run -it --rm hub.databaker.io/devops/argcd-cli:0.1.22
root@76db905a83c6:/sh# pwd
/sh
root@76db905a83c6:/sh# doctl version
doctl version 1.43.0-release
Git commit hash: 1b6d0b8

如您所见,我可以doctl在容器内调用它并显示预期结果。

我使用Drone CI构建管道并在以下管道上遇到问题:

kind: pipeline
type: docker
name: DEV build, push and deploy

steps:
  - name: DEV deployment
    image: hub.databaker.io/devops/argcd-cli:0.1.22
    pull: if-not-exists
    environment:
      DO_AC:
        from_secret: do_ac
      K8S_CLUSTER:
        from_secret: k8s_cluster
      ARGO_SERVER:
        from_secret: argo_server
      ARGO_USERNAME:
        from_secret: argo_username
      ARGO_PW:
        from_secret: argo_pw
      IMAGE_VERSION: ${DRONE_SEMVER_SHORT}
      USER:
        from_secret: gituser
      PW:
        from_secret: gitpw
      GIT_URL: gitlab.com/databaker.io/gitops.git
      PATH: keycloak-svc
      NAMESPACE: dev
    commands:
      - cd /sh
      - pwd
      - doctl version

trigger:
  event:
    - tag

image_pull_secrets:
  - dockerconfig

它显示以下错误消息:

/bin/sh: 5: chmod: not found
/bin/sh: 24: doctl: not found
+ cd /sh
+ pwd
/sh
+ doctl version

我也试过:

commands:
  - ls -la
  - cd /usr/local/bin/
  - ls -la
  - /bin/bash -c doctl version
  - /bin/bash -c pwd
  - doctl version

并得到:

/bin/sh: 5: chmod: not found
2 /bin/sh: 18: ls: not found
3 + ls -la

为什么在管道doctlchmod找不到?我是否忘记激活管道上的某些内容?

标签: dockerdrone

解决方案


PATH在您的 Drone 环境变量中被覆盖

看起来您的PATH变量并非旨在保存可执行路径(PATH: keycloak-svc)。我建议使用不同的名称。

如果在更改该环境变量名称后,您发现它/usr/local/bin/不在 Drone'sPATH中,您可以将其添加到该commands部分,如Drone 文档中所述。

笔记:

我想在找到其他人失败构建的PATH日志后查看一下,然后查看他们大约在同一时间提交的更改


推荐阅读