为什么找不到 chmod 和 doctl?

Why chmod and doctl not found?

我创建了一个 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?我忘记激活管道上的东西了吗?

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

您的 PATH 变量看起来不像是用来保存可执行文件路径 (PATH: keycloak-svc)。我建议使用不同的名称。

如果在更改该环境变量名称后,您发现 /usr/local/bin/ 不在 Drone 的 PATH 上,您可以将其添加到 commands 部分,如Drone docs.

注:

我想在找到 someone else's failed build and then taking a peek at a change they committed around the same time 的日志后查看 PATH