上传到 Cloud Storage 存储桶时如何设置内容类型?

How to set the content-type, when uploading to Cloud Storage bucket?

*.tar.gz 构建工件上传到 Cloud Storage 存储桶时,它错误地应用了 MIME 类型 application/tar,而它必须应用 MIME 类型 application/tar+gzip(或官方 MIME 类型application/gzip),以便能够再次下载和提取上传的 *.tar.gz 存档。这仅在我之后手动设置 MIME 类型(在对象详细信息中)时有效,但我正在寻找一种方法来立即定义正确的 MIME 类型。如何做到这一点?

产生问题的cloudbuild.yaml大致如下所示:

steps:
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:latest'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
      - tar -zcf ./test_${SHORT_SHA}.tar.gz ./$_UPLOAD_DIRNAME
    env:
      - '_UPLOAD_DIRNAME=$_UPLOAD_DIRNAME'
      - 'SHORT_SHA=$SHORT_SHA'
artifacts:
  objects:
    location: 'gs://some-bucket/'
    paths: ['*.tar.gz']

看完:Working With Object Metadata,原来artifacts节点不够用。 gsutil 似乎是明确传递所需 MIME 类型的唯一方法 application/tar+gzip:

steps:
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:latest'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
        tar -zcf ./test_${SHORT_SHA}.tar.gz ./$_UPLOAD_DIRNAME
        gsutil -h "Content-Type:application/tar+gzip" cp ./test_${SHORT_SHA}.tar.gz ${_GOOGLE_STORAGE_BUCKET}
        gsutil ls -L ${_GOOGLE_STORAGE_BUCKET}test_${SHORT_SHA}.tar.gz
    env:
      - '_UPLOAD_DIRNAME=$_UPLOAD_DIRNAME'
      - '_GOOGLE_STORAGE_BUCKET=$_GOOGLE_STORAGE_BUCKET'
      - 'SHORT_SHA=$SHORT_SHA'