从gitlab-ci将docker容器部署到数字海洋液滴

Fre*_*all 13 digital-ocean gitlab-ci

所以这就是我想要做的.

  1. 推送到git中掌握
  2. 让gitlab-ci听到推动启动管道
  3. 管道构建代码​​并将docker容器推送到gitlab注册表
  4. 管道通过ssh登录到数字海洋液滴
  5. 管道从gitlab注册表中拉出docker容器
  6. 管道启动容器

我可以顺利到第4步没问题.但是第4步只是失败了.我尝试过ssh key方法:

但那没用.

所以我尝试了这样的纯文本密码方法:

image: gitlab/dind:latest

before_script:
 - apt-get update -y && apt-get install sshpass

stages:
 - deploy

deploy:
  stage: deploy
  script:
    - sshpass -p "mypassword" ssh root@x.x.x.x 'echo $HOME'
Run Code Online (Sandbox Code Playgroud)

这个版本code 1就像这样退出

由于stdin不是终端,因此不会分配伪终端.

ln: failed to create symbolic link '/sys/fs/cgroup/systemd/name=systemd': Operation not permitted
/usr/local/bin/wrapdocker: line 113:    54 Killed                  docker daemon $DOCKER_DAEMON_ARGS &> /var/log/docker.log
Timed out trying to connect to internal docker host. 
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?我怎样才能从gitlab-ci构建环境中访问我的Droplet?

d g*_*d g 2

我刚刚回答了这个相关问题:创建反应应用程序+ Gitlab CI + Digital Ocean Droplet - Pipeline successed but Docker container iselalet right after

这是他用来设置 ssh 信用的解决方案:

before_script:
  ## Install ssh agent (so we can access the Digital Ocean Droplet) and run it.
  - apk update && apk add openssh-client
  - eval $(ssh-agent -s)

  ## Write the environment variable value to the agent store, create the ssh directory and give the right permissions to it.
  - echo "$SECRETS_DIGITAL_OCEAN_DROPLET_SSH_KEY" | ssh-add -
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh

  ## Make sure that ssh will trust the new host, instead of asking
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

  ## Test it!
  - ssh -t ${SECRETS_DIGITAL_OCEAN_DROPLET_USER}@${SECRETS_DIGITAL_OCEAN_DROPLET_IP} 'echo $HOME'
Run Code Online (Sandbox Code Playgroud)

代码信用转到/sf/users/465850801/