【问题标题】:Bitbucket Pipelines: gcloud crashed (UnicodeDecodeError)Bitbucket 管道:gcloud 崩溃 (UnicodeDecodeError)
【发布时间】:2018-07-31 19:21:21
【问题描述】:

编辑:我想指出,如果我在计算机上使用 cloud sdk 手动部署,则不会发生此问题。仅使用管道

再次编辑:我在我的 gcloud 应用部署中添加了 verbosity=debug。以下是生成的内容:

Do you want to continue (Y/n)?  
DEBUG: No bucket specified, retrieving default bucket.
DEBUG: Using bucket [gs://staging.PROJECT.appspot.com].
DEBUG: Service [appengineflex.googleapis.com] is already enabled for project [PROJECT]
Beginning deployment of service [default]...
INFO: Need Dockerfile to be generated for runtime php
Building and pushing image for service [default]
DEBUG: 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128)

Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 845, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 767, in Run
    resources = command_instance.Run(args)
  File "/usr/lib/google-cloud-sdk/lib/surface/app/deploy.py", line 87, in Run
    parallel_build=False)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 594, in RunDeploy
    flex_image_build_option=flex_image_build_option)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 393, in Deploy
    flex_image_build_option)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 283, in _PossiblyBuildAndPush
    self.deploy_options.parallel_build)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/deploy_command_util.py", line 427, in BuildAndPushDockerImage
    skip_files=service.parsed.skip_files.regex)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/cloud_build.py", line 151, in UploadSource
    skip_files)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/cloud_build.py", line 122, in _GetIncludedPaths
    paths = docker.utils.exclude_paths(root, exclude)
  File "/usr/bin/../lib/google-cloud-sdk/lib/third_party/docker/docker/utils/utils.py", line 111, in exclude_paths
    all_paths = get_paths(root)
  File "/usr/bin/../lib/google-cloud-sdk/lib/third_party/docker/docker/utils/utils.py", line 135, in get_paths
    for parent, dirs, files in os.walk(root, followlinks=False):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 286, in walk
    if isdir(join(top, name)):
  File "/usr/lib/python2.7/posixpath.py", line 80, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128)
ERROR: gcloud crashed (UnicodeDecodeError): 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128)

我正在尝试使用 bitbucket 管道部署到 gcloud。

在完成某些文件的编辑(我正在使用应用引擎部署 wordpress 网站)之前,我最初没有遇到这个奇怪的错误。

