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

WIP Add docker use examples #951

Closed
Closed
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
compose-*.yml
*.md
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# copied from https://github.com/datproject/datBase/blob/master/Dockerfile
FROM node:6.9
EXPOSE 80

ENV PORT 80
ENV NODE_ENV development

ENV DATADIR /data
VOLUME /data

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install --production --loglevel warn
COPY . /usr/src/app
RUN npm link
COPY compose-sync.sh /
ENTRYPOINT ["dat"]
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Have questions? Join our chat via IRC or Gitter:
- [Installation](#installation)
- [Getting Started](#getting-started)
- [Using Dat](#usage)
- [Using Dat from Docker](#dockerusage)
- [Troubleshooting](#troubleshooting)
- [Javascript API](#js-api)
- [For Developers](#for-developers)
Expand Down Expand Up @@ -190,6 +191,35 @@ Once a dat is created, you can run all the commands inside that folder, similar

Dat keeps secret keys in the `~/.dat/secret_keys` folder. These are required to write to any dats you create.

## Docker Usage

To get a dat dataset using a Docker container, you can either do it directly:

```
docker run -d --name demo-data \
-p 3282:3282/tcp -p 3282:3282/udp \
-e DATAURL=dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639 \
-e DATADIR=/data \
-v $(pwd)/data:/data \
--entrypoint /compose-sync.yml
dat
```

or use `compose-sync.yml` from Docker swarm mode:

```
$ docker stack up -c compose-sync.yml demo-data
Creating network demo-data_default
Creating service demo-data_dat-sync

$ docker run --rm -v demo-data_sync:/data alpine ls /data
dat.json
dat_intro.gif
```

The Docker image uses `DATADIR` and `DATAURL` if there is no dat data already available, but both environment variables
are optional if there is already dat data in the `/data` dir.

### Sharing

The quickest way to get started sharing files is to `share`:
Expand Down
19 changes: 19 additions & 0 deletions compose-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

: "${DATADIR:=/data}"


if [ -d "$DATADIR/.dat" ]; then
echo "using dat to sync data from in $DATADIR"
dat $OPTS sync $DATADIR
else
if [[ "$(ls $DATADIR)" == "" ]]; then
echo "using dat to sync data from $DATAURL into $DATADIR"
dat $OPTS clone $DATAURL $DATADIR
else
echo "$DATADIR not empty, and no .dat dir, so creating new share"
dat $OPTS create $DATADIR
dat $OPTS share $DATADIR
fi
fi
dat sync $DATADIR
18 changes: 18 additions & 0 deletions compose-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.4"
services:
dat-sync:
image: svendowideit/dat
#command: clone dat://f6d022942d14f3a27c9c09af8c7e673038652a6f11626efbd38f0308f6b47bbf /data
entrypoint: /compose-sync.sh
environment:
- DATAURL=dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639
- DATADIR=/data
ports:
- "3282:3282/tcp"
- "3282:3282/udp"
volumes:
- sync:/data


volumes:
sync: