|
| 1 | +# S3 Datastore Implementation |
| 2 | + |
| 3 | +This is an implementation of the datastore interface backed by amazon s3. |
| 4 | + |
| 5 | +**NOTE:** Plugins only work on Linux and MacOS at the moment. You can track the progress of this issue here: https://github.com/golang/go/issues/19282 |
| 6 | + |
| 7 | +## Building and Installing |
| 8 | + |
| 9 | +You must build the plugin with the *exact* version of go used to build the go-ipfs binary you will use it with. You can find the go version for go-ipfs builds from dist.ipfs.io in the build-info file, e.g. https://dist.ipfs.io/go-ipfs/v0.4.22/build-info or by running `ipfs version --all`. |
| 10 | + |
| 11 | +In addition to needing the exact version of go, you need to build the correct version of this plugin. |
| 12 | + |
| 13 | +* To build against a released version of go-ipfs, checkout the `release/v$VERSION` branch and build. |
| 14 | +* To build against a custom (local) build of go-ipfs, run `make IPFS_VERSION=/path/to/go-ipfs/source`. |
| 15 | + |
| 16 | +You can then install it into your local IPFS repo by running `make install`. |
| 17 | + |
| 18 | +## Bundling |
| 19 | + |
| 20 | +As go plugins can be finicky to correctly compile and install, you may want to consider bundling this plugin and re-building go-ipfs. If you do it this way, you won't need to install the `.so` file in your local repo, i.e following the above Building and Installing section, and you won't need to worry about getting all the versions to match up. |
| 21 | + |
| 22 | +```bash |
| 23 | +# We use go modules for everything. |
| 24 | +> export GO111MODULE=on |
| 25 | + |
| 26 | +# Clone go-ipfs. |
| 27 | +> git clone https://github.com/ipfs/go-ipfs |
| 28 | +> cd go-ipfs |
| 29 | + |
| 30 | +# Pull in the datastore plugin (you can specify a version other than latest if you'd like). |
| 31 | +> go get github.com/ipfs/go-ds-s3/plugin@latest |
| 32 | + |
| 33 | +# Add the plugin to the preload list. |
| 34 | +> echo -en "\ns3ds github.com/ipfs/go-ds-s3/plugin 0" >> plugin/loader/preload_list |
| 35 | + |
| 36 | +# ( this first pass will fail ) Try to build go-ipfs with the plugin |
| 37 | +> make build |
| 38 | + |
| 39 | +# Update the deptree |
| 40 | +> go mod tidy |
| 41 | + |
| 42 | +# Now rebuild go-ipfs with the plugin |
| 43 | +> make build |
| 44 | + |
| 45 | +# (Optionally) install go-ipfs |
| 46 | +> make install |
| 47 | +``` |
| 48 | + |
| 49 | +## Detailed Installation |
| 50 | + |
| 51 | +For a brand new ipfs instance (no data stored yet): |
| 52 | + |
| 53 | +1. Copy s3plugin.so $IPFS_DIR/plugins/go-ds-s3.so (or run `make install` if you are installing locally). |
| 54 | +2. Run `ipfs init`. |
| 55 | +3. Edit $IPFS_DIR/config to include s3 details (see Configuration below). |
| 56 | +4. Overwrite `$IPFS_DIR/datastore_spec` as specified below (*Don't do this on an instance with existing data - it will be lost*). |
| 57 | + |
| 58 | +### Configuration |
| 59 | + |
| 60 | +The config file should include the following: |
| 61 | +```json |
| 62 | +{ |
| 63 | + "Datastore": { |
| 64 | + ... |
| 65 | + |
| 66 | + "Spec": { |
| 67 | + "mounts": [ |
| 68 | + { |
| 69 | + "child": { |
| 70 | + "type": "s3ds", |
| 71 | + "region": "us-east-1", |
| 72 | + "bucket": "$bucketname", |
| 73 | + "rootDirectory": "$bucketsubdirectory", |
| 74 | + "accessKey": "", |
| 75 | + "secretKey": "" |
| 76 | + }, |
| 77 | + "mountpoint": "/blocks", |
| 78 | + "prefix": "s3.datastore", |
| 79 | + "type": "measure" |
| 80 | + }, |
| 81 | +``` |
| 82 | + |
| 83 | +If the access and secret key are blank they will be loaded from the usual ~/.aws/. |
| 84 | +If you are on another S3 compatible provider, e.g. Linode, then your config should be: |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "Datastore": { |
| 89 | + ... |
| 90 | + |
| 91 | + "Spec": { |
| 92 | + "mounts": [ |
| 93 | + { |
| 94 | + "child": { |
| 95 | + "type": "s3ds", |
| 96 | + "region": "us-east-1", |
| 97 | + "bucket": "$bucketname", |
| 98 | + "rootDirectory": "$bucketsubdirectory", |
| 99 | + "regionEndpoint": "us-east-1.linodeobjects.com", |
| 100 | + "accessKey": "", |
| 101 | + "secretKey": "" |
| 102 | + }, |
| 103 | + "mountpoint": "/blocks", |
| 104 | + "prefix": "s3.datastore", |
| 105 | + "type": "measure" |
| 106 | + }, |
| 107 | +``` |
| 108 | + |
| 109 | +If you are configuring a brand new ipfs instance without any data, you can overwrite the datastore_spec file with: |
| 110 | + |
| 111 | +``` |
| 112 | +{"mounts":[{"bucket":"$bucketname","mountpoint":"/blocks","region":"us-east-1","rootDirectory":"$bucketsubdirectory"},{"mountpoint":"/","path":"datastore","type":"levelds"}],"type":"mount"} |
| 113 | +``` |
| 114 | + |
| 115 | +Otherwise, you need to do a datastore migration. |
| 116 | + |
| 117 | +## Contribute |
| 118 | + |
| 119 | +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/go-ipfs-example-plugin/issues)! |
| 120 | + |
| 121 | +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). |
| 122 | + |
| 123 | +### Want to hack on IPFS? |
| 124 | + |
| 125 | +[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +MIT |
0 commit comments