但是,即使将我的存储库恢复到我的构建成功时,它最终还是再次失败,并出现 `ERROR: gcloud crashed (UnicodeDecodeError): 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in范围(128)

这对我来说毫无意义。它工作正常。有没有办法扩展此错误或查找导致此错误发生的文件?

以下是在管道中触发构建后:

+ gcloud app deploy
Services to deploy:
descriptor:      [/opt/atlassian/pipelines/agent/build/app.yaml]
source:          [/opt/atlassian/pipelines/agent/build]
target project:  [project]
target service:  [default]
target version:  [20180731t175825]
target url:      [https://site.appspot.com]
Do you want to continue (Y/n)?  
Beginning deployment of service [default]...
Building and pushing image for service [default]
ERROR: gcloud crashed (UnicodeDecodeError): 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128)
If you would like to report this issue, please run the following command:
  gcloud feedback
To check gcloud for common problems, please run the following command:
  gcloud info --run-diagnostics

这是我的 bitbucket-pipelines.yml

图片:php:7.1.1

pipelines:
  branches:
   master:
    - step:
        # set GCLOUD_PROJECT environment variablee to your project ID
        # set GCLOUD_API_KEYFILE environment variable to base64-encoded keyfile as described here: https://confluence.atlassian.com/x/dm2xNQ
        name: Deploy to GCloud
        deployment: production   # set to test, staging or production
        # trigger: manual  # uncomment to have a manual step
        image: google/cloud-sdk:latest
        caches:
          - composer
        script:
          - echo $GCLOUD_API_KEYFILE | base64 --decode --ignore-garbage > ./gcloud-api-key.json
          - gcloud auth activate-service-account --key-file gcloud-api-key.json
          - gcloud config set project $GCLOUD_PROJECT
          - gcloud app deploy app.yaml

app.yaml

runtime: php
env: flex

handlers:
- url: /(.*\.(htm|html|css|js))$
  static_files: wordpress/\1
  upload: wordpress/.*\.(htm|html|css|js)$
  application_readable: true

- url: /wp-content/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/wp-content/\1
  upload: wordpress/wp-content/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/\1
  upload: wordpress/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /wp-includes/images/media/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/wp-includes/images/media/\1
  upload: wordpress/wp-includes/images/media/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /wp-admin/(.+)
  script: wordpress/wp-admin/\1
  secure: always

- url: /wp-admin/
  script: wordpress/wp-admin/index.php
  secure: always

- url: /wp-login.php
  script: wordpress/wp-login.php
  secure: always

- url: /wp-cron.php
  script: wordpress/wp-cron.php
  login: admin

- url: /xmlrpc.php
  script: wordpress/xmlrpc.php

- url: /wp-(.+).php
  script: wordpress/wp-\1.php

- url: /(.+)?/?
  script: wordpress/index.php

beta_settings:
  cloud_sql_instances: project:us-central1:match

runtime_config:
  document_root: wordpress
  skip_lockdown_document_root: true

env_variables:
  WHITELIST_FUNCTIONS: escapeshellarg,escapeshellcmd,exec,pclose,popen,shell_exec,phpversion,php_uname

【问题讨论】:

  • 感谢您的回复。你知道我怎样才能得到回溯吗?
  • 如果发生错误时它没有发出一个,那么可能将--verbosity标志设置为debug(见gcloud --help
  • 我已经编辑了我的答案以包含回溯。你能看看吗?你认为这是我使用的 sdk 镜像的问题吗?
  • 这看起来像是包含非 ascii 字符的路径元素的问题。您机器上的路径或用户名中是否有任何非 ASCII 字符?
  • 我不知道在哪里。我的用户名不包括它,这只是使用 bitbucket 时的问题。我可以通过我计算机上的 google sdk 部署相同的代码和 app.yaml。有没有办法可以在我的管道文件中使用不同的 sdk 版本?

标签: google-app-engine bitbucket gcloud


【解决方案1】:

问题是由 gcloud 尝试处理的路径中的非 ascii 字符引起的。

消息UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128) 是 Python 异常,表示尝试将字节 0xe2 编码为 ascii 时出现问题。

运行 gcloud --verbosity=debug .... 会生成 Python 回溯。

回溯结束

  File "/usr/bin/../lib/google-cloud-sdk/lib/third_party/docker/docker/utils/utils.py", line 135, in get_paths
    for parent, dirs, files in os.walk(root, followlinks=False):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 296, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 286, in walk
    if isdir(join(top, name)):
  File "/usr/lib/python2.7/posixpath.py", line 80, in join
    path += '/' + b

表明 Python 代码正在遍历文件系统层次结构(这就是 os.walk 所做的)并且有问题的操作正在构建路径(这是 path += '/' + b 所做的)。

鉴于此信息,下一步是检查与非 ascii 字符的部署相关的路径,OP 已经能够使用此 superuser answer 中的技术成功地做到这一点。

【讨论】:

  • 再次感谢您的帮助。我认为 ascii 代码在文件中 - 而不是在文件路径中。感谢上帝的 power shell 命令。我为此浪费了几个小时……哈哈
猜你喜欢
  • 1970-01-01
  • 2018-07-14
  • 2019-08-26
  • 2019-08-03
  • 2017-08-11
  • 2019-02-13
  • 2020-11-06
  • 2021-10-29
  • 2019-09-02
相关资源
最近更新 更多