所以这就是我想做的事。
我可以顺利完成第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
,就像这样
由于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.
有更好的方法吗?我怎样才能至少从gitlab-ci构建环境中访问我的Droplet?
答案 0 :(得分:0)
我刚刚回答了以下相关问题:Create react app + Gitlab CI + Digital Ocean droplet - Pipeline succeeds but Docker container is deleted 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'
代码功劳归于https://stackoverflow.com/users/6655011/leonardo-sarmento-de-castro