简体   繁体   English

Docker + Nodejs +私有回购+私有NPM模块 - 访问问题

[英]Docker + Nodejs + Private Repo + Private NPM Module - Access Problems

I am in process of setting up the the deployment of a Node.js Service with Docker. 我正在使用Docker设置Node.js服务的部署。

The Dockerfile I have is pieced together from various examples from around the net. 我所拥有的Dockerfile是从网络上的各种示例中拼凑而成的。 The directory for the Dockerfile includes: Dockerfile的目录包括:

  • Dockerfile Dockerfile
  • id_rsa id_rsa
  • start.sh start.sh

This is the 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

After the set-up is complete, start.sh runs and I experience problems with a private NPM dependency that the private Node.js service has. 设置完成后,start.sh运行,我遇到私有Node.js服务所具有的私有NPM依赖问题。 This is what start.sh is doing: 这就是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

In package.json for ExampleRepo, there is one private module that we import like this: 在ExampleRepo的package.json中,我们导入了一个私有模块,如下所示:

"dependencies": {
    "scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},

When npm install gets to this repo, it outputs these logs: 当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

I thought that since the git clone of the private Node service works fine, any of its private NPM dependencies would install smoothly. 我认为,由于私有Node服务的git克隆工作正常,它的任何私有NPM依赖项都可以顺利安装。

I am fairly positive that my SSH set up is flawed (and that it didn't manifest its self while git cloning the private parents repo) because I added username and password to the link. 我相当肯定我的SSH设置有缺陷(并且它没有表现出自己,而git克隆私人父母回购)因为我在链接中添加了用户名和密码。 However, I am unsure and would appreciate some guidance on how to do this correctly. 但是,我不确定,并希望得到一些关于如何正确执行此操作的指导。

git clone https://<username>:<password>@github.com/company/ExampleRepo.git

Works, because you are passing the username and password and doing it over https 工作,因为您传递usernamepassword并通过https

"dependencies": {
    "scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},

Fails, because you are connecting directly over ssh and Docker doesn't do any ssh agent forwarding from the host machine. 失败,因为您通过ssh直接连接,而Docker不会从主机上执行任何ssh agent转发。

Unfortunatly it dosen't look like npm supports any url format to send username and password like your clone line: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies 不幸的是,它看起来不像npm支持任何url格式来发送用户名和密码,如你的克隆行: https//docs.npmjs.com/files/package.json#git-urls-as-dependencies

You'd have to add your ssh keys to the docker container ( Not Reccomended ) 你必须将你的ssh密钥添加到docker容器中(Not Reccomended)

Or do something funky like share you SSH_SOCKET from the host like: 或者做一些时髦的事情,比如从主机上分享你的SSH_SOCKET,如:

https://gist.github.com/d11wtq/8699521 https://gist.github.com/d11wtq/8699521

Here's an approach I'm going to try implementing this evening: 这是我今晚要尝试实施的方法:

docker create --build-arg TOKEN <my priv token> <dockerFile>

maybe declare the arg in the docker file? 也许在docker文件中声明arg?

ARG TOKEN  

then in the script have npm install use that TOKEN in dependencies 然后在脚本中有npm install在依赖项中使用那个TOKEN

"privModule": "git+https://${TOKEN}:x-oauth-basic@github.com/<githubID>/<privateModule>.git"

and if that doesn't work, somehow replace that var in the package.json (with sed) or have npm use an environment var. 如果这不起作用,以某种方式替换package.json中的var(使用sed)或使用npm使用环境var。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM