Skip to content

Commit cc83ec4

Browse files
committed
Add support for automated setup
Those changes provides a way to automatically setup a seafile/seahub instance with default settings. Settings can be overridden using environment variables right in docker-compose. Note this drops the seafile user, as it seems easier to let the end-user handle user management/file ownership inside it's own Dockerfile. Database creation is now provided by seafile mysql script (USE_EXISTING_DB=0).
1 parent af1fcff commit cc83ec4

14 files changed

Lines changed: 266 additions & 158 deletions

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ RUN \
3434
ln -s /run/seafile /opt/seafile/pids && \
3535
ln -s "${SEAFILE_PATH}" /opt/seafile/latest && \
3636
ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf && \
37-
mkdir -p /seafile && \
38-
# seafile user
39-
useradd -r -s /bin/false seafile && \
40-
chown seafile:seafile /run/seafile
37+
ln -s /scripts/setup.sh /bin/setup && \
38+
mkdir -p /seafile
4139

4240
WORKDIR "/seafile"
4341

4442
VOLUME "/seafile"
4543

4644
EXPOSE 80
4745

48-
CMD ["/scripts/startup.sh"]
46+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

README.md

Lines changed: 97 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,123 @@
11
# seafile-docker
22
Seafile docker image for swift setup
33

4-
## Getting started (docker-compose setup)
5-
* prepare docker-compose.yml (see example below)
6-
* start the system with `docker-compose up -d`
7-
* see `docker-compose logs mysql` to find out mysql root password (if you did not set it in docker-compose.override.yml)
8-
* perform initial setup with `docker-compose exec seafile setup` (this will ask you for mysql root password)
4+
## Quickstart
95

