From 5f8f93a11b1ee9f94242fa52324eff4e298ce437 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Fri, 2 Mar 2018 13:12:56 +1000 Subject: [PATCH 1/3] example docker run, and docker stack to get the demo dat Signed-off-by: Sven Dowideit --- .dockerignore | 3 +++ Dockerfile | 23 +++++++++++++++++++++++ README.md | 29 +++++++++++++++++++++++++++++ compose-sync.sh | 13 +++++++++++++ compose-sync.yml | 15 +++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 compose-sync.sh create mode 100644 compose-sync.yml 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..50a385db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# 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"] +#RUN npm run build-js-prod && npm run build-css && npm run minify && npm run version + +# do docker exec: npm run database + +#CMD npm run database && DEBUG=dat-registry npm run server diff --git a/README.md b/README.md index 70365602..111e301e 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,34 @@ 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 \ + -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..b7e9e58b --- /dev/null +++ b/compose-sync.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +: "${DATADIR:=/data}" + + +if [ -d "$DATADIR/.dat" ]; then + echo "using dat to sync data from in $DATADIR" + dat sync $DATADIR +else + echo "using dat to sync data from $DATAURL into $DATADIR" + dat clone $DATAURL $DATADIR +fi +dat sync $DATADIR diff --git a/compose-sync.yml b/compose-sync.yml new file mode 100644 index 00000000..6f4d4feb --- /dev/null +++ b/compose-sync.yml @@ -0,0 +1,15 @@ +version: "3.4" +services: + dat-sync: + image: svendowideit/dat + #command: clone dat://f6d022942d14f3a27c9c09af8c7e673038652a6f11626efbd38f0308f6b47bbf /data + entrypoint: /compose-sync.sh + environment: + - DATAURL=dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639 + - DATADIR=/data + volumes: + - sync:/data + + +volumes: + sync: From 1ff613f65e525e4f7b6967f2685278204a2062eb Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Fri, 2 Mar 2018 13:29:59 +1000 Subject: [PATCH 2/3] mape the default dat ports for the simple clone/sync example Signed-off-by: Sven Dowideit --- README.md | 1 + compose-sync.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 111e301e..b77c3457 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ 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 \ diff --git a/compose-sync.yml b/compose-sync.yml index 6f4d4feb..bd7915e4 100644 --- a/compose-sync.yml +++ b/compose-sync.yml @@ -7,6 +7,9 @@ services: environment: - DATAURL=dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639 - DATADIR=/data + ports: + - "3282:3282/tcp" + - "3282:3282/udp" volumes: - sync:/data From 70fecf84c16ec4c5f9e451e57374bf8c34eac5b6 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Sat, 3 Mar 2018 14:36:11 +1000 Subject: [PATCH 3/3] if data dir has files in it, but no .dat dir, create and share it Signed-off-by: Sven Dowideit --- Dockerfile | 5 ----- compose-sync.sh | 12 +++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 50a385db..b23b4489 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,3 @@ COPY . /usr/src/app RUN npm link COPY compose-sync.sh / ENTRYPOINT ["dat"] -#RUN npm run build-js-prod && npm run build-css && npm run minify && npm run version - -# do docker exec: npm run database - -#CMD npm run database && DEBUG=dat-registry npm run server diff --git a/compose-sync.sh b/compose-sync.sh index b7e9e58b..bce1883c 100755 --- a/compose-sync.sh +++ b/compose-sync.sh @@ -5,9 +5,15 @@ if [ -d "$DATADIR/.dat" ]; then echo "using dat to sync data from in $DATADIR" - dat sync $DATADIR + dat $OPTS sync $DATADIR else - echo "using dat to sync data from $DATAURL into $DATADIR" - dat clone $DATAURL $DATADIR + 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