Zin Yosrim
Zin Yosrim

Reputation: 1684

Copy a file from a docker image running on a Google Compute Engine VM to a Google Storage bucket

I'm running a Python 3.6 application within docker und would like to store the output file directly in a GCS bucket. What sounds obvious to me doing following within the docker image:

But, how can I copy the file without switching to another venv?

Upvotes: 1

Views: 1568

Answers (2)

Zin Yosrim
Zin Yosrim

Reputation: 1684

Solution - create file 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()

Run the script:

#!/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 

Upvotes: 2

Gal Ben-Haim
Gal Ben-Haim

Reputation: 17803

you can store the file to GCS from your Python application or from a 2nd Python script, this is very easy - https://pypi.python.org/pypi/google-cloud-storage

Upvotes: 0

Related Questions