Move Dockerfile and assets, add labels for MicroBadger

This commit is contained in:
flow.gunso
2020-01-04 10:07:24 +01:00
parent 1741ddb98d
commit d16a21758f
6 changed files with 132 additions and 79 deletions

77
seafile-client/Dockerfile Normal file
View File

@@ -0,0 +1,77 @@
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019-2020, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM debian:buster-slim
# For MicroBadger.
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Seafile Docker client" \
org.label-schema.description="Sync Seafile librairies within Docker containers." \
org.label-schema.url=$CI_PROJECT_URL \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$CI_PROJECT_URL \
org.label-schema.vendor="flow.gunso@gmail.com" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
# Prevent the packages installation to halt.
ENV DEBIAN_FRONTEND noninteractive
# Create the Seafile client's user.
ENV UNAME=seafuser
ENV UID=1000
ENV GID=1000
# Seafile optional configuration.
ENV SEAF_SKIP_SSL_CERT=1
# Safely import Seafile APT key, then install both seafile-cli and supervisord.
COPY import-seafile-apt-key.sh /
RUN apt-get update && apt-get install -y gnupg && \
mkdir -p /etc/apt/sources.list.d/ && \
echo "deb http://deb.seadrive.org buster main" > /etc/apt/sources.list.d/seafile.list && \
bash /import-seafile-apt-key.sh && \
apt-get purge --yes gnupg && apt-get autoremove --yes && \
apt-get update && apt-get install \
--no-install-recommends \
--yes \
seafile-cli \
oathtool \
cron && \
apt-get clean && apt-get autoclean && \
rm -rf \
/var/log/fsck/*.log \
/var/log/apt/*.log \
/var/cache/debconf/*.dat-old \
/var/lib/apt/lists/* \
/import-seafile-apt-key.sh && \
mkdir /volume/ && \
echo "seafuser" > /etc/cron.allow && \
echo "*/20 * * * * /bin/bash /home/seafuser/healthcheck.sh" \
> /var/spool/cron/crontabs/seafuser && \
groupadd -g $GID -o $UNAME && \
useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
# Copy over the entrypoints, healthchecks and tests.
COPY docker-entrypoint.sh /entrypoint.sh
COPY seafile-healthcheck.sh /home/seafuser/healthcheck.sh
COPY seafile-entrypoint.sh /home/seafuser/entrypoint.sh
COPY tests /tests
# Set bash as the entrypoint and run the entrypoint script from that.
ENTRYPOINT ["/bin/bash"]
CMD ["/entrypoint.sh"]

View File

