2014-11-07 10 views
6

Ich bin dabei, die Einrichtung eines Node.js-Dienstes mit Docker einzurichten.Docker + Nodejs + Private Repo + Privates NPM-Modul - Zugriffsprobleme

Die Dockerfile, die ich habe, ist aus verschiedenen Beispielen aus dem Netz zusammengesetzt. Das Verzeichnis für den Dockerfile umfasst:

  • Dockerfile
  • id_rsa
  • start.sh

Dies ist die Dockerfile ist:

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 

Nachdem das Set-up ist komplett , start.sh läuft und ich habe Probleme mit einer privaten NPM-Abhängigkeit, die die private Node.js serv Eis hat. Dies ist, was start.sh tut:

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 für ExampleRepo gibt ein privates Modul, das wir so importieren:

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

Wenn npm installieren, um dieses Repo wird, es gibt diese Protokolle:

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]thub.com: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 

ich dachte, dass der git clont der privaten Knoten Infahrtsetzung funktioniert gut, eines seiner privaten NPM Abhängigkeiten reibungslos würde installieren.

Ich bin ziemlich positiv, dass meine SSH-Einrichtung fehlerhaft ist (und dass es sich selbst nicht manifestiert, während Git das private Eltern-Repo klont), weil ich Benutzernamen und Passwort zum Link hinzugefügt habe. Ich bin jedoch unsicher und würde mir einige Hinweise dazu geben, wie dies richtig zu machen ist.

+1

Zum einen benötigen Sie die openssh und ca-Zertifikat Pakete. Versuchen Sie auch, Ihren Container interaktiv auszuführen und alles durchzugehen, um diese Dinge herauszufinden. docker run -it /bin/bash – user2105103

Antwort

5

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

Works, weil Sie das Bestehen der username und password und tun es über https

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

ausfällt, weil Sie direkt über ssh anschließen und Docker nicht tun, um jede ssh agent Weiterleitung von die Host-Maschine.

Unfortunatly dosen't es wie npm aussieht unterstützt jedes URL-Format Benutzername und Passwort wie Ihre Klon Linie zu senden: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Sie haben würden Ihren SSH-Schlüssel zu dem Docker Behälter (nicht Reccomended)

hinzufügen

Oder etwas flippiger teilen Sie vom Host SSH_SOCKET wie:

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

1

Hier ist ein Ansatz, den ich Umsetzung dieser Abend versuchen werde:

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

vielleicht die arg in der docker-Datei deklarieren?

ARG TOKEN 

dann im Skript haben npm Verwendung, die

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

in Abhängigkeiten TOKEN installieren und wenn das nicht funktioniert, ersetzen Sie irgendwie, dass var im package.json (mit sed) oder haben npm Verwenden Sie eine Umgebung var.

Verwandte Themen