社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Git

将git repo同步到谷歌云

John Constantine • 5 年前 • 1074 次点击  

所以假设我有一个Git存储库 https://github.com/jc/ 我有一个Google Bucket的位置 gs://acme-sales/ .

有没有一种方法可以编写一个python程序来更新在github中所做的更改,并在每次运行它时将它们同步到google cloud?

我想我们得用 gitpython 从Github链接读取该文件,但我如何继续将该文件更新到Google Bucket。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38759
 
1074 次点击  
文章 [ 2 ]  |  最新文章 5 年前
A.Queue
Reply   •   1 楼
A.Queue    6 年前

添加到上一个答案中。

你可以选择 "Automatically Mirror from GitHub or Bitbucket" ,这是自描述性的。或者你可以使用 "Automatic Build Trigger" 直接定制 build steps 执行某些动作。

Dustin Ingram
Reply   •   2 楼
Dustin Ingram    6 年前

如果您不需要立即同步(即,w/秒),可以设置一个 cron job 定期下拉 .zip 将你的报告存档,并上传到谷歌云存储。

在你的 app.yaml :

runtime: python37

在你的 cron.yaml :

cron:
- description: "sync from git repo"
  url: /tasks/sync
  schedule: every 1 minute

在你的 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))

部署方式:

$ gcloud app deploy
$ gcloud app deploy cron.yaml