比较目录,有效地将更改同步到aws,并使cdn失效。
wood的Python项目详细描述
Wood是一个表示目录树、计算比较的工具箱 以及影响s3、cloudfront和cloudflare中的这些变化。它 开始时是我个人网站的一组部署脚本,但后来 有些东西我吃得太多了,藏不住 另一个网站存储库。它不像,比如说,请求那样精致,但是应该 对任何希望将网站高效部署到aws的人都有用,和/或 使用cloudflare作为cdn。
值得注意的是,与aws cli工具或boto3不同,wood不依赖文件 时间戳,而不是使用md5校验和进行最小数量的更改 可能在S3它还有一个算法,用于将失效路径聚合到 使CloudFront Free层尽可能运行。同步器和无效器 以通用方式实现,允许轻松扩展到 根据需要提供服务。
功能
- 树表示法
- 树比较
- S3中比较的动作
- 根据需要使cloudfront和cloudflare中的路径无效
演示
importwood# low-level comparison of two local directoriescomparison=wood.compare('~/dir','~/.snapshot/hourly.1/dir')comparison.new()# files added since the snapshotcomparison.modified()# files modified since the snapshotcomparison.deleted()# files deleted since the snapshotimportpathlibimportboto3local_base=pathlib.Path('/path/to/web/root')bucket=boto3.resource('s3').Bucket('example.com')# create representations of the local and remote treesto_deploy=wood.root(local_base)deployed=wood.s3.objects_to_root(bucket.objects.all())# compare the two as if they were local directoriescomparison=wood.compare(to_deploy,deployed)# write all changes (additions, modifications, deletions) to the S3 bucketsyncer=wood.s3.Syncer(local_base,bucket)syncer.sync(comparison)# invalidate the minimum amount in CloudFront to ensure the changes are# visible, using prefix grouping where possiblecloudfront=boto3.client('cloudfront')invalidator=wood.cloudfront.Invalidator(cloudfront,'{distribution}','{reference}')invalidator.invalidate(comparison)# do the same for Cloudflare in the case of a second CDNinvalidator=wood.cloudflare.Invalidator(sess,email,key,zone,'https://example.com/')invalidator.invalidate(comparison)
为什么是“木头”?
因为它开始是一个树比较工具,然后从那里生长出来。是的 边缘也有点粗糙。