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

ssh to deploy machine and running python file gives error not found even if it exists

我已经更改了用户的密码(让我们称他为 staging_user)gitlab-运行ner 将用于登录到 运行 登台服务器的另一台机器,

并在 .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-运行ner 运行s 在 git01 机器上,从那里 gitlab-运行ner ssh 到 staging_server 用户是 staging_user(见SSH_EXEC 以上数值)

我注意到 GITSSHKEY 是存储在 gitlab 项目下的变量: gitlab.com/test_group/project_site/settings/ci_cd 。所以我认为需要更新这个 SSH 密钥,但我有点困惑,不确定 运行 ssh-keygen 在哪里生成一个新密钥并粘贴到这里,我是否 运行 ssh-keygen on git01 来自其中 gitlab-运行ner 正在 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

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

上的 public 密钥

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

经过讨论,OP Ciasto piekarz states

I have discovered that if the container is already running then we get this error, but if we stop the running container and update the branch for gitlab-runner to run the pipeline then the deployment goes successful