我在docker中运行Python 3.6应用程序,并希望将输出文件直接存储在GCS存储桶中。在docker镜像中跟踪我的声音听起来很明显:
gcloud compute scp
的文件复制到存储桶但是,如何在不切换到另一个venv的情况下复制文件?
答案 0 :(得分:0)
您可以从Python应用程序或第二个Python脚本将文件存储到GCS,这非常简单 - https://pypi.python.org/pypi/google-cloud-storage
答案 1 :(得分:0)
解决方案 - 创建文件gcpupload.py
from google.cloud import storage
def main():
client = storage.Client()
bucket = client.get_bucket('my_bucket')
blob = bucket.blob('myfile.txt')
blob.upload_from_filename(filename='/path/myfile.txt')
if __name__ == "__main__":
main()
运行脚本:
#!/bin/sh
# Need to create the api keys file through google cloud console
# API's and services -> credentials -> service account key
export GOOGLE_APPLICATION_CREDENTIALS=google-api-keys.json
python gcpupload.py