diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..dfc9f6b6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +Dockerfile +compose-*.yml +*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b23b4489 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 70365602..b77c3457 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`: diff --git a/compose-sync.sh b/compose-sync.sh new file mode 100755 index 00000000..bce1883c --- /dev/null +++ b/compose-sync.sh @@ -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 diff --git a/compose-sync.yml b/compose-sync.yml new file mode 100644 index 00000000..bd7915e4 --- /dev/null +++ b/compose-sync.yml @@ -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: