If you don't need the sync to be immediate (i.e., w/in seconds), you could set up a cron job to periodically pull down the .zip
archive of your repo, and upload it to Google Cloud Storage.
In your app.yaml
:
runtime: python37
In your cron.yaml
:
cron:
- description: "sync from git repo"
url: /tasks/sync
schedule: every 1 minute
In your main.py
:
from urllib.request import urlopen
from zipfile import ZipFile
from flask import Flask
from google.cloud import storage
app = Flask(__name__)
client = storage.Client(project='your-project-name')
bucket = client.get_bucket('your-bucket-name')
# Path to the archive of your repository's master branch
repo = 'https://github.com/your-username/your-repo-name/archive/master.zip'
@app.route('/tasks/sync')
def sync():
with ZipFile(BytesIO(urlopen(repo).read())) as zipfile:
for filename in zipfile.namelist():
blob = storage.Blob(filename, bucket)
blob.upload_from_string(zipfile.read(filename))
Deploy with:
$ gcloud app deploy
$ gcloud app deploy cron.yaml
gsutil rsync
cloud SDK utility to sync the repo content to the bucket. – Japhetic