Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for S3 as a storage backend #90

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ Set a remote store for the fat objects by editing `.gitfat`.

This file should typically be committed to the repository so that others
will automatically have their remote set. This remote address can use
any protocol supported by rsync.
any protocol supported by rsync.

Most users will configure it to use remote ssh in a directory with shared
access. To do this, set the `sshuser` and `sshport` variables in `.gitfat`
Most users will configure it to use remote ssh in a directory with shared
access. To do this, set the `sshuser` and `sshport` variables in `.gitfat`
configuration file. For example, to use rsync with ssh, with the default
port (22) and authenticate with the user "_fat_", your configuration would
look like this:
port (22) and authenticate with the user "_fat_", your configuration would
look like this:

[rsync]
remote = your.remote-host.org:/share/fat-store
sshuser = fat

To use an Amazon S3 bucket as the backend, you should first install the AWS CLI and configure it with a user that has access to the bucket. Your configuration would then look like:

[s3]
bucket = s3://your-s3-bucket

# A worked example

Before we start, let's turn on verbose reporting so we can see what's
Expand Down Expand Up @@ -145,7 +150,7 @@ selected history.
1 file to consider
1f218834a137f7b185b498924e7a030008aee2ae
6449 100% 6.15MB/s 0:00:00 (xfer#1, to-check=0/1)

sent 30 bytes received 6558 bytes 4392.00 bytes/sec
total size is 6449 speedup is 0.98
Restoring 1f218834a137f7b185b498924e7a030008aee2ae -> master.tar.gz
Expand Down
50 changes: 50 additions & 0 deletions git-fat
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ except ImportError:

BLOCK_SIZE = 4096

def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None


def verbose_stderr(*args, **kwargs):
return print(*args, file=sys.stderr, **kwargs)
def verbose_ignore(*args, **kwargs):
Expand Down Expand Up @@ -158,7 +175,40 @@ class GitFat(object):
if remote is None:
raise RuntimeError('No rsync.remote in %s' % cfgpath)
return remote, ssh_port, ssh_user, options

def get_aws_cmd(self, push, s3_bucket):
if not which('aws'):
sys.stderr.write('Could not find aws cli install.\n')
sys.exit(1)

if not s3_bucket.startswith('s3://'):
s3_bucket = "s3://{}".format(s3_bucket)

if push:
self.verbose('Pushing to %s' % (s3_bucket))
cmd = [
"aws",
"s3",
"sync",
self.objdir + "/",
s3_bucket + "/"
]
else:
self.verbose('Pulling from %s' % (s3_bucket))
cmd = [
"aws",
"s3",
"sync",
s3_bucket + "/",
self.objdir + "/"
]
return cmd

def get_rsync_command(self,push):
cfgpath = os.path.join(self.gitroot,'.gitfat')
s3_bucket = gitconfig_get('s3.bucket', file=cfgpath)
if s3_bucket:
return self.get_aws_cmd(push, s3_bucket)
(remote, ssh_port, ssh_user, options) = self.get_rsync()
if push:
self.verbose('Pushing to %s' % (remote))
Expand Down