无人机CI部署到Google Compute Engine



我试图使用无人机CI自动在Google Cloud Compute Engine上部署我的应用程序。我尝试了很多方式,但我不能部署任何东西。

我有测试并发布阶段正常运行,我可以将代码自动将我的代码推到我的Google Container注册表,构建图像并将其推开。

i在我的计算引擎实例中验证,我坚持尝试将机器连接到Google容器注册表,但我无法设法运行构建的图像。这是我缺乏的最后一步,我无法做到。

这是我的.drone-ci.yml文件,其中包括:

kind: pipeline
name: my-app
steps:
  - name: test
    image: node:11-alpine
    commands:
      - npm install
      - npm run test
  - name: publish
    image: plugins/gcr
    settings:
      repo: project-id/my-app
      dockerfile: Dockerfile
      tags: latest
      json_key:
        from_secret: google_credentials
  - name: deploy
    image: google/cloud-sdk:alpine
    environment:
      google_credentials:
        from_secret: google_credentials
    commands:
      - echo $google_credentials > /tmp/$CI_PIPELINE_ID.json
      - gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
      - gcloud compute ssh my-instance --zone my-zone --command "cat $google_credentials | sudo docker login -u _json_key --password-stdin https://gcr.io"
      - gcloud compute ssh my-instance --zone us-east1-b --command "sudo docker run -d -p 80:3000 --restart always --env-file ./env.list gcr.io/project-id/my-app:latest"

它抛出此错误(是最后一个错误(:

cat: '{': No such file or directory
bash: line 1: type:: command not found
bash: line 2: project_id:: command not found
bash: line 3: private_key_id:: command not found
bash: line 4: private_key:: command not found
bash: line 5: client_email:: command not found
bash: line 6: client_id:: command not found
bash: line 7: auth_uri:: command not found
bash: line 8: token_uri:: command not found
bash: line 9: auth_provider_x509_cert_url:: command not found
bash: line 10: client_x509_cert_url:: command not found
bash: -c: line 11: syntax error near unexpected token `}'
bash: -c: line 11: `} | sudo docker login -u _json_key --password-stdin 
https://gcr.io'

我尝试了其他方式,但是我从未成功地对Google Container注册表进行验证。我该如何从实例中验证Docker Deamon?

此处的故障命令是:

cat $google_credentials | sudo docker login -u _json_key --password-stdin https://gcr.io

您的变量$google_credentials保留JSON密钥的目录:它不符合文件的路径,因此cat $google_credentials没有意义。由于文件/tmp/$CI_PIPELINE_ID.json包含您的JSON密钥,因此您应该写过:

cat /tmp/$CI_PIPELINE_ID.json | 
    sudo docker login -u _json_key --password-stdin https://gcr.io

或(未经测试,请仔细使用(:

echo $google_credentials | 
    sudo docker login -u _json_key --password-stdin https://gcr.io

第三个解决方案(我确定这有效,因为我已经使用它来验证了(是:

docker login -u _json_key -p "$(cat /tmp/$CI_PIPELINE_ID.json)" https://gcr.io

相关内容

  • 没有找到相关文章

最新更新