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))
如果您不需要立即同步(即,以秒为单位),您可以设置一个cron job来定期下拉回购的
.zip
存档,并将其上载到Google云存储。在在您的
app.yaml
中:在您的
^{pr2}$cron.yaml
中:在您的
main.py
中:部署方式:
加上前面的答案。在
您可以选择"Automatically Mirror from GitHub or Bitbucket",这是自描述性的。或者您可以直接将"Automatic Build Trigger"与自定义build steps一起使用来执行某些操作。在
我建议您使用Google Cloud Build。它允许您同步您的repo,并使用gsutil自动更新存储,即each commits上的
gs://acme-sales
到GitHub存储库:您可以在GitHub上通过connecting your repository即
https://github.com/jc/<repo_name>
到Google Cloud Build,使用下面的链接:相关问题 更多 >
编程相关推荐