1 Commits

Author SHA1 Message Date
29980517f6 publish experimental apparatus plugin 2017-12-18 22:53:02 -07:00
4 changed files with 172 additions and 48 deletions

View File

@ -1,16 +1,20 @@
FROM node:lts-alpine
FROM node:8-slim
RUN apk add --update --no-cache \
dumb-init \
git \
jq
WORKDIR "/home/node"
ARG WIKI_PACKAGE=wiki@0.19.0
RUN su node -c "npm install -g --prefix . $WIKI_PACKAGE"
RUN su node -c "mkdir -p .wiki"
VOLUME "/home/node/.wiki"
RUN useradd --create-home app \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
jq \
git
WORKDIR /home/app
ARG WIKI_PACKAGE='dobbs/wiki#apparatus'
RUN su app -c "npm install -g --prefix . $WIKI_PACKAGE"
RUN su app -c "mkdir .wiki"
COPY configure-and-launch-wiki set-owner-name ./
RUN chown app configure-and-launch-wiki set-owner-name
VOLUME "/home/app/.wiki"
ENV DOMAIN=localhost
ENV OWNER_NAME="The Owner"
ENV COOKIE=insecure
EXPOSE 3000
USER node
ENV PATH="${PATH}:/home/node/bin"
ENTRYPOINT ["dumb-init"]
CMD ["wiki", "--farm", "--security_type=friends"]
USER app
CMD ["./configure-and-launch-wiki"]

View File

@ -1,58 +1,62 @@
# Federated Wiki Farm
Start Playing Federated Wiki: http://start.fed.wiki
http://fed.wiki.org
### Run a local wiki farm
### Get acquainted with wiki.
docker run -p 3000:3000 -it --rm \
dobbs/farm
Launch the container:
``` bash
docker run -p 3000:3000 -it --rm \
dobbs/farm
```
Visit http://localhost:3000 and http://anything.localtest.me:3000
Visit http://localhost:3000
### Run a local wiki that will survive a reboot
### Make your wiki survive a reboot
docker run -p 3000:3000 -it --rm \
-v ~/.wiki:/home/node/.wiki \
dobbs/farm
Create a volume:
Your wiki pages and configuration will be saved in the ~/.wiki folder.
``` bash
docker volume create dot-wiki
```
# Release Notes for 1.0.0
Launch the container:
``` bash
docker run -p 3000:3000 -it --rm \
-v dot-wiki:/home/app/.wiki \
dobbs/farm
```
This is a significant **breaking** change from pre-1.0 releases. Especially:
Visit http://localhost:3000
* changed the user from `app` (`uid=1001(app) gid=1001(app) groups=1001(app)`)
to `node` (`uid=1000(node) gid=1000(node) groups=1000(node),1000(node)`)
### Make your wiki a local farm
* no longer installing `bash`, `configure-wiki`, nor `set-owner-name`
We're going to use http://localtest.me instead of localhost for our
domain name. See http://readme.localtest.me for more info.
* no longer creating `/home/app/.wiki/wiki.json`
Let's also use a different volume for this one:
``` bash
docker volume create localtest.me
```
Those changes in particular will impose some work on authors upgrading
from previous versions.
Specify the domain name when you launch your wiki
``` bash
docker run -p 3000:3000 -it --rm \
-v localtest.me:/home/app/.wiki \
-e DOMAIN=localtest.me \
dobbs/farm
```
The last non-breaking revision is 0.52.0 https://github.com/dobbs/farm/tree/0.52.0#readme
Open http://this.localtest.me:3000 in one tab.
Open http://that.localtest.me:3000 in another.
# Development
This image's tag does not match the version of the included wiki software.
Notes to self:
This image's tag matches the version of the included wiki software.
``` bash
docker build --tag dobbs/farm:0.51.0 .
git tag -am "" '0.51.0'
git tag -am "" '0.13.0'
git push --tags
```
The repos in Dockerhub and GitHub are configured to automatically build new tags.
# Publish experimental plugins
``` bash
docker build \
--tag dobbs/farm:0.14.0-frame \
--build-arg WIKI_PACKAGE='dobbs/wiki#frame' \
.
docker push dobbs/farm:0.14.0-frame
```

77
configure-and-launch-wiki Executable file
View File

@ -0,0 +1,77 @@
#!/bin/bash -eu
set -o pipefail
main() {
initialize-environment-vars
assert-file-privileges || report-errors-and-exit
ensure-owner-file
ensure-config-file
show-configs
exec-wiki
}
initialize-environment-vars() {
ERRORS=''
readonly OWNER_FILE=/home/app/.wiki/$DOMAIN.owner.json
readonly CONFIG_FILE=/home/app/.wiki/config.json
}
assert-file-privileges() {
[ -w /home/app/.wiki ] \
|| ERRORS="app cannot write to /home/app/.wiki\n${ERRORS}"
[ ${#ERRORS} == 0 ]
}
report-errors-and-exit() {
echo -e $ERRORS
echo "exiting."
exit 1
}
ensure-owner-file() {
if [ ! -r "$OWNER_FILE" ]; then
jq -n --arg name "$OWNER_NAME" --arg secret $(random-string) \
'.name = $name | .friend.secret = $secret' > $OWNER_FILE
fi
}
ensure-config-file() {
if [ ! -r "$CONFIG_FILE" ]; then
> $CONFIG_FILE \
jq -n -M \
--arg admin $(jq -r .friend.secret $OWNER_FILE) \
--arg random $(random-string) \
--arg cookie $COOKIE \
--arg domain $DOMAIN \
--arg owner $OWNER_FILE \
'
.admin = $admin
| .autoseed = true
| .farm = true
| .cookieSecret = $random
| .secure_cookie = ("secure" == $cookie)
| .security_type = "friends"
| .wikiDomains[$domain].id = "/home/app/.wiki/\($domain).owner.json"
'
fi
}
random-string() {
node -e 'console.log(require("crypto").randomBytes(64).toString("hex"))'
}
show-configs() {
set -x
ls -l $OWNER_FILE $CONFIG_FILE
cat $OWNER_FILE
cat $CONFIG_FILE
set +x
}
exec-wiki() {
exec /home/app/bin/wiki
}
main

39
set-owner-name Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash -eu
set -o pipefail
usage() {
cat <<EOF
Usage: $(basename $0) NAME
replaces the owner's name in $OWNER_FILE
EOF
}
main() {
initialize-environment-vars $@ || { usage; exit 1; }
backup-and-save-name
report-success
}
initialize-environment-vars() {
readonly OWNER_FILE=/home/app/.wiki/$DOMAIN.owner.json
readonly OWNER_BACKUP_FILE=$OWNER_FILE-saved-$(date --iso-8601=minutes)
readonly NAME=${@:-missing}
[ ! "$NAME" == "missing" ]
}
backup-and-save-name() {
mv $OWNER_FILE $OWNER_BACKUP_FILE
jq ".name = \"$NAME\"" $OWNER_BACKUP_FILE > $OWNER_FILE
}
report-success() {
cat <<EOF
Owner's name changed to "$NAME"
Previous config is saved in ${OWNER_BACKUP_FILE##$PWD/}
EOF
}
main "$@"