2017-02-16 69 views
0

我閱讀文檔:https://gitlab.ida.liu.se/help/ci/ssh_keys/README.mdSSH例如不與碼頭工人工作:混帳/ DIND圖像

我使用的是當前gitlab-ci.yml:

image: docker:git 
services: 
- docker:dind 
stages: 
- node_test 
- docker_one 
variables: 
    DOCKER_DRIVER: overlay 
before_script: 
    # Install ssh-agent if not already installed, it is required by Docker. 
    # (change apt-get to yum if you use a CentOS-based image) 
    - 'which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)' 
    # Run ssh-agent (inside the build environment) 
    - eval $(ssh-agent -s) 
    # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store 
    - ssh-add <(echo "$SSH_PRIVATE_KEY") 
    # For Docker builds disable host key checking. Be aware that by adding that 
    # you are suspectible to man-in-the-middle attacks. 
    # WARNING: Use this only with the Docker executor, if you use it with shell 
    # you will overwrite your user's SSH config. 
    - mkdir -p ~/.ssh 
    - ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts 
    - ssh-keyscan gitlab.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts 
    - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' 
node_test: 
    image: node:7.3.0 
    stage: node_test 
    script: 
    - ls 
docker_one: 
    stage: docker_one 
    script: 
    - docker info 

node_test通行證:

Running with gitlab-ci-multi-runner 1.10.4 (b32125f) 
Using Docker executor with image node:7.3.0 ... 
Starting service docker:dind ... 
Pulling docker image docker:dind ... 
Waiting for services to be up and running... 
Pulling docker image node:7.3.0 ... 
Running on runner-4e4528ca-project-2641294-concurrent-0 via runner-4e4528ca-machine-1487244621-a8ff6b11-digital-ocean-4gb... 
Cloning repository... 
Cloning into '/builds/instanty/test'... 
Checking out 0b261283 as master... 
Skipping Git submodules setup 
Identity added: /dev/fd/63 (rsa w/o comment) 
$ which ssh-agent || (apt-get update -y && apt-get install openssh-client -y) 
/usr/bin/ssh-agent 
$ eval $(ssh-agent -s) 
Agent pid 11 
$ ssh-add <(echo "$SSH_PRIVATE_KEY") 
$ mkdir -p ~/.ssh 
$ ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
$ ssh-keyscan gitlab.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 
$ [[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config 
$ ls 
Build succeeded 

當我用圖像泊塢窗它失敗:Git和服務DIND:

Running with gitlab-ci-multi-runner 1.10.4 (b32125f) 
Using Docker executor with image docker:git ... 
Starting service docker:dind ... 
Pulling docker image docker:dind ... 
Waiting for services to be up and running... 
Pulling docker image docker:git ... 
Running on runner-4e4528ca-project-2641294-concurrent-0 via runner-4e4528ca-machine-1487244733-2b616928-digital-ocean-4gb... 
Cloning repository... 
Cloning into '/builds/instanty/test'... 
Checking out 0b261283 as master... 
Skipping Git submodules setup 
$ which ssh-agent || (apt-get update -y && apt-get install openssh-client -y) 
/usr/bin/ssh-agent 
$ eval $(ssh-agent -s) 
Agent pid 14 
$ ssh-add <(echo "$SSH_PRIVATE_KEY") 
/bin/sh: eval: line 50: syntax error: unexpected "(" 
ERROR: Build failed: exit code 2 

爲什麼此圖像失敗?

回答

0

你正在使用的語法不是由你的形象使用的shell確認:
ssh-add <(echo "$SSH_PRIVATE_KEY")

SSH-ADD需要一個文件作爲參數。因此,要解決這個問題,你可以替換該行:

回聲 「$ SSH_PRIVATE_KEY」> ssh.priv
SSH-添加ssh.priv