summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Kubik <ondrej.kubik@canonical.com>2017-11-04 19:23:28 +0000
committerOndrej Kubik <ondrej.kubik@canonical.com>2018-02-21 22:29:23 +0000
commite077c85d003fb3cfd837ad8064ade767fa8fe04f (patch)
treea2440082e3c4f8917095758dead9a577b3efa4b5
parent3665a9131c4f0bac07727a5f908905e9a6348535 (diff)
downloadwekan-e077c85d003fb3cfd837ad8064ade767fa8fe04f.tar.gz
wekan-e077c85d003fb3cfd837ad8064ade767fa8fe04f.tar.bz2
wekan-e077c85d003fb3cfd837ad8064ade767fa8fe04f.zip
Adding caddy support
Signed-off-by: Ondrej Kubik <ondrej.kubik@canonical.com>
-rw-r--r--snap-src/Caddyfile5
-rwxr-xr-xsnap-src/bin/caddy-control12
-rwxr-xr-xsnap-src/bin/config12
-rwxr-xr-xsnap-src/bin/wekan-read-settings9
-rwxr-xr-xsnap/hooks/configure12
-rw-r--r--snapcraft.yaml14
6 files changed, 63 insertions, 1 deletions
diff --git a/snap-src/Caddyfile b/snap-src/Caddyfile
new file mode 100644
index 00000000..07ed4143
--- /dev/null
+++ b/snap-src/Caddyfile
@@ -0,0 +1,5 @@
+http://:8080
+proxy / localhost:3001 {
+ websocket
+ transparent
+}
diff --git a/snap-src/bin/caddy-control b/snap-src/bin/caddy-control
new file mode 100755
index 00000000..c6a4f0d4
--- /dev/null
+++ b/snap-src/bin/caddy-control
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# get wekan/mongo settings
+source $SNAP/bin/wekan-read-settings
+
+if [ "$CADDY_ENABLED" = "true" ]; then
+ env LC_ALL=C caddy -conf=$SNAP_DATA/Caddyfile -host=localhost:${CADDY_PORT}
+else
+ snapctl stop caddy-service 2>&1 || true
+ # sleep here, in case snapctl fails to stop service so we do not restart too often
+ sleep 60
+fi
diff --git a/snap-src/bin/config b/snap-src/bin/config
index dbf8402c..e0b257d7 100755
--- a/snap-src/bin/config
+++ b/snap-src/bin/config
@@ -1,12 +1,14 @@
#!/bin/sh
# store here all configuration options for wekan snap
+SNAP_NAME="wekan"
+
# read configured settings first
SETTINGS_FILE="$SNAP_COMMON/wekan_settings.sh"
[ -f $SETTINGS_FILE ] && . $SETTINGS_FILE
# list of supported keys
-keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB"
+keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB CADDY_ENABLED CADDY_BIND_PORT"
# default values
DESCRIPTION_MONGODB_BIND_UNIX_SOCKET="mongodb binding unix socket:\n"\
@@ -42,3 +44,11 @@ KEY_PORT="port"
DESCRIPTION_DISABLE_MONGODB="Disable mongodb service: use only if binding to database outside of the snap. Valid values: [true,false]"
DEFAULT_DISABLE_MONGODB="false"
KEY_DISABLE_MONGODB="disable-mongodb"
+
+DESCRIPTION_CADDY_ENABLED="Enable caddy service (caddy - Every Site on HTTPS). Set to 'true' to enable caddy\n caddy settings are handled through $SNAP_COMMON/Caddyfile"
+DEFAULT_CADDY_ENABLED="false"
+KEY_CADDY_ENABLED="caddy-enabled"
+
+DESCRIPTION_CADDY_BIND_PORT="Port on which caddy will expect proxy, value set here will be set in $SNAP_COMMON/Caddyfile"
+DEFAULT_CADDY_BIND_PORT="3001"
+KEY_CADDY_BIND_PORT="caddy-bind-port"
diff --git a/snap-src/bin/wekan-read-settings b/snap-src/bin/wekan-read-settings
index a924eaea..f216c2a8 100755
--- a/snap-src/bin/wekan-read-settings
+++ b/snap-src/bin/wekan-read-settings
@@ -18,3 +18,12 @@ do
export $key=$value
fi
done
+
+# if caddy is enabled, do update port settings based on caddy file
+if [ "$CADDY_ENABLED" = "true" ]; then
+ echo "caddy is enabled, adjusting ports"
+ export CADDY_PORT=${PORT}
+ echo -e "CADDY_PORT=$CADDY_PORT"
+ export PORT=${CADDY_BIND_PORT}
+ echo -e "PORT=$PORT"
+fi
diff --git a/snap/hooks/configure b/snap/hooks/configure
index 60ce81e8..fd18da33 100755
--- a/snap/hooks/configure
+++ b/snap/hooks/configure
@@ -7,4 +7,16 @@ echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook"
. $SNAP/bin/config
# settings were altered by user, safest way to get them applied is to restart service
+# first check if caddy service is enabled
+value=$(snapctl get caddy-enabled)
+if [ "$value" = "true" ]; then
+ # update caddy file
+ bind_port=$(snapctl get caddy-bind-port)
+ port=$(snapctl get port)
+ [ "x" != "x${bind_port}" ] && sed -i 's|proxy / localhost:.* {|proxy / localhost:'"${bind_port}"' {|g' $SNAP_COMMON/Caddyfile
+ [ "x" != "x$port" ] && sed -i 's|http://:.*|http://:'"${port}"'|g' $SNAP_COMMON/Caddyfile
+ snapctl start caddy-service 2>&1 || true
+else
+ snapctl stop caddy-service 2>&1 || true
+fi
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 7766f677..ce41bdf3 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -38,6 +38,11 @@ apps:
daemon: simple
plugs: [network, network-bind]
+ caddy-service:
+ command: caddy-control
+ daemon: simple
+ plugs: [network, network-bind]
+
help:
command: wekan-help
@@ -124,3 +129,12 @@ parts:
helpers:
source: snap-src
plugin: dump
+
+ caddy:
+ plugin: go
+ go-importpath: github.com/mholt/caddy
+ source: https://github.com/mholt/caddy.git
+ source-type: git
+ source-commit: 53e117802fedd5915eeb32907873d8786a4b2936
+ prime:
+ - bin/caddy