【问题标题】:Deploy docker container to digital ocean droplet from gitlab-ci从 gitlab-ci 将 docker 容器部署到数字海洋水滴
【发布时间】:2019-01-28 12:13:20
【问题描述】:

这就是我想要做的。

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

我可以达到第 4 步没问题。但是第 4 步只是失败了。我已经尝试过 ssh 密钥方法:

但这没有用。

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

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'

这个版本只是像这样以code 1 退出

不会分配伪终端,因为标准输入不是终端。

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. 

有没有更好的方法来做到这一点?我如何至少从 gitlab-ci 构建环境中访问我的 droplet?

【问题讨论】:

  • 您是否设法找到解决方法或解决此问题?

标签: digital-ocean gitlab-ci


【解决方案1】:

我刚刚回答了这个相关问题:Create react app + Gitlab CI + Digital Ocean droplet - Pipeline succeeds but Docker container is deleted right after

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

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'

代码致谢https://stackoverflow.com/users/6655011/leonardo-sarmento-de-castro

【讨论】:

    猜你喜欢
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    相关资源
    最近更新 更多