首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ssh代理在gitlab ci中运行部署作业?

如何使用ssh代理在gitlab ci中运行部署作业?
EN

Stack Overflow用户
提问于 2018-12-23 03:55:54
回答 2查看 1.7K关注 0票数 2

我在伊朗有一台服务器,我想使用gitlab ci打开到我的服务器的ssh隧道。

但由于谷歌的云服务,gitlab看不到伊朗的IP地址。

有没有办法使用伊朗的中间服务器打开从gitlab到我的代理服务器的代理隧道,然后使用docker从gitlab registery中提取图像?

考虑到伊朗的服务器无法连接到gitlab,gitlab也无法连接到伊朗的服务器。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-24 07:17:20

这对我来说也是有效的

代码语言:javascript
复制
deploy:
  environment:
    name: production
    url: http://example.com
  image: ubuntu:latest
  stage: deploy
  only:
    - master
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    ## Install rsync to create mirror between runner and host.
    - apt-get install -y rsync
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - eval $(ssh-agent -s)
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode)
    - ssh -o StrictHostKeyChecking=no $SSH_USER@"$SSH_HOST" 'ls -la && ssh user@host "cd ~/api && docker-compose pull && docker-compose up -d"'

我还在这里描述了我用波斯语做的所有事情:https://virgol.io/@aminkt

票数 1
EN

Stack Overflow用户

发布于 2019-01-22 01:39:42

我已经成功地使用了这样的代码

代码语言:javascript
复制
before_script:
  - apt-get update -y
  - apt-get install openssh-client curl -y


integration:
  stage: integration
  script:
    - mkdir ~/.ssh/
    - eval $(ssh-agent -s)
    - echo "$SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - ssh -fN -L 1029:localhost:1729 user@$HOST -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no 2>&1
    - ssh -fN -L 9013:localhost:9713 user@$HOST -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no 2>&1
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53898891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档