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] __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