Skip to main content

Compare directories, efficiently sync changes to AWS, and invalidate CDNs.

Project description

https://img.shields.io/pypi/status/wood.svg https://img.shields.io/pypi/v/wood.svg https://img.shields.io/pypi/pyversions/wood.svg https://travis-ci.org/gebn/wood.svg?branch=master https://coveralls.io/repos/github/gebn/wood/badge.svg?branch=master

Wood is a toolbox for representing directory trees, calculating comparisons between them, and effecting those changes in S3, CloudFront and Cloudflare. It started as a set of deploy scripts for my personal website, but grew into something that I was too chuffed with to keep hidden away in the bowls of another website repository. It’s not as refined as, say, requests, but should be useful to anyone looking to efficiently deploy a website to AWS, and/or using Cloudflare as a CDN.

Notably, unlike the AWS CLI tools or boto3, wood does not rely on file timestamps, instead using MD5 checksums to make the minimum number of changes possible in S3. It also has an algorithm for aggregating invalidation paths to make the CloudFront free tier go as far as possible. Syncers and invalidators are implemented in a generic way, allowing easy extension to additional services as needed.

Features

  • Tree representation

  • Tree comparison

    • Action that comparison in S3

    • Invalidate paths as necessary in CloudFront and Cloudflare

Demo

import wood

# low-level comparison of two local directories
comparison = wood.compare('~/dir', '~/.snapshot/hourly.1/dir')
comparison.new()       # files added since the snapshot
comparison.modified()  # files modified since the snapshot
comparison.deleted()   # files deleted since the snapshot


import pathlib
import boto3

local_base = pathlib.Path('/path/to/web/root')
bucket = boto3.resource('s3').Bucket('example.com')

# create representations of the local and remote trees
to_deploy = wood.root(local_base)
deployed = wood.s3.objects_to_root(bucket.objects.all())

# compare the two as if they were local directories
comparison = wood.compare(to_deploy, deployed)

# write all changes (additions, modifications, deletions) to the S3 bucket
syncer = 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 possible
cloudfront = boto3.client('cloudfront')
invalidator = wood.cloudfront.Invalidator(cloudfront, '{distribution}',
                                          '{reference}')
invalidator.invalidate(comparison)

# do the same for Cloudflare in the case of a second CDN
invalidator = wood.cloudflare.Invalidator(sess, email, key, zone,
                                         'https://example.com/')
invalidator.invalidate(comparison)

Why “wood”?

Because it started as a tree comparison tool, and grew out from there. It’s also a little rough around the edges.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wood-1.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

wood-1.0.1-py2.py3-none-any.whl (18.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wood-1.0.1.tar.gz.

File metadata

  • Download URL: wood-1.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wood-1.0.1.tar.gz
Algorithm Hash digest
SHA256 58c04a9a69628ae4338c5453f04e3e4463638bc6ed9901d4de8780851d17e71e
MD5 46d8aecbd36b72c4aa4b136f7a98d1c9
BLAKE2b-256 d1c471e85052886ac19a9fd25ee9afb763a475d9fc875cbe73d4c501210d1557

See more details on using hashes here.

File details

Details for the file wood-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for wood-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d42379586a75e1e0293fb3c2743a046d37cd67f6b486ec301374405f7f97a189
MD5 8259d06e01a052f4346b709e7986f70e
BLAKE2b-256 799bcf9092c375b0fb0449a3f0e407772502ec1c28e6f1ee47c84bbfad0cdd9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page