[英]Docker + Nodejs + Private Repo + Private NPM Module - Access Problems
我正在使用Docker設置Node.js服務的部署。
我所擁有的Dockerfile是從網絡上的各種示例中拼湊而成的。 Dockerfile的目錄包括:
這是Dockerfile:
FROM ubuntu:13.10
# make sure apt is up to date
RUN apt-get update
# install npm, git, ssh, curl
RUN apt-get install -y npm git git-core ssh curl
RUN mkdir /nodejs && curl http://nodejs.org/dist/v0.10.31/node-v0.10.31-linux-x64.tar.gz | tar xvzf - -C /nodejs --strip-components=1
# Fixes empty home
ENV PATH $PATH:/nodejs/bin
ENV HOME /root
# SSH SETUP
RUN mkdir -p /root/.ssh
ADD id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "IdentityFile /root/.ssh/id_rsa" >> /root/.ssh/ssh_config
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
ADD start.sh /tmp/
RUN chmod +x /tmp/start.sh
CMD ./tmp/start.sh
設置完成后,start.sh運行,我遇到私有Node.js服務所具有的私有NPM依賴問題。 這就是start.sh正在做的事情:
cd /tmp
# try to remove the repo if it already exists
rm -rf MediaFX; true
git clone https://<username>:<password>@github.com/company/ExampleRepo.git
cd RepoName
node --version
ls
npm install
NODE_ENV=test DEBUG=* PORT=3000 node server.js
在ExampleRepo的package.json中,我們導入了一個私有模塊,如下所示:
"dependencies": {
"scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},
當npm install進入此repo時,它會輸出以下日志:
npm ERR! git clone git@github.com:InboxAppCo/scribe.git Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-InboxAppCo-scribe-git-abae334a'...
npm ERR! git clone git@github.com:InboxAppCo/scribe.git
npm ERR! git clone git@github.com:InboxAppCo/scribe.git Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
npm ERR! git clone git@github.com:InboxAppCo/scribe.git Permission denied (publickey).
npm ERR! git clone git@github.com:InboxAppCo/scribe.git fatal: Could not read from remote repository.
npm ERR! git clone git@github.com:InboxAppCo/scribe.git
npm ERR! git clone git@github.com:InboxAppCo/scribe.git Please make sure you have the correct access rights
npm ERR! git clone git@github.com:InboxAppCo/scribe.git and the repository exists.
npm ERR! Error: `git "clone" "--mirror" "git@github.com:InboxAppCo/scribe.git" "/root/.npm/_git-remotes/git-github-com-InboxAppCo-scribe-git-abae334a"` failed with 128
npm ERR! at ChildProcess.cpclosed (/usr/share/npm/lib/utils/exec.js:59:20)
npm ERR! at ChildProcess.EventEmitter.emit (events.js:98:17)
npm ERR! at Process.ChildProcess._handle.onexit (child_process.js:789:12)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://bugs.debian.org/npm>
npm ERR! or use
npm ERR! reportbug --attach /tmp/MediaFX/npm-debug.log npm
npm ERR! System Linux 3.16.4-tinycore64
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /tmp/MediaFX
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.2.18
我認為,由於私有Node服務的git克隆工作正常,它的任何私有NPM依賴項都可以順利安裝。
我相當肯定我的SSH設置有缺陷(並且它沒有表現出自己,而git克隆私人父母回購)因為我在鏈接中添加了用戶名和密碼。 但是,我不確定,並希望得到一些關於如何正確執行此操作的指導。
git clone https://<username>:<password>@github.com/company/ExampleRepo.git
工作,因為您傳遞username
和password
並通過https
"dependencies": {
"scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},
失敗,因為您通過ssh
直接連接,而Docker不會從主機上執行任何ssh agent
轉發。
不幸的是,它看起來不像npm支持任何url格式來發送用戶名和密碼,如你的克隆行: https : //docs.npmjs.com/files/package.json#git-urls-as-dependencies
你必須將你的ssh密鑰添加到docker容器中(Not Reccomended)
或者做一些時髦的事情,比如從主機上分享你的SSH_SOCKET,如:
這是我今晚要嘗試實施的方法:
docker create --build-arg TOKEN <my priv token> <dockerFile>
也許在docker文件中聲明arg?
ARG TOKEN
然后在腳本中有npm install在依賴項中使用那個TOKEN
"privModule": "git+https://${TOKEN}:x-oauth-basic@github.com/<githubID>/<privateModule>.git"
如果這不起作用,以某種方式替換package.json中的var(使用sed)或使用npm使用環境var。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.