10-
## docker-compose.yml example
11-
```
12-
version: '2'
6+
* Write the following `docker-compose.yml` configuration. You should change environment variables as needed.
137

8+
```
9+
version: '2.2'
1410
services:
1511
seafile:
1612
image: foxel/seafile:6.3.3
1713
ports:
1814
- "9080:80"
1915
environment:
16+
MYSQL_ROOT_PASSWORD: 'my-root-secret'
17+
ADMIN_EMAIL: 'admin@example.com'
18+
ADMIN_PASSWORD: 'admin'
2019
SEAFILE_URL: 'http://seafile.example.com'
21-
links:
22-
- mysql
2320
volumes:
2421
- seafile:/seafile
2522
mysql:
2623
environment:
27-
MYSQL_RANDOM_ROOT_PASSWORD: 1
24+
MYSQL_ROOT_PASSWORD: 'my-root-secret'
2825
volumes:
2926
- mysql:/var/lib/mysql
3027
image: mysql:5.7
31-
3228
volumes:
33-
mysql:
34-
driver: local
29+
mysql: ~
30+
seafile: ~
31+
```
32+
33+
* Start the services with `docker-compose up -d`
34+
35+
* Connect to http://localhost:9080 and login with provided `ADMIN_EMAIL` and `ADMIN_PASSWORD` values.
36+
37+
## Without sensitive environment variables
38+
39+
If you mind using variables containing passwords, you can install seafile in two steps.
40+
41+
* Write the following `docker-compose.yml` configuration.
42+
43+
```
44+
version: '2.2'
45+
services:
3546
seafile:
36-
driver: local
47+
image: foxel/seafile:6.3.3
48+
ports:
49+
- "9080:80"
50+
environment:
51+
SEAFILE_URL: 'http://seafile.example.com'
52+
volumes:
53+
- seafile:/seafile
54+
mysql:
55+
volumes:
56+
- mysql:/var/lib/mysql
57+
image: mysql:5.7
58+
volumes:
59+
mysql: ~
60+
seafile: ~
61+
```
62+
63+
* Start the services with `docker-compose up -d`
64+
65+
* Check the generated mysql root password in docker logs
66+
67+
```
68+
docker-compose logs mysql
69+
```
70+
71+
* Run seafile setup by providing variables for the setup execution only.
72+
73+
```
74+
docker-compose exec \
75+
-e MYSQL_ROOT_PASSWORD="mysql-generated-password" \
76+
-e ADMIN_EMAIL="admin@example.com" \
77+
-e ADMIN_PASSWORD="admin" \
78+
seafile setup
3779
```
3880

81+
* Connect to http://localhost:9080 and login with provided `ADMIN_EMAIL` and `ADMIN_PASSWORD` values.
82+
83+
## Environment variables
84+
85+
- `MYSQL_ROOT_PASSWORD` (or `MYSQL_ROOT_PASSWD`)
86+
87+
Root password of the mysql database used during setup.
88+
89+
- `MYSQL_HOST` (default: `mysql`)
90+
91+
Docker service name of the mysql database.
92+
93+
- `ADMIN_EMAIL` (default: `admin@example.com`)
94+
95+
Default admin user email created during setup.
96+
97+
- `ADMIN_PASSWORD` (default: `admin`)
98+
99+
Default admin password created during setup.
100+
101+
- `USE_EXISTING_DB` (default: `0`)
102+
103+
Set to `1` if database already exists. This will create databases by default.
104+
105+
- `SERVER_NAME` (default: `seafile`)
106+
107+
Name of the seafile server.
108+
109+
- `CCNET_DB` (default: `ccnet-db`)
110+
111+
Ccnet database name.
112+
113+
- `SEAFILE_DB` (default: `seafile-db`)
114+
115+
Seafile database name.
116+
117+
- `SEAHUB_DB` (default: `seahub-db`)
118+
119+
Seahub database name.
120+
39121
## UPGRADING
40122

41123
Upgrading is possible in step-by-step manner:

docker-compose.override.yml.sample

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
version: '2'
2-
1+
version: '2.2'
32
services:
43
seafile:
54
ports:
65
- "9080:80"
76
environment:
8-
SEAFILE_URL: 'https://seafile.example.com'
9-
# volumes:
10-
# - /docker/seafile:/seafile
11-
# mysql:
12-
# environment:
13-
# MYSQL_ROOT_PASSWORD: 'my-root-secret'
7+
MYSQL_ROOT_PASSWORD: 'my-root-secret'
8+
ADMIN_EMAIL: 'admin@example.com'
9+
ADMIN_PASSWORD: 'admin'
10+
SEAFILE_URL: 'http://seafile.example.com'
11+
mysql:
12+
environment:
13+
MYSQL_ROOT_PASSWORD: 'my-root-secret'

docker-compose.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
version: '2'
2-
1+
version: '2.2'
32
services:
43
seafile:
54
build: .
6-
links:
7-
- mysql
85
volumes:
96
- seafile:/seafile
107
mysql:
11-
environment:
12-
MYSQL_RANDOM_ROOT_PASSWORD: 1
8+
image: mysql:5.7
139
volumes:
1410
- mysql:/var/lib/mysql
15-
image: mysql:5.7
16-
1711
volumes:
18-
mysql:
19-
driver: local
20-
seafile:
21-
driver: local
12+
mysql: ~
13+
seafile: ~

etc/supervisor.d/seafile.conf

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
[group:main]
2+
programs=seafile,seahub,nginx
3+
priority=10
4+
5+
[group:setup]
6+
programs=setup
7+
priority=1
8+
19
[program:seafile]
2-
user=seafile
310
command=/scripts/seafile.sh
4-
priority=1
11+
priority=3
512
autorestart=true
13+
startretries=9999999999999
614
redirect_stderr=false
715
stdout_logfile=/dev/stdout
816
stdout_logfile_maxbytes=0
@@ -12,10 +20,23 @@ stderr_logfile_maxbytes=0
1220
stderr_logfile_backups=0
1321

1422
[program:seahub]
15-
user=seafile
1623
command=/scripts/seahub.sh
1724
priority=5
1825
autorestart=true
26+
startretries=9999999999999
27+
redirect_stderr=false
28+
stdout_logfile=/dev/stdout
29+
stdout_logfile_maxbytes=0
30+
stdout_logfile_backups=0
31+
stderr_logfile=/dev/stderr
32+
stderr_logfile_maxbytes=0
33+
stderr_logfile_backups=0
34+
35+
[program:setup]
36+
command=/scripts/setup.sh
37+
priority=1
38+
autorestart=unexpected
39+
startretries=0
1940
redirect_stderr=false
2041
stdout_logfile=/dev/stdout
2142
stdout_logfile_maxbytes=0
@@ -27,6 +48,7 @@ stderr_logfile_backups=0
2748
[program:nginx]
2849
command=nginx
2950
priority=10
51+
startretries=0
3052
redirect_stderr=false
3153
stdout_logfile=/dev/stdout
3254
stdout_logfile_maxbytes=0

scripts/check-admin-user.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

33
. /scripts/seafile-env.sh
4+
. /scripts/seafile-setup-env.sh
5+
6+
if [[ ! -z "${ADMIN_EMAIL}" && ! -z \"${ADMIN_PASSWORD}\" ]]; then
7+
echo "{\"email\": \"${ADMIN_EMAIL}\", \"password\": \"${ADMIN_PASSWORD}\"}">"$SEAFILE_CENTRAL_CONF_DIR/admin.txt"
8+
fi
49

510
python ${INSTALLPATH}/check_init_admin.py

scripts/seafile-gc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [ $# -gt 0 ]; then
2121
fi
2222

2323
# stop server
24-
[ -f /var/run/supervisord.pid ] && supervisorctl stop all
24+
[ -f /var/run/supervisord.pid ] && supervisorctl stop main:*
2525

2626
"${seaf_gc}" \
2727
-c "${ccnet_conf_dir}" \
@@ -30,6 +30,6 @@ fi
3030
"$@";
3131

3232
# starting server
33-
[ -f /var/run/supervisord.pid ] && supervisorctl start all
33+
[ -f /var/run/supervisord.pid ] && supervisorctl start main:*
3434

3535
echo "Done"

scripts/seafile-setup-env.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
SERVER_NAME="${SERVER_NAME-seafile}"
4+
SERVER_IP="${SERVER_IP-127.0.0.1}"
5+
FILESERVER_PORT="${FILESERVER_PORT-8082}"
6+
SEAFILE_DIR="${SEAFILE_DIR-${SEAFILE_PATH}/seafile-data}"
7+
8+
USE_EXISTING_DB="${USE_EXISTING_DB-0}"
9+
MYSQL_HOST="${MYSQL_HOST-mysql}"
10+
MYSQL_PORT="${MYSQL_PORT-3306}"
11+
12+
MYSQL_ROOT_PASSWD="${MYSQL_ROOT_PASSWD-${MYSQL_ROOT_PASSWORD}}"
13+
14+
MYSQL_USER="${MYSQL_USER-seafile}"
15+
MYSQL_USER_PASSWD="${MYSQL_USER_PASSWD-${MYSQL_USER}}"
16+
MYSQL_USER_HOST="${MYSQL_USER_HOST-%}"
17+
18+
CCNET_DB="${CCNET_DB-ccnet-db}"
19+
SEAFILE_DB="${SEAFILE_DB-seafile-db}"
20+
SEAHUB_DB="${SEAHUB_DB-seahub-db}"
21+
22+
ADMIN_EMAIL="${ADMIN_EMAIL-admin@example.com}"
23+
ADMIN_PASSWORD="${ADMIN_PASSWORD-admin}"

scripts/seafile.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/bin/bash
22

3+
if [ ! -f /seafile/.installed ]; then
4+
exit 0
5+
fi
6+
37
. /scripts/seafile-env.sh
48

9+
# fix seafile install path symlinks
10+
for folder in ccnet conf logs seafile-data seahub-data; do
11+
[ -L "/opt/seafile/${folder}" ] || ln -s "/seafile/${folder}" "/opt/seafile/${folder}"
12+
done
13+
514
seaf_controller="${INSTALLPATH}/seafile/bin/seafile-controller"
615

716
echo "Starting seafile server, please wait ..."
@@ -10,4 +19,3 @@ exec "${seaf_controller}" -f \
1019
-c "${ccnet_conf_dir}" \
1120
-d "${seafile_data_dir}" \
1221
-F "${central_config_dir}"
13-

scripts/seahub.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
#!/bin/bash
22

3+
if [ ! -f /seafile/.installed ]; then
4+
exit 0
5+
fi
6+
37
. /scripts/seafile-env.sh
48

9+
# fix seahub symlinks
10+
if [ ! -L ${SEAFILE_PATH}/seahub/media/avatars ]; then
11+
rm -rf ${SEAFILE_PATH}/seahub/media/avatars
12+
ln -s /seafile/seahub-data/avatars ${SEAFILE_PATH}/seahub/media/avatars
13+
fi
14+
15+
if [ ! -L ${SEAFILE_PATH}/seahub/media/custom ]; then
16+
rm -rf ${SEAFILE_PATH}/seahub/media/custom
17+
ln -s /seafile/seahub-data/custom ${SEAFILE_PATH}/seahub/media/custom
18+
fi
19+
20+
if [ ! -L ${SEAFILE_PATH}/seahub/media/CACHE ]; then
21+
rm -rf ${SEAFILE_PATH}/seahub/media/CACHE
22+
ln -s /seafile/seahub-data/CACHE ${SEAFILE_PATH}/seahub/media/CACHE
23+
fi
24+
525
manage_py="${INSTALLPATH}/seahub/manage.py"
626
gunicorn_conf=${INSTALLPATH}/runtime/seahub.conf
727
gunicorn_exe=${INSTALLPATH}/seahub/thirdpart/gunicorn

0 commit comments

Comments
 (0)