部署机器和运行python文件的ssh即使存在也找不到错误

时间:2018-05-16 03:54:00

标签: docker gitlab ssh-keys gitlab-ci-runner

我已经更改了用户的密码(让我们称之为staging_user)gitlab-runner将用于登录运行登台服务器的其他计算机,

.gitlab-ci.yml

staging_deploy:
  stage: deploy
  variables:
    SSH_EXEC: "ssh staging_user@staging_server"
    DEPLOY_PATH: "/home/staging_user/project_site"
  only:
    - staging
  script:
    - ${SSH_EXEC} "if [ -d ${DEPLOY_PATH} ]; then \rm -r ${DEPLOY_PATH}/*; else mkdir -p ${DEPLOY_PATH}; fi"
    - echo -e ${GITSSHKEY} > conf/.ssh/id_rsa
    - scp -r * staging-user@staging_server://home/staging_user/project_site/
    - ${SSH_EXEC} "cd ${DEPLOY_PATH}/; docker-compose build --no-cache --force-rm; docker-compose up -d"
    - ${SSH_EXEC} "docker exec website_staging python /var/www/website.com/src/manage.py collectstatic --no-input"

gitlab-runner在git01机器上运行,从那里gitlab-runner ssh到staging_server用户是staging_user(参见上面的SSH_EXEC值)

我注意到GITSSHKEY是存储在gitlab项目下的变量:gitlab.com/test_group/project_site/settings/ci_cd。所以我认为需要更新这个SSH密钥,但我有点困惑,不知道在哪里运行ssh-keygen来生成一个新密钥并粘贴到这里,我是否在git01上运行ssh-keygen,其中gitlab-runner是ssh'ing或在staging_server机器上。

我收到错误

Service 'web' failed to build: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/0a/0a2bad7da9b55f3121f0829de061f002ef059717fc2ed23c135443081200000e/data?Expires=1526503430&Signature=LZNRPPcqYzFoeE94jHgdxyN7gONaewh3ZF2688IVPhrOFKt-DB20gcSZIytqiDff8Hk7CS60SFKoROkU4VWMroByNqAcrFeMJGEAG-GKSSLXKPqQUsxYeXyW5rRGGbC8CqARQKsj1GBR-fTvRstcrnfhQVrn9gv~IFtqRXNB-LM_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout
website_web_1 is up-to-date
$ ${SSH_EXEC} "ls -lh /var/www/website.com/src/manage.py"
-rw-rw-r-- 1 staging_user staging_user 280 May 15 16:26 /var/www/website.com/src/manage.py
$ ${SSH_EXEC} "docker exec website_web_1 python /var/www/website.com/src/manage.py collectstatic --no-input"
python: can't open file '/var/www/website.com/src/manage.py': [Errno 2] No such file or directory

1 个答案:

答案 0 :(得分:1)

关于初始问题的注意事项:更改密码不应影响ssh密钥,因为它依赖于远程服务器~staging_user/.ssh/authorized_keys上的公钥。

在源计算机上需要生成新的ssh密钥(将ssh启动到远程计算机的那个),并且您需要首先将公钥部署到远程~staging_user/.ssh/authorized_keys文件。

经过讨论,OP Ciasto piekarzin the comments

  

我发现如果容器已经运行,那么我们会收到此错误,但如果我们停止正在运行的容器并更新gitlab-runner的分支以运行管道,那么部署就会成功