插件/docker:传递id_rsa秘密键使用build_args正确?
秘密
我用drone.io添加了一个秘密:
drone org secret add --image=* --conceal --skip-verify=true octocat SSH_KEY @/home/me/.ssh/id_rsa
Dockerfile
由于npm install
需要访问私有存储库,我在我的Dockerfile中指定了一个ARG ,以获得我的私有ssh_key:
FROM node:latest ARG SSH_KEY ENV SSH_KEY=$SSH_KEY RUN mkdir /root/.ssh && \ echo $SSH_KEY | cut -d "\"" -f 2 > /root/.ssh/id_rsa && \ chmod 0600 /root/.ssh/id_rsa && \ eval `ssh-agent -s` && \ ssh-add /root/.ssh/id_rsa && \ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config RUN mkdir /app WORKDIR /app COPY . /app EXPOSE 3001 CMD ["npm", "start"]
.drone.yml
最后,在我的.drone.yml
pipe道中,在plugin/docker
.drone.yml
步骤中,使用build-arg注入ssk_key:
pipeline: test: image: node:latest commands: - mkdir /root/.ssh && echo "$SSH_KEY" > /root/.ssh/id_rsa && chmod 0600 /root/.ssh/id_rsa - eval `ssh-agent -s` && ssh-add /root/.ssh/id_rsa - echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config - npm install - npm test docker: image: plugins/docker repo: octocat/bar tags: latest build_args: - SSH_KEY=${SSH_KEY}
我的问题:
- 这是正确的方式注入我的SSH密钥到无人机pipe道Dockerfile?
- build_args打印在前端日志中,SSK_KEY也是如此…如何避免这种情况?
- 构buildparameter passing我的SSK_KEY +引号 – >“SSH_KEY”,所以我必须删除我的Dockerfile中的引号(通过pipe道化string),然后将其回显到
/root/.ssh/id_rsa:
,任何方式不有这些"
?
非常感谢!!
[编辑]感谢Adrianbuild议更好的方法,从Dockerfile中删除npm install
,因为node_modules
可以通过pipe道步骤之间的卷共享。