From 0e4bc443e2a1dcf703174df6c885281a0a6a64d3 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Fri, 14 Aug 2020 11:43:41 +0200 Subject: [PATCH 1/5] Add a type for wikijs. --- type/__wikijs/files/config.yml.sh | 34 ++++++++++++++++++ type/__wikijs/files/wikijs-openrc | 10 ++++++ type/__wikijs/gencode-remote | 25 +++++++++++++ type/__wikijs/man.rst | 55 ++++++++++++++++++++++++++++ type/__wikijs/manifest | 60 +++++++++++++++++++++++++++++++ type/__wikijs/parameter/boolean | 1 + type/__wikijs/parameter/optional | 3 ++ type/__wikijs/parameter/required | 1 + type/__wikijs/singleton | 0 9 files changed, 189 insertions(+) create mode 100755 type/__wikijs/files/config.yml.sh create mode 100644 type/__wikijs/files/wikijs-openrc create mode 100644 type/__wikijs/gencode-remote create mode 100644 type/__wikijs/man.rst create mode 100644 type/__wikijs/manifest create mode 100644 type/__wikijs/parameter/boolean create mode 100644 type/__wikijs/parameter/optional create mode 100644 type/__wikijs/parameter/required create mode 100644 type/__wikijs/singleton diff --git a/type/__wikijs/files/config.yml.sh b/type/__wikijs/files/config.yml.sh new file mode 100755 index 0000000..6f9943f --- /dev/null +++ b/type/__wikijs/files/config.yml.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +if [ $# -ne 1 ]; +then + echo "You have to give me the database password as an argument:" + echo "on some systems, anyone can read env(1)." + exit 1; +fi + +cat << EOF +port: 80 +db: + type: postgres + host: localhost + port: 5432 + user: ${DB_USER:?} + pass: $1 + db: ${DB_NAME:?} + ssl: false +ssl: + enabled: ${SSL} + port: 443 + provider: letsencrypt + domain: ${__target_host:?} + subscriberEmail: ${LE_EMAIL:?} +pool: + min: 2 + max: 10 +bindIP: 0.0.0.0 +logLevel: warn +offline: false +ha: false +dataPath: ./data +EOF diff --git a/type/__wikijs/files/wikijs-openrc b/type/__wikijs/files/wikijs-openrc new file mode 100644 index 0000000..e484647 --- /dev/null +++ b/type/__wikijs/files/wikijs-openrc @@ -0,0 +1,10 @@ +#!/sbin/openrc-run + +command='/usr/bin/node' +command_args='server' +command_background=true +description="Run wiki.js" +directory='/var/wiki' +error_log=/var/log/"$RC_SVCNAME".err +output_log=/var/log/"$RC_SVCNAME".log +pidfile="/run/$RC_SVCNAME.pid" diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote new file mode 100644 index 0000000..2faf559 --- /dev/null +++ b/type/__wikijs/gencode-remote @@ -0,0 +1,25 @@ +#!/bin/sh + +# Check for installation +cat << EOF +if [ -f '/var/wiki/LICENSE' ]; +then + # Assume everything is done already. + exit 0; +fi +EOF + +# Download and copy source +cat << EOF +TMPDIR=\$(mktemp -d) +cd \$TMPDIR || exit 1 +wget https://github.com/Requarks/wiki/releases/download/2.4.107/wiki-js.tar.gz +tar xf wiki-js.tar.gz -C /var/wiki +EOF + +# Install deps and launch +cat << EOF +cd /var/wiki || exit 1 +npm install +service start wikijs +EOF diff --git a/type/__wikijs/man.rst b/type/__wikijs/man.rst new file mode 100644 index 0000000..6573b60 --- /dev/null +++ b/type/__wikijs/man.rst @@ -0,0 +1,55 @@ +cdist-type__wikijs(7) +======================== + +NAME +---- +cdist-type__wikijs - Deploy the wiki.js software. + +DESCRIPTION +----------- + +See wiki.js.org for more information. This type deploys with a postgresql +database, since it is the upstream recommended for production, and they seem to +strongly suggest that in thenext releases, they will not support anything else. + +Currently, this type servers wikijs as standalone, listening on ports 80 and +443, and with a service file for OpenRC. Feel free to contribute a +generalisation if you require one. + +REQUIRED PARAMETERS +------------------- + +database-password + The password to the PSQL database. + +OPTIONAL PARAMETERS +------------------- + +database + The name of the PSQL database to connect to. If omitted, then 'wikijs' is + used. + +database-user + The name of the PSQL database user to connec as. If omitted, then 'wikijs' is + used. + +letsencrypt-mail + If the SSL parameter is passed, then we setup wikijs to automatically obtain + certificates: this is the email used to sign up to a LE account. + +BOOLEAN PARAMETERS +------------------ + +ssl + Whether or not to enable the wikijs automatic obtention of LE certificates. + +AUTHORS +------- +Joachim Desroches + +COPYING +------- +Copyright \(C) 2020 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__wikijs/manifest b/type/__wikijs/manifest new file mode 100644 index 0000000..7ee42ac --- /dev/null +++ b/type/__wikijs/manifest @@ -0,0 +1,60 @@ +#!/bin/sh + +os="$(cat "${__global:?}"/explorer/os)" + +case "$os" in + alpine) + : + ;; + *) + echo "This type has no implementation for $os. Aborting." >&2; + exit 1; +esac + +DB_USER=wikijs +if [ -f "${__object:?}/parameter/database-user" ]; +then + DB_USER="$(cat "${__object:?}/parameter/database-user")" +fi +export DB_USER + +DB_NAME=wikijs +if [ -f "${__object:?}/parameter/database" ]; +then + DB_NAME="$(cat "${__object:?}/parameter/database")" +fi +export DB_NAME + +SSL=false +if [ -f "${__object:?}/parameter/ssl" ]; +then + SSL=true +fi +export SSL + +if ! [ "$SSL" = "false" ]; +then + if [ -f "${__object:?}/parameter/letsencrypt-mail" ]; + then + LE_EMAIL="$(cat "${__object:?}/parameter/letsencrypt-mail")" + export LE_EMAIL + else + echo "You must specify an email account if you request SSL." + echo "Hit me." + exit 1 + fi +fi + +db_pass="$(cat "${__object:?}/parameter/database-password")" + +__package nodejs +__package nghttp2-dev # Required for some reason, else a symbol is missing +__package npm +__directory /var/wiki/ +__file /etc/init.d/wikijs --source "${__files:?}/files/wikijs-openrc" +require='__file/etc/init.d/wikijs' __start_on_boot wikijs + +mkdir -p "${__object:?}/files" +"${__type:?}/files/config.yml.sh" "$db_pass" > "${__object:?}/files/config.yml" +require='__directory/var/wiki' \ + __file /var/wiki/config.yml --source "${__object:?}/files/config.yml" diff --git a/type/__wikijs/parameter/boolean b/type/__wikijs/parameter/boolean new file mode 100644 index 0000000..a2647ce --- /dev/null +++ b/type/__wikijs/parameter/boolean @@ -0,0 +1 @@ +ssl diff --git a/type/__wikijs/parameter/optional b/type/__wikijs/parameter/optional new file mode 100644 index 0000000..9c309c9 --- /dev/null +++ b/type/__wikijs/parameter/optional @@ -0,0 +1,3 @@ +database +database-user +letsencrypt-mail diff --git a/type/__wikijs/parameter/required b/type/__wikijs/parameter/required new file mode 100644 index 0000000..8a109a1 --- /dev/null +++ b/type/__wikijs/parameter/required @@ -0,0 +1 @@ +database-password diff --git a/type/__wikijs/singleton b/type/__wikijs/singleton new file mode 100644 index 0000000..e69de29 From ef748cf8e248f4f3f4eed88e433fc34ab24b0cb5 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Fri, 14 Aug 2020 13:02:17 +0200 Subject: [PATCH 2/5] Fix typo and drop use of useless tempdir. --- type/__wikijs/gencode-remote | 5 +---- type/__wikijs/man.rst | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote index 2faf559..66d7df7 100644 --- a/type/__wikijs/gencode-remote +++ b/type/__wikijs/gencode-remote @@ -11,10 +11,7 @@ EOF # Download and copy source cat << EOF -TMPDIR=\$(mktemp -d) -cd \$TMPDIR || exit 1 -wget https://github.com/Requarks/wiki/releases/download/2.4.107/wiki-js.tar.gz -tar xf wiki-js.tar.gz -C /var/wiki +wget -O - https://github.com/Requarks/wiki/releases/download/2.4.107/wiki-js.tar.gz | tar xz -C /var/wiki EOF # Install deps and launch diff --git a/type/__wikijs/man.rst b/type/__wikijs/man.rst index 6573b60..50dcd1d 100644 --- a/type/__wikijs/man.rst +++ b/type/__wikijs/man.rst @@ -10,7 +10,7 @@ DESCRIPTION See wiki.js.org for more information. This type deploys with a postgresql database, since it is the upstream recommended for production, and they seem to -strongly suggest that in thenext releases, they will not support anything else. +strongly suggest that in the next releases, they will not support anything else. Currently, this type servers wikijs as standalone, listening on ports 80 and 443, and with a service file for OpenRC. Feel free to contribute a From 647833580df813bdd105a7e0c28ca1d004ded668 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Fri, 14 Aug 2020 13:46:05 +0200 Subject: [PATCH 3/5] Split out service management from the installation type. --- type/__wikijs/gencode-remote | 1 - type/__wikijs/manifest | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote index 66d7df7..a45ac22 100644 --- a/type/__wikijs/gencode-remote +++ b/type/__wikijs/gencode-remote @@ -18,5 +18,4 @@ EOF cat << EOF cd /var/wiki || exit 1 npm install -service start wikijs EOF diff --git a/type/__wikijs/manifest b/type/__wikijs/manifest index 7ee42ac..2e3e96c 100644 --- a/type/__wikijs/manifest +++ b/type/__wikijs/manifest @@ -48,11 +48,12 @@ fi db_pass="$(cat "${__object:?}/parameter/database-password")" __package nodejs -__package nghttp2-dev # Required for some reason, else a symbol is missing __package npm __directory /var/wiki/ + +# These things are Alpine-dependant. __file /etc/init.d/wikijs --source "${__files:?}/files/wikijs-openrc" -require='__file/etc/init.d/wikijs' __start_on_boot wikijs +__package nghttp2-dev # Required for some reason, else a symbol is missing mkdir -p "${__object:?}/files" "${__type:?}/files/config.yml.sh" "$db_pass" > "${__object:?}/files/config.yml" From 7122fe1bee6977794bb5e9cc5d2eb8c4f0380067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Tue, 12 Jan 2021 07:57:34 +0100 Subject: [PATCH 4/5] __wikijs: add version management and HTTP(S) port configuration --- type/__wikijs/files/config.yml.sh | 26 ++++++++++++++++------ type/__wikijs/gencode-remote | 14 ++++++++++-- type/__wikijs/man.rst | 9 ++++++++ type/__wikijs/manifest | 8 +++++-- type/__wikijs/parameter/default/http-port | 1 + type/__wikijs/parameter/default/https-port | 1 + type/__wikijs/parameter/optional | 2 ++ type/__wikijs/parameter/required | 1 + 8 files changed, 51 insertions(+), 11 deletions(-) mode change 100644 => 100755 type/__wikijs/gencode-remote create mode 100644 type/__wikijs/parameter/default/http-port create mode 100644 type/__wikijs/parameter/default/https-port diff --git a/type/__wikijs/files/config.yml.sh b/type/__wikijs/files/config.yml.sh index 6f9943f..b66687a 100755 --- a/type/__wikijs/files/config.yml.sh +++ b/type/__wikijs/files/config.yml.sh @@ -7,8 +7,25 @@ then exit 1; fi +generate_ssl_section () { + + cat << EOF +ssl: + enabled: ${SSL} +EOF + +if [ "$SSL" = "true" ]; then + cat << EOF + port: $HTTPS_PORT + provider: letsencrypt + domain: ${__target_host:?} + subscriberEmail: ${LE_EMAIL:?} +EOF + fi +} + cat << EOF -port: 80 +port: $HTTP_PORT db: type: postgres host: localhost @@ -17,12 +34,7 @@ db: pass: $1 db: ${DB_NAME:?} ssl: false -ssl: - enabled: ${SSL} - port: 443 - provider: letsencrypt - domain: ${__target_host:?} - subscriberEmail: ${LE_EMAIL:?} +$(generate_ssl_section) pool: min: 2 max: 10 diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote old mode 100644 new mode 100755 index a45ac22..81055e2 --- a/type/__wikijs/gencode-remote +++ b/type/__wikijs/gencode-remote @@ -1,17 +1,22 @@ #!/bin/sh +VERSION_FILE=/var/wiki/version +version=$(cat "${__object:?}/parameter/version") + # Check for installation cat << EOF -if [ -f '/var/wiki/LICENSE' ]; +if [ -f $VERSION_FILE ] && [ "\$(cat $VERSION_FILE)" = "$version" ]; then # Assume everything is done already. exit 0; +else + echo "$version" > $VERSION_FILE fi EOF # Download and copy source cat << EOF -wget -O - https://github.com/Requarks/wiki/releases/download/2.4.107/wiki-js.tar.gz | tar xz -C /var/wiki +wget -O - https://github.com/Requarks/wiki/releases/download/$version/wiki-js.tar.gz | tar xz -C /var/wiki EOF # Install deps and launch @@ -19,3 +24,8 @@ cat << EOF cd /var/wiki || exit 1 npm install EOF + +# Restart service. +cat << EOF +service wikijs restart +EOF diff --git a/type/__wikijs/man.rst b/type/__wikijs/man.rst index 50dcd1d..b259c90 100644 --- a/type/__wikijs/man.rst +++ b/type/__wikijs/man.rst @@ -22,6 +22,9 @@ REQUIRED PARAMETERS database-password The password to the PSQL database. +version + 'wikijs' version to be deployed. + OPTIONAL PARAMETERS ------------------- @@ -37,6 +40,12 @@ letsencrypt-mail If the SSL parameter is passed, then we setup wikijs to automatically obtain certificates: this is the email used to sign up to a LE account. +http-port + Specify HTTP port, defaults to 80. + +http-port + Specify HTTPS port, defaults to 443. Only relevant if the SSL flag is enabled. + BOOLEAN PARAMETERS ------------------ diff --git a/type/__wikijs/manifest b/type/__wikijs/manifest index 2e3e96c..04a21af 100644 --- a/type/__wikijs/manifest +++ b/type/__wikijs/manifest @@ -32,7 +32,7 @@ then fi export SSL -if ! [ "$SSL" = "false" ]; +if [ "$SSL" = "true" ]; then if [ -f "${__object:?}/parameter/letsencrypt-mail" ]; then @@ -45,6 +45,10 @@ then fi fi +HTTP_PORT=$(cat "${__object:?}/parameter/http-port") +HTTPS_PORT=$(cat "${__object:?}/parameter/https-port") +export HTTP_PORT HTTPS_PORT + db_pass="$(cat "${__object:?}/parameter/database-password")" __package nodejs @@ -52,7 +56,7 @@ __package npm __directory /var/wiki/ # These things are Alpine-dependant. -__file /etc/init.d/wikijs --source "${__files:?}/files/wikijs-openrc" +__file /etc/init.d/wikijs --source "${__type:?}/files/wikijs-openrc" __package nghttp2-dev # Required for some reason, else a symbol is missing mkdir -p "${__object:?}/files" diff --git a/type/__wikijs/parameter/default/http-port b/type/__wikijs/parameter/default/http-port new file mode 100644 index 0000000..d15a2cc --- /dev/null +++ b/type/__wikijs/parameter/default/http-port @@ -0,0 +1 @@ +80 diff --git a/type/__wikijs/parameter/default/https-port b/type/__wikijs/parameter/default/https-port new file mode 100644 index 0000000..6a13cf6 --- /dev/null +++ b/type/__wikijs/parameter/default/https-port @@ -0,0 +1 @@ +443 diff --git a/type/__wikijs/parameter/optional b/type/__wikijs/parameter/optional index 9c309c9..be19c92 100644 --- a/type/__wikijs/parameter/optional +++ b/type/__wikijs/parameter/optional @@ -1,3 +1,5 @@ database database-user letsencrypt-mail +http-port +https-port diff --git a/type/__wikijs/parameter/required b/type/__wikijs/parameter/required index 8a109a1..ae542bc 100644 --- a/type/__wikijs/parameter/required +++ b/type/__wikijs/parameter/required @@ -1 +1,2 @@ database-password +version From 8929c566fcc0493ee50ca18974ea5488aa2f196b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Tue, 12 Jan 2021 08:33:50 +0100 Subject: [PATCH 5/5] __wikijs: remove uneeded npm install call See https://github.com/Requarks/wiki/issues/1325. --- type/__wikijs/gencode-remote | 5 ----- type/__wikijs/manifest | 1 - 2 files changed, 6 deletions(-) diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote index 81055e2..37c7df7 100755 --- a/type/__wikijs/gencode-remote +++ b/type/__wikijs/gencode-remote @@ -22,10 +22,5 @@ EOF # Install deps and launch cat << EOF cd /var/wiki || exit 1 -npm install -EOF - -# Restart service. -cat << EOF service wikijs restart EOF diff --git a/type/__wikijs/manifest b/type/__wikijs/manifest index 04a21af..b047223 100644 --- a/type/__wikijs/manifest +++ b/type/__wikijs/manifest @@ -52,7 +52,6 @@ export HTTP_PORT HTTPS_PORT db_pass="$(cat "${__object:?}/parameter/database-password")" __package nodejs -__package npm __directory /var/wiki/ # These things are Alpine-dependant.