@@ -0,0 +1,94 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019-2020, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Check mandatory Seafile configuration have been properly set.
if [ -z $SEAF_SERVER_URL ]; then
echo "The \$SEAF_SERVER_URL is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_USERNAME ]; then
echo "The \$SEAF_USERNAME is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_PASSWORD ]; then
echo "The \$SEAF_PASSWORD is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_LIBRARY_UUID ]; then
echo "The \$SEAF_LIBRARY_UUID is not defined. Stopping container..."
exit 1
fi
if [[ -n "$SEAF_UPLOAD_LIMIT"
&& $SEAF_UPLOAD_LIMIT =~ ^[0-9]+$
&& "$SEAF_UPLOAD_LIMIT" -gt 0 ]]; then
echo "The \$SEAF_UPLOAD_LIMIT is not an integer greater than 0. Stopping container..."
exit 1
fi
if [[ -n "$SEAF_DOWNLOAD_LIMIT"
&& $SEAF_DOWNLOAD_LIMIT =~ ^[0-9]+$
&& "$SEAF_DOWNLOAD_LIMIT" -gt 0 ]]; then
echo "The \$SEAF_DOWNLOAD_LIMIT is not an integer greater than 0. Stopping container..."
exit 1
fi
if [ -n "$SEAF_2FA_SECRET" ]; then
curl -X POST http://2fa:1880/auth \
-H "Content-Type: application/json" \
-d '{"secret":"YWAMNW7YTTB2QDU6ENTJ4LIPUYFUG4SW","key":"docker-seaf-cli","desc":"/"}'
if [ $? -ne 0 ]; then
echo "Could create an 2FA token provider at $SEAF_2FA_PROVIDER. curl error $?"
exit 1
fi
fi
# Update the user ID, if the $UID changed.
if [ "$UID" != "1000" ]; then
usermod -u $UID $UNAME
# What if the $UID already exists ?
fi
# Change the group, if the $GID changed.
if [ "$GID" != "1000" ]; then
getent group | grep ":$GID:" >/dev/null
if [ $? -eq 0 ]; then
usermod -g $GID -G 1000 $UNAME
else
groupmod -g $GID $UNAME
fi
fi
# Set the files ownership.
chown $UID.$GID /home/seafuser/seafile-healthcheck.sh
chown $UID.$GID /home/seafuser/entrypoint.sh
chown $UID.$GID -R /volume
# Run the Seafile client as the container user.
su - $UNAME << EO
export SEAF_SERVER_URL=$SEAF_SERVER_URL
export SEAF_USERNAME=$SEAF_USERNAME
export SEAF_PASSWORD=$SEAF_PASSWORD
export SEAF_LIBRARY_UUID=$SEAF_LIBRARY_UUID
export SEAF_SKIP_SSL_CERT=$SEAF_SKIP_SSL_CERT
test -n "$SEAF_UPLOAD_LIMIT" && export SEAF_UPLOAD_LIMIT=$SEAF_UPLOAD_LIMIT
test -n "$SEAF_DOWNLOAD_LIMIT" && export SEAF_DOWNLOAD_LIMIT=$SEAF_DOWNLOAD_LIMIT
test -n "$SEAF_2FA_SECRET" && export SEAF_2FA_SECRET=$SEAF_2FA_SECRET
test -n "$SEAF_LIBRARY_PASSWORD" && export SEAF_LIBRARY_PASSWORD=$SEAF_LIBRARY_PASSWORD
export UNAME=$UNAME
/bin/bash /home/seafuser/entrypoint.sh
EO
cron -f

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019-2020, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
not_imported=true
while $not_imported; do
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8756C4F765C9AC3CB6B85D62379CE192D401AB61
if [ $? -eq 0 ]; then
not_imported=false
else
sleep 5
fi
done

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019-2020, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Define variable shortcuts for readability purposes.
seafile_ini=~/.ccnet/seafile.ini
seafile_sock=~/.seafile/seafile-data/seafile.sock
# Prepare the directories.
mkdir ~/.seafile
# Safely initialise the Seafile client.
/usr/bin/seaf-cli init -d ~/.seafile
while [ ! -f $seafile_ini ]; do sleep 1; done
# Safely start the Seafile daemon.
/usr/bin/seaf-cli start
while [ ! -S $seafile_sock ]; do sleep 1; done
# Set the disable_verify_certificate key to true only if the environment variable is true.
test "$SEAF_SKIP_SSL_CERT" = true && seaf-cli config -k disable_verify_certificate -v true
# Set the upload/download limits
test -n "$SEAF_PLOAD_LIMIT" && seaf-cli config -k upload_limit -v $SEAF_UPLOAD_LIMIT
test -n "$SEAF_DOWNLOAD_LIMIT" && seaf-cli config -k download_limit -v $SEAF_DOWNLOAD_LIMIT
# Build the seaf-cli sync command.
cmd="seaf-cli sync -u $SEAF_USERNAME -p $SEAF_PASSWORD -s $SEAF_SERVER_URL -l $SEAF_LIBRARY_UUID"
test $SEAF_2FA_SECRET && cmd+=" -a $(oathlib --base32 --totp $SEAF_2FA_SECRET)"
test $SEAF_LIBRARY_PASSWORD && cmd+=" -e $SEAF_LIBRARY_PASSWORD"
# Run it.
if ! eval $cmd; then echo "Failed to sync"; exit 1; fi

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019-2020, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# `seaf-cli status` output csv-like information with tabulates as separators and columns named in comment lines.
# The Seafile client should not be restarted while some statuses are occuring, such as "downloading" or "committing".
#
# This script grabs the output while ignoring the comments to iterate over the informations set to their columns,
# then it compares the statuses, when not empty, to the ones that do not require a restart. Finally either restart or don't.
seaf=/usr/bin/seaf-cli
dont_restart_on=("downloading" "committing")
restart=true
while IFS=$'\t' read -r name status progress; do
if [ $status ]; then
for dont_restart_on_status in "${dont_restart_on[@]}"; do
if [ "$status" == "$dont_restart_on_status" ]; then
restart=false; break; break
fi
done
fi
done < <($seaf status | grep -v "^#")
if $restart; then
$seaf stop
$seaf start
fi