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

How can I change node's startup command? #4

Open
ghost opened this issue Mar 27, 2021 · 3 comments
Open

How can I change node's startup command? #4

ghost opened this issue Mar 27, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2021

Hi, how is Tiddly Wiki started inside container? I'm trying to manually install TW5-Bob plugin, and it required to modify startup command:

cd TiddlyWiki5
node ./tiddlywiki.js Wikis/BobWiki  --wsserver
@m0wer
Copy link
Owner

m0wer commented Nov 26, 2021

First of all, sorry for the late reply. I didn't get any notifications since the repo is a fork and it was unwatched by default.

You can see the startup command (and modify it) in

exec /usr/bin/env node $NODEJS_V8_ARGS $tiddlywiki_script mywiki --listen host=0.0.0.0 port=8080 username="$USERNAME" password="${PASSWORD-wiki}" debug-level=${DEBUG_LEVEL-none};
.

A good solution would be to allow users to customize that command when running the Docker image, using the arguments from the docker run command in the init-and-run script (maybe with "$@" or something similar). PRs are welcome.

@cornernote
Copy link

cornernote commented Jan 14, 2023

I did it using docker compose like this:

Download the Dockerfile and init-and-run-wiki from the repo.

Edit the init-and-run-wiki to suit.

You may also need to chmod +x init-and-run-wiki, or change Dockerfile with this line:

ADD --chmod=755 init-and-run-wiki /usr/local/bin/init-and-run-wiki

Make a folder for the data with mkdir tiddlywiki.

Next create docker-compose.yml with the following:

version: '3'
services:
  tiddlywiki:
    build:
      dockerfile: Dockerfile
      context: .
    volumes:
      - ./tiddlywiki:/var/lib/tiddlywiki
    restart: unless-stopped
    ports:
      - 8080:8080

Then run docker compose up -d, and you have a server.

In addition, you can shell into the instance with docker compose exec tiddlywiki sh, then you can run tiddlywiki node commands, for example to export your wiki to a HTML file.

@cornernote
Copy link

cornernote commented Jan 14, 2023

Followup, I was able to get Bob working like this:

Dockerfile

FROM node:alpine

RUN npm install -g [email protected]

# Setup wiki volume
VOLUME /var/lib/tiddlywiki
WORKDIR /var/lib/tiddlywiki

# Add init-and-run script
ADD --chmod=755 init-and-run-wiki /usr/local/bin/init-and-run-wiki

# Meta
CMD ["/usr/local/bin/init-and-run-wiki"]

init-and-run-wiki

#!/bin/sh
set -e

tiddlywiki_script=$(readlink -f $(which tiddlywiki))

if [ -n "$NODE_MEM" ]; then
    # Based on rule of thumb from:
    # http://fiznool.com/blog/2016/10/01/running-a-node-dot-js-app-in-a-low-memory-environment/
    mem_node_old_space=$((($NODE_MEM*4)/5))
    NODEJS_V8_ARGS="--max_old_space_size=$mem_node_old_space $NODEJS_V8_ARGS"
fi

# Setup initial wiki
if [ ! -d /var/lib/tiddlywiki/mywiki ]; then
  /usr/bin/env node $NODEJS_V8_ARGS $tiddlywiki_script mywiki --init server

  mkdir /var/lib/tiddlywiki/mywiki/tiddlers
fi

# Define plugins
if [  -n "$PLUGINS" ]; then
  plugins_params="$PLUGINS"
fi

# Configure listen command, see https://tiddlywiki.com/static/ListenCommand.html
listen_params="host=0.0.0.0 port=8080"
listen_params="$listen_params debug-level=${DEBUG_LEVEL-none}"
if [ -n "$PATH_PREFIX" ]; then
  listen_params="$listen_params path-prefix=$PATH_PREFIX"
fi
if [ -n "$USERNAME" ]; then
  listen_params="$listen_params username=$USERNAME"
  listen_params="$listen_params password=${PASSWORD-wiki}"
fi

# Start the tiddlywiki server
exec /usr/bin/env node $NODEJS_V8_ARGS $tiddlywiki_script $plugins_params mywiki --listen $listen_params $OPTIONS

docker-compose.yml

version: '3'
services:
  tiddlywiki:
    build:
      dockerfile: Dockerfile
      context: .
    volumes:
      - ./tiddlywiki:/var/lib/tiddlywiki
    restart: unless-stopped
    ports:
      - 8080:8080
    environment:
      - PLUGINS=+plugins/tiddlywiki/markdown ++./plugins/OokTech/Bob
      - OPTIONS=--wsserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants