2014-11-07 15 views
6

Tôi đang trong quá trình thiết lập việc triển khai Dịch vụ Node.js bằng Docker.Docker + Nodejs + Repo riêng tư + Module NPM riêng tư - Các sự cố truy cập

Dockerfile tôi đã ghép nối với nhau từ các ví dụ khác nhau từ khắp nơi trên mạng. Thư mục cho Dockerfile bao gồm:

  • Dockerfile
  • id_rsa
  • start.sh

Đây là 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 

Sau khi thiết lập xong , start.sh chạy và tôi gặp sự cố với phụ thuộc NPM riêng tư mà dịch vụ Node.js riêng tư băng có. Đây là những gì start.sh được thực hiện:

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 

Trong package.json cho ExampleRepo, có một mô-đun riêng mà chúng tôi nhập khẩu như thế này:

"dependencies": { 
    "scribe": "git+ssh://[email protected]:Company/PrivateDep.git" 
}, 

Khi NPM cài đặt được để repo này, nó xuất ra các nhật ký này:

npm ERR! git clone [email protected]:InboxAppCo/scribe.git Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-InboxAppCo-scribe-git-abae334a'... 
npm ERR! git clone [email protected]:InboxAppCo/scribe.git 
npm ERR! git clone [email protected]: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 [email protected]:InboxAppCo/scribe.git Permission denied (publickey). 
npm ERR! git clone [email protected]:InboxAppCo/scribe.git fatal: Could not read from remote repository. 
npm ERR! git clone [email protected]:InboxAppCo/scribe.git 
npm ERR! git clone [email protected]:InboxAppCo/scribe.git Please make sure you have the correct access rights 
npm ERR! git clone [email protected]:InboxAppCo/scribe.git and the repository exists. 
npm ERR! Error: `git "clone" "--mirror" "[email protected]: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 

Tôi nghĩ rằng vì bản sao của dịch vụ Node riêng tư hoạt động tốt, bất kỳ phụ thuộc NPM riêng nào của nó sẽ cài đặt trơn tru.

Tôi khá tích cực rằng việc thiết lập SSH của tôi là không hoàn thiện (và nó không thể hiện bản thân trong khi git nhân bản repo cha mẹ riêng) vì tôi đã thêm tên người dùng và mật khẩu vào liên kết. Tuy nhiên, tôi không chắc chắn và sẽ đánh giá cao một số hướng dẫn về cách thực hiện điều này một cách chính xác.

+1

Đối với một điều, bạn cần gói openssh và ca-certificate. Ngoài ra, hãy thử chạy thùng chứa của bạn tương tác và bước tất cả mọi thứ để tìm ra những thứ này. docker run -it /bin/bash – user2105103

Trả lời

5

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

trình, bởi vì bạn đang đi qua các usernamepassword và làm nó trên https

"dependencies": { 
    "scribe": "git+ssh://[email protected]:Company/PrivateDep.git" 
}, 

thất bại, bởi vì bạn đang kết nối trực tiếp trên ssh và Docker không làm bất cứ ssh agent chuyển tiếp từ máy chủ.

Đáng tiếc là nó doesnt trông giống như NPM hỗ trợ bất kỳ định dạng url gửi tên người dùng và mật khẩu như dòng clone của bạn: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Bạn sẽ phải thêm phím ssh của bạn để container Docker (Không reccomended)

Hoặc làm điều gì đó sôi nổi như chia sẻ bạn SSH_SOCKET từ các máy chủ như:

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

1

Dưới đây là một cách tiếp cận tôi sẽ cố gắng thực hiện tối nay:

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

có thể tuyên bố arg trong tệp docker?

ARG TOKEN 

sau đó trong kịch bản có NPM cài đặt sử dụng mà TOKEN trong phụ thuộc

"privModule": "git+https://${TOKEN}:[email protected]/<githubID>/<privateModule>.git" 

và nếu điều đó không làm việc, bằng cách nào đó thay thế var rằng trong package.json (với sed) hoặc có NPM sử dụng môi trường var.

Các vấn đề liên quan