This commit is contained in:
Jiang Yio 2022-08-29 16:20:14 -04:00
parent cfb78d99c3
commit 2c7531f75d
4 changed files with 258 additions and 1 deletions

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM debian:bullseye-slim
LABEL maintainer "Jiang Yio <inportb@gmail.com>"
ENV SEAFILE_DIR=/opt/seafile
RUN apt update && \
apt install -y python3 python3-setuptools python3-pip python3-jinja2 python3-ldap sqlite3 curl procps dialog nano && \
apt clean && rm -rf /var/lib/apt/lists/* && \
pip3 install --no-cache-dir --timeout=3600 Pillow captcha sqlalchemy==1.4.3 django-simple-captcha && \
adduser --disabled-password --home "${SEAFILE_DIR}" --gecos "" seafile && \
mkdir -p "${SEAFILE_DIR}" && chown seafile:seafile "${SEAFILE_DIR}"
COPY entrypoint.sh /usr/local/bin/seaf-ctl
EXPOSE 8000 8080 8082
VOLUME ["/opt/seafile"]
USER seafile
ENV PATH=${PATH}:${SEAFILE_DIR}/seafile-server-latest
ENTRYPOINT ["/usr/local/bin/seaf-ctl"]
CMD ["init"]

View File

@ -1,3 +1,15 @@
# docker-seafile
Seafile installer for Docker
Seafile installer for Docker
`seaf-ctl init`: Start Seafile if possible or hang (default)
`seaf-ctl setup`: Download and install Seafile (run first)
`seaf-ctl createsuperuser`: Create admin account
`seaf-ctl start`: Start Seafile
`seaf-ctl restart`: Restart Seafile
`seaf-ctl stop`: Stop Seafile

16
docker-compose.yml Normal file
View File

@ -0,0 +1,16 @@
version: '3.6'
services:
main:
build: .
environment:
SEAFILE_SERVER_NAME: Seafile
SEAFILE_SERVER_HOST: seafile.example.com
ports:
- '8000:8000'
- '8080:8080'
- '8082:8082'
volumes:
- seafile-data:/opt/seafile
restart: unless-stopped
volumes:
seafile-data:

208
entrypoint.sh Executable file
View File

@ -0,0 +1,208 @@
#!/bin/sh
SEAFILE_DIR_LATEST="${SEAFILE_DIR}/seafile-server-latest"
version_lte() { # https://stackoverflow.com/a/4024263
[ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
}
version_lt() { # https://stackoverflow.com/a/4024263
[ "$1" = "$2" ] && return 1 || version_lte "$1" "$2"
}
path_version() {
version="`readlink -m "$1"`"
version="${version%/}"
echo "${version##*-}"
}
download_list() {
curl -sL https://download.seadrive.org/ | grep -o 'seafile-server_[^_]*_[^_]*\.tar\.gz' | sort -rV
}
download_select() {
case "$1" in
http*)
echo "$1"
;;
seafile-server_*.tar.gz)
echo "https://download.seadrive.org/$1"
;;
6.*|7.*|8.*|9.*)
echo "https://download.seadrive.org/seafile-server_$1_x86-64.tar.gz"
;;
latest)
selection="`download_list | head -1`"
echo "https://download.seadrive.org/${selection}"
;;
*)
options=`download_list | awk '{print $1, "on"}'`
selection="`dialog --stdout --no-items --ok-label Fetch --radiolist "Choose version:" 0 0 0 ${options}`"
if [ ! "$selection" = "" ]; then
echo "https://download.seadrive.org/${selection}"
fi
;;
esac
}
build_download() {
url="`download_select "$@"`"
if [ ! "$url" = "" ]; then
echo 1>&2 "Fetching <${url}>..."
curl -sL "${url}" > "${SEAFILE_DIR}/pkg.tar.gz"
name="`tar -tvf "${SEAFILE_DIR}/pkg.tar.gz" | head -1 | awk '{print $6}'`"
echo 1>&2 "Unpacking \`${name%/}'..."
tar -xzf "${SEAFILE_DIR}/pkg.tar.gz" -C "${SEAFILE_DIR}"
rm "${SEAFILE_DIR}/pkg.tar.gz"
echo "${name%/}"
fi
}
build_setup() {
if [ -e "$1" ]; then
version_new="`path_version "$1"`"
echo 1>&2 "\033[32m Info: \033[0m Requested: ${version_new}"
version_old=
if [ -L "${SEAFILE_DIR_LATEST}" ]; then
version_old="`path_version "${SEAFILE_DIR_LATEST}"`"
echo 1>&2 "\033[32m Info: \033[0m Installed: ${version_old}"
control_server stop
fi
if [ ! -e "${SEAFILE_DIR}/seafile-data" ]; then
(
cd "${SEAFILE_DIR}/seafile-server-${version_new}"
echo 1>&2 "==> ./setup-seafile.sh"
server_name=${SEAFILE_SERVER_NAME} ip_or_domain=${SEAFILE_SERVER_HOST} ./setup-seafile.sh auto
sed -i 's/127\.0\.0\.1/0.0.0.0/' "${SEAFILE_DIR}/conf/gunicorn.conf.py"
)
fi
if [ ! "${version_old}" = "" ] && [ ! "${version_old}" = "${version_new}" ]; then
if version_lt "${version_old}" "${version_new}"; then
echo 1>&2 "\033[32m Info: \033[0m Upgrade needed ${version_old} => ${version_new}."
oldver1=`echo "$version_old" | cut -d. -f1`
oldver2=`echo "$version_old" | cut -d. -f2`
nxtver1=${oldver1}
nxtver2=`expr ${oldver2} + 1`
newver1=`echo "$version_new" | cut -d. -f1`
newver2=`echo "$version_new" | cut -d. -f2`
while [ $nxtver1 -le $newver1 ]; do
script="${SEAFILE_DIR}/seafile-server-${version_new}/upgrade/upgrade_${oldver1}.${oldver2}_${nxtver1}.${nxtver2}.sh"
if [ -f $script ]; then
echo 1>&2 "==> ${script}"
"${script}"
if [ "$nxtver1" = "6" -a "$nxtver2" = "3" ]; then
(
cd "${SEAFILE_DIR}/seafile-server-${version_new}/seahub"
./manage.py migrate_file_comment
)
fi
oldver2=${nxtver2}
nxtver2=`expr ${nxtver2} + 1`
else
oldver1=${nxtver1}
nxtver1=`expr ${nxtver1} + 1`
nxtver2=0
fi
done
"${SEAFILE_DIR}/seafile-server-${version_new}/upgrade/minor-upgrade.sh"
sed -i 's/127\.0\.0\.1/0.0.0.0/' "${SEAFILE_DIR}/conf/gunicorn.conf.py"
else
echo 1>&2 "\033[33m Warning: \033[0m Manual intervention required to downgrade ${version_old} => ${version_new}."
fi
fi
else
echo 1>&2 "\033[31m Error: \033[0m \`$1' not available."
fi
}
control_server() {
"${SEAFILE_DIR_LATEST}/seafile.sh" "$@" || return 1
"${SEAFILE_DIR_LATEST}/seahub.sh" "$@" || return 1
}
collect_logs() {
for fn in "${SEAFILE_DIR}/logs"/*; do
if [ -s "${fn}" ]; then
echo "==> ${fn} <==" >> "${SEAFILE_DIR}/logs/.history"
cat "${fn}" >> "${SEAFILE_DIR}/logs/.history"
echo >> "${SEAFILE_DIR}/logs/.history"
truncate -s0 "${fn}"
fi
done
}
tail_logs() {
tail -f "${SEAFILE_DIR}/logs"/*
}
wait_forever() {
while :; do
if [ -e "${SEAFILE_DIR}/.stop" ]; then
echo 1>&2 "\033[32m Info: \033[0m Received shutdown signal."
rm "${SEAFILE_DIR}/.stop"
exit 0
else
sleep 4
fi
done
}
do_init() {
if [ -f "${SEAFILE_DIR}/seafile-data/version" ]; then
data_version=`cat "${SEAFILE_DIR}/seafile-data/version"`
if [ ! "${SEAFILE_VERSION}" = "${data_version}" ]; then
echo 1>&2 "\033[31m Error: \033[0m Seafile server version mismatch."
echo 1>&2 "Server: ${SEAFILE_VERSION}"
echo 1>&2 "Data: ${data_version}"
if version_lt "${data_version}" "${SEAFILE_VERSION}"; then
echo 1>&2 "\033[32m Info: \033[0m Consider running upgrade scripts per <https://manual.seafile.com/deploy/upgrade/>"
fi
echo 1>&2 "\033[32m Info: \033[0m Remove \`${SEAFILE_DIR}/seafile-data/version' after reconciling versions."
return 1
fi
fi
if [ -e "${SEAFILE_DIR_LATEST}" ]; then
collect_logs
if control_server start; then
echo -n "${SEAFILE_VERSION}" > "${SEAFILE_DIR}/seafile-data/version"
sleep 2
else
echo 1>&2 "\033[31m Error: \033[0m Seafile server not started."
fi
tail_logs &
else
echo 1>&2 "\033[31m Error: \033[0m Seafile server not installed. Run \`$0 setup' to install."
fi
wait_forever
}
CMD="$1"
[ "$#" -gt 0 ] && shift
case "${CMD}" in
setup)
version="`build_download "$@"`"
build_setup "${SEAFILE_DIR}/${version}"
echo 1>&2 "\033[32m Info: \033[0m Run \`$0 start' to start seafile and seahub."
;;
createsuperuser)
"${SEAFILE_DIR_LATEST}/seahub/manage.py" createsuperuser
;;
start)
control_server start "$@"
;;
restart)
control_server restart "$@"
;;
stop)
control_server stop
;;
shutdown)
touch "${SEAFILE_DIR}/.stop"
echo 1>&2 "\033[32m Info: \033[0m Sent shutdown signal."
;;
init)
do_init
;;
*)
do_init
;;
esac