Vman

Gem Version

Like superman but not at all.

A ruby gem to help manage (push/pull/delete/promote/etc) your objects and directories in a versioned S3 bucket.

Prerequisites

Ensure you have the AWS cli installed and configured properly.

Installation

Install with:

$ gem install vman

Create a configuration file with:

$ vman configure

Then edit the new ~/.vman.json file with your correct values.

  • bucket_uri is your s3://-prefixed S3 bucket URL to which you have permissions.
  • local_dir (optional) value that tells vman which directory to work in. If not supplied, defaults to Dir.pwd.

Usage

Run without arguments to access help documentation:

$ vman

Show local file diff (differences on your local machine that are not on S3):

$ echo "Hello world" > newfile.txt
$ vman diff
Showing file diff for a push from '/Users/chl/Desktop/test' to 's3://my-bucket'

(dryrun) upload: ./newfile.txt to s3://my-bucket/newfile.txt

Show remote file diff (differences on remote S3 that are not on your local machine):

$ vman diff -r
Showing file diff for a pull from 's3://my-bucket' to '/Users/chl/Desktop/test'

(dryrun) download: s3://my-bucket/Gemfile to ./Gemfile
(dryrun) download: s3://my-bucket/Gemfile.lock to ./Gemfile.lock
(dryrun) download: s3://my-bucket/test.txt to ./test.txt

Push local changes to remote:

$ vman push -f
Pushing changes from /Users/chl/Desktop/test to remote bucket 's3://my-bucket'
upload: ./newfile.txt to s3://my-bucket/newfile.txt

Pull remote changes to local:

$ vman pull -f
Pulling changes from remote bucket 's3://my-bucket' to /Users/chl/Desktop/test.
This will overwrite local changes!
download: s3://my-bucket/Gemfile to ./Gemfile
download: s3://my-bucket/tete.txt to ./tete.txt
download: s3://my-bucket/test.txt to ./test.txt
download: s3://my-bucket/Gemfile.lock to ./Gemfile.lock

Interactive Usage

Vman also comes with a fully interactive tty menu system for finer-grained over single files or versions. This can be accessed with:

$ vman -i

Image of interactive menu

Integration With Git

You can easily hook into the git workflow with Vman by doing the following:

  1. Add the directory or sub-directory in your local repo that you wish to sync to S3 to your .gitignore file.
  2. To have Vman automatically push changes in your selected (sub)directory to S3, create a git hook in .git/hooks/pre-push. For example: ```bash #!/bin/bash

exec < /dev/tty

cd ./path/to/synced/directory

vman push

while true; do read -p "Do you wish to push these files to S3?" yn case $yn in [Yy]* ) vman push -f; break;; [Nn]* ) printf "Nothing pushed to S3.\n\n"; exit;; * ) echo "Please answer yes or no.";; esac done

printf "Continuing with git operation...\n"


This will first do a dry-run of `vman push` and show you the files that it plans to push to your S3 bucket. It will then prompt for
confirmation to execute the push. Regardless of your selection, your normal git flow will not be interrupted.

For hooking into git pulls/merge, add a similar git hook under `.git/hooks/post-merge`. For example:
```bash
#!/bin/bash

exec < /dev/tty

cd ./path/to/synced/directory

vman pull

while true; do
  read -p "Do you wish to pull these files from S3?" yn
  case $yn in
    [Yy]* ) vman pull -f; break;;
    [Nn]* ) printf "Nothing pulled from S3.\n\n"; exit;;
    * ) echo "Please answer yes or no.";;
  esac
done

The post-merge hook is called after a merge. Because of this, it cannot abort a merge.

N.B. githooks execute in the root of your repo directory. Keep this in mind when entering the path to the (sub)directory you wish to sync.

Testing

Note that AWS cli must be installed. Then simply:

$ rake test

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/doximity/vman.