Added docker files.
This commit is contained in:
parent
7e166688ff
commit
c85ee014f8
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
FROM debian:wheezy-slim
|
||||||
|
|
||||||
|
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8756C4F765C9AC3CB6B85D62379CE192D401AB61 && \
|
||||||
|
echo deb http://deb.seadrive.org wheezy main | tee /etc/apt/sources.list.d/seafile.list && \
|
||||||
|
apt-get update -y && \
|
||||||
|
apt-get install -y seafile-cli procps curl && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /seafile-client
|
||||||
|
|
||||||
|
COPY start.sh /seafile-client/start.sh
|
||||||
|
|
||||||
|
RUN chmod +x /seafile-client/start.sh && \
|
||||||
|
useradd -U -d /seafile-client -s /bin/bash seafile && \
|
||||||
|
usermod -G users seafile && \
|
||||||
|
chown seafile:seafile -R /seafile-client && \
|
||||||
|
su - seafile -c "seaf-cli init -d /seafile-client"
|
||||||
|
|
||||||
|
CMD ["./start.sh"]
|
||||||
15
docker-compose.yaml
Normal file
15
docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
seafile-client:
|
||||||
|
restart: always
|
||||||
|
image: gronis:seafile-client-docker
|
||||||
|
container_name: seafile-client
|
||||||
|
environment:
|
||||||
|
- LIBRARY_ID=<your-library-id-here>
|
||||||
|
- SERVER_URL=<server-url>
|
||||||
|
- SERVER_PORT=<server-port>
|
||||||
|
- USERNAME=<username>
|
||||||
|
- PASSWORD=<password>
|
||||||
|
- DATA_DIR=<directory-path-to-sync>
|
||||||
|
volumes:
|
||||||
|
- <host-volume-path>:<directory-path-to-sync>
|
||||||
72
start.sh
Normal file
72
start.sh
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
DATA_DIR="${DATA_DIR:-/data}"
|
||||||
|
SEAFILE_UID="${SEAFILE_UID:-1000}"
|
||||||
|
SEAFILE_GID="${SEAFILE_GID:-1000}"
|
||||||
|
|
||||||
|
get () {
|
||||||
|
NAME="$1"
|
||||||
|
JSON="$2"
|
||||||
|
# Tries to regex setting name from config. Only works with strings for now
|
||||||
|
VALUE=$(echo $JSON | grep -Po '"'"$NAME"'"\s*:\s*.*?[^\\]"+,*' | sed -n -e 's/.*: *"\(.*\)",*/\1/p')
|
||||||
|
# Use eval to ensure that nested expressens are executed (config points to environment var)
|
||||||
|
eval echo $VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_lib_sync(){
|
||||||
|
if [ ! -d $DATA_DIR ]; then
|
||||||
|
echo "Using new data directory: $DATA_DIR"
|
||||||
|
mkdir -p $DATA_DIR
|
||||||
|
chown seafile:seafile -R $DATA_DIR
|
||||||
|
fi
|
||||||
|
TOKEN_JSON=$(curl -d "username=$USERNAME" -d "password=$PASSWORD" ${SERVER_URL}:${SERVER_PORT}/api2/auth-token/ 2> /dev/null)
|
||||||
|
TOKEN=$(get token "$TOKEN_JSON")
|
||||||
|
LIBS=(${LIBRARY_ID//:/ })
|
||||||
|
for i in "${!LIBS[@]}"
|
||||||
|
do
|
||||||
|
LIB="${LIBS[i]}"
|
||||||
|
LIB_JSON=$(curl -G -H "Authorization: Token $TOKEN" -H 'Accept: application/json; indent=4' ${SERVER_URL}:${SERVER_PORT}/api2/repos/${LIB}/ 2> /dev/null)
|
||||||
|
LIB_NAME=$(get name "$LIB_JSON")
|
||||||
|
LIB_DIR=${DATA_DIR}/${LIB_NAME}
|
||||||
|
if [ ! -d $LIB_DIR ]; then
|
||||||
|
echo "Syncing $LIB_NAME"
|
||||||
|
mkdir -p $LIB_DIR
|
||||||
|
chown seafile:seafile -R $LIB_DIR
|
||||||
|
su - seafile -c "seaf-cli sync -l \"$LIB\" -s \"${SERVER_URL}:${SERVER_PORT}\" -d $LIB_DIR -u \"$USERNAME\" -p \"$PASSWORD\""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_uid(){
|
||||||
|
# Setup user/group ids
|
||||||
|
if [ ! "$(id -u seafile)" -eq "${SEAFILE_UID}" ]; then
|
||||||
|
# Change the SEAFILE_UID
|
||||||
|
usermod -o -u "${SEAFILE_UID}" -g "${SEAFILE_GID}" seafile
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_in_foreground() {
|
||||||
|
# As there seems to be no way to let Seafile processes run in the foreground we
|
||||||
|
# need a foreground process. This has a dual use as a supervisor script because
|
||||||
|
# as soon as one process is not running, the command returns an exit code >0
|
||||||
|
# leading to a script abortion thanks to "set -e".
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
for SEAFILE_PROC in "ccnet" "seaf-daemon"
|
||||||
|
do
|
||||||
|
pkill -0 -f "${SEAFILE_PROC}"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
su - seafile -c "seaf-cli status"
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_uid
|
||||||
|
su - seafile -c "seaf-cli start"
|
||||||
|
setup_lib_sync
|
||||||
|
keep_in_foreground
|
||||||
Loading…
Reference in New Issue
Block a user