From 149e7fc5c5a2254aa8a0cc203d86d7f4eb1ac174 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:19:27 +0100 Subject: [PATCH 1/8] bump caddy version --- seafile-caddy/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seafile-caddy/Dockerfile b/seafile-caddy/Dockerfile index 54502a6..bfef75f 100644 --- a/seafile-caddy/Dockerfile +++ b/seafile-caddy/Dockerfile @@ -1,3 +1,3 @@ -FROM caddy:2.2.1-alpine +FROM caddy:2.3.0-alpine COPY Caddyfile /etc/caddy/Caddyfile \ No newline at end of file From fa77a6e236df740a618f53565d89af6f49360bd1 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:20:17 +0100 Subject: [PATCH 2/8] apk add bash bind-tools --- seafile-caddy/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/seafile-caddy/Dockerfile b/seafile-caddy/Dockerfile index bfef75f..2977701 100644 --- a/seafile-caddy/Dockerfile +++ b/seafile-caddy/Dockerfile @@ -1,3 +1,7 @@ FROM caddy:2.3.0-alpine +RUN apk add --no-cache \ +bash \ +bind-tools + COPY Caddyfile /etc/caddy/Caddyfile \ No newline at end of file From 281646dcae306de2f67f241fe55bad8fffe6452b Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:53:43 +0100 Subject: [PATCH 3/8] add swam-dns.sh --- seafile-caddy/scripts/swarm-dns.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 seafile-caddy/scripts/swarm-dns.sh diff --git a/seafile-caddy/scripts/swarm-dns.sh b/seafile-caddy/scripts/swarm-dns.sh new file mode 100644 index 0000000..c24b221 --- /dev/null +++ b/seafile-caddy/scripts/swarm-dns.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ "$SWARM_DNS" = true ]; then + + cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.default + + while true; do + + SEAHUB_IPS=$(dig +short seahub | sed -e 's/$/:8000/' | tr ' ' '\n' | sort | tr '\n' ' ') + SEAHUB_MEDIA_IPS=$(dig +short seahub-media | sed -e 's/$/:80/' | tr ' ' '\n' | sort | tr '\n' ' ') + + cp /etc/caddy/Caddyfile.default /etc/caddy/Caddyfile.tmp + + sed -i "s/seahub:8000/$(echo $SEAHUB_IPS)/g" /etc/caddy/Caddyfile.tmp + sed -i "s/seahub-media:80/$(echo $SEAHUB_MEDIA_IPS)/g" /etc/caddy/Caddyfile.tmp + + if ! diff -q "/etc/caddy/Caddyfile" "/etc/caddy/Caddyfile.tmp"; then + rm -f /etc/caddy/Caddyfile + mv /etc/caddy/Caddyfile.tmp /etc/caddy/Caddyfile + echo "Applying new Caddyfile:" + cat /etc/caddy/Caddyfile + caddy reload --config /etc/caddy/Caddyfile + fi + + sleep 10 + + done +fi From 69cbbfb0206382b0d408f3eeb27070aaa0f05925 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:53:51 +0100 Subject: [PATCH 4/8] add start.sh --- seafile-caddy/scripts/start.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 seafile-caddy/scripts/start.sh diff --git a/seafile-caddy/scripts/start.sh b/seafile-caddy/scripts/start.sh new file mode 100644 index 0000000..390e2f2 --- /dev/null +++ b/seafile-caddy/scripts/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +/scripts/swarm-dns.sh & + +caddy run --config /etc/caddy/Caddyfile --adapter caddyfile + From 35a7bb96005409a2a90e6bb57e084159179fd7a2 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:54:34 +0100 Subject: [PATCH 5/8] add scripts folder, run start.sh --- seafile-caddy/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seafile-caddy/Dockerfile b/seafile-caddy/Dockerfile index 2977701..e9052c4 100644 --- a/seafile-caddy/Dockerfile +++ b/seafile-caddy/Dockerfile @@ -4,4 +4,7 @@ RUN apk add --no-cache \ bash \ bind-tools -COPY Caddyfile /etc/caddy/Caddyfile \ No newline at end of file +COPY Caddyfile /etc/caddy/Caddyfile +COPY scripts /scripts + +CMD ["/scripts/start.sh"] \ No newline at end of file From 2025bd8646d00f63849f6396e255c7baf418cee3 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 00:58:28 +0100 Subject: [PATCH 6/8] update docker-compose-swarm.yml --- compose/docker-compose-swarm.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compose/docker-compose-swarm.yml b/compose/docker-compose-swarm.yml index 8da5393..4a92eef 100644 --- a/compose/docker-compose-swarm.yml +++ b/compose/docker-compose-swarm.yml @@ -29,7 +29,9 @@ services: networks: - seafile-net deploy: - replicas: 1 + mode: replicated + replicas: 4 + endpoint_mode: dnsrr seahub-media: image: ggogel/seahub-media @@ -39,7 +41,9 @@ services: networks: - seafile-net deploy: - replicas: 1 + mode: replicated + replicas: 2 + endpoint_mode: dnsrr db: image: mariadb:latest @@ -58,18 +62,20 @@ services: - seafile-net seafile-caddy: - image: ggogel/seafile-caddy:1.0.0 + image: ggogel/seafile-caddy:1.0.1 + environment: + - SWARM_DNS=true networks: - seafile-net - caddy deploy: - endpoint_mode: dnsrr # this enables caddy to see all IPs of service's replicas labels: caddy: http://seafile.gogel.me caddy.reverse_proxy: "{{upstreams 80}}" networks: seafile-net: + driver: overlay internal: true caddy: external: true From 7c9d7d5a56edea20ad52f5c238c425c34f997a81 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 01:29:00 +0100 Subject: [PATCH 7/8] Update README.md --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bb7b125..ef13095 100644 --- a/README.md +++ b/README.md @@ -62,19 +62,16 @@ Networks: 2. ***Get the compose file*** - #### Docker - Use this compose file as a starting point. + #### Docker Compose + + Use this compose file as a starting point. ``` wget https://github.com/ggogel/seafile-containerized/blob/master/compose/docker-compose.yml ``` - #### Docker Swarm - With only one node you can use the above file. If you have multiple nodes, you will either need to force most of the services to run on the same node or you will need some kind of distributed storage or network storage. - - You can check out this example using [lucaslorentz/caddy-docker-proxy](https://manual.seafile.com/docker/deploy%20seafile%20with%20docker/) as reverse proxy and the GlusterFS plugin [marcelo-ochoa/docker-volume-plugins](https://github.com/marcelo-ochoa/docker-volume-plugins). This resembles my personal setup. + #### Docker Swarm - ``` - wget https://github.com/ggogel/seafile-containerized/blob/master/compose/docker-compose-swarm.yml - ``` + If you run a single node swarm and don't want to run multiple replicas, you can use the same compose file. Otherwise refer to [Additional Information / Docker Swarm](#Docker-Swarm-1). + 3. ***Set environment variables*** @@ -240,3 +237,49 @@ For OAuth the same network problem as with LDAP will occur, but here you will ne caddy.rewrite: /accounts/login* /oauth/login/? ``` +### Docker Swarm + +If you want to stacks on a Docker Swarm with multiple nodes or if you want to run replicas of the frontend (clustering), there several things you have to consider first. + +**Important:** You can only deploy multiple replicas of the frontend services *seahub* and *seahub-media*. Deploying replicas of the backend or the database would cause data inconsistency or even data corruption. + +#### Storage +In order to make the same volumes available to services running on different nodes, you need an advanced storage solution. This could either be distributed storage like GlusterFS and Ceph or a network storage like a NFS share. The volumes are then usually mounted through storage plugins. The repository [marcelo-ochoa/docker-volume-plugins](https://github.com/marcelo-ochoa/docker-volume-plugins) contains some good storage plugins for Docker Swarm. + +``` +wget https://github.com/ggogel/seafile-containerized/blob/master/compose/docker-compose-swarm.yml +``` + +#### Network +If you have services running on different nodes, which have to communicate to each other, you have to define their network as an overlay network. This will span the network across the whole Swarm. +``` +seafile-net: + driver: overlay + internal: true +``` + +#### Reverse Proxy load balancing +If you want to run frontend replicas (clustering), you'll need to enable IP hash based load balancing. The load balancer, in this case *seafile-caddy*, will then create so called sticky sessions, which means that a client connecting with a certain IP will be forwarded to the same service for the time being. + +To enable IP hash based load balancing you have to configure the following options: + +Set the endpoint mode for the frontend services to dnsrr. This will enable *seafile-caddy* to see the IPs of all replicas, instead the default virtual IP (VIP) created by the Swarm routing mesh. +``` +deploy: + mode: replicated + replicas: 2 + endpoint_mode: dnsrr + +``` +Then you have to set the following environment variable for *seafile-caddy*, which will enable a periodic DNS resolution for the frontend services. +``` +environment: + - SWARM_DNS=true +``` + + +#### Example +You can check out this example and use it as a starting point for you Docker Swarm deployment. It is using [lucaslorentz/caddy-docker-proxy](https://manual.seafile.com/docker/deploy%20seafile%20with%20docker/) as the external reverse proxy and the GlusterFS plugin from [marcelo-ochoa/docker-volume-plugins](https://github.com/marcelo-ochoa/docker-volume-plugins). This resembles my personal production setup. +``` + wget https://github.com/ggogel/seafile-containerized/blob/master/compose/docker-compose.yml +``` From 4d5a87f8652959bb04b1fdbcbf374a8aa05b2541 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Mon, 25 Jan 2021 01:33:13 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index ef13095..6c838f4 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ Networks: The [official Docker deployment](https://manual.seafile.com/docker/deploy%20seafile%20with%20docker/) uses [bind mounts](https://docs.docker.com/storage/bind-mounts/) to the host path instead of actual docker volumes. This was probably chosen to create compatibility between a native install and the docker deployment. This deployment uses [named volumes](https://docs.docker.com/storage/volumes/), which come with several advantages over bind mounts and are the recommended mechanism for persisted storage on Docker. The default path for named volumes on Docker is `/var/lib/docker/volumes/VOLUME_NAME/_data`. + To migrate storage from the official Docker deployment run: ``` mkdir -p /var/lib/docker/volumes/seafile-data/_data @@ -141,6 +142,15 @@ Networks: ``` Of course you could also just use the old paths but I would strongly advise against that. + *Tip:* If you want to use a different path, like a separate drive, to store your Docker volumes, simply create a dynamic link like this: + ``` + docker service stop + mv /var/lib/docker/volumes /var/lib/docker/volumes-bak + mkdir -p /mnt/external/volumes + ln -sf /mnt/external/volumes /var/lib/docker + docker service start + ``` + 5. ***(Optional) Reverse Proxy*** Short version: