我创建了一个包含以下内容的 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
为什么在管道中找不到doctl
和chmod
?我是否忘记激活管道上的某些内容?
PATH
在无人机环境变量中被覆盖
看起来您的PATH
变量不是为了保存可执行路径(PATH: keycloak-svc
(。我建议使用其他名称。
如果在更改该环境变量名称后,您发现/usr/local/bin/
不在 Drone 的PATH
上,则可以将其添加到commands
部分中,如 Drone 文档中所述。
注意:
我想在找到其他人失败构建的日志后查看PATH
,然后查看他们大约同时提交的更改。