[docker-registry] EPEL support
Marek Goldmann
goldmann at fedoraproject.org
Tue Dec 3 08:15:59 UTC 2013
commit 1e53b1ee25e84937ea5837abb212e6bfe2dd689e
Author: Marek Goldmann <marek.goldmann at gmail.com>
Date: Mon Dec 2 17:48:15 2013 +0100
EPEL support
Support-for-older-Redis-Python-binding.patch | 25 ++++++
docker-registry.service | 6 +-
docker-registry.spec | 78 +++++++++++++++---
docker-registry.sysconfig | 12 ++-
docker-registry.sysvinit | 114 ++++++++++++++++++++++++++
5 files changed, 218 insertions(+), 17 deletions(-)
---
diff --git a/Support-for-older-Redis-Python-binding.patch b/Support-for-older-Redis-Python-binding.patch
new file mode 100644
index 0000000..9016802
--- /dev/null
+++ b/Support-for-older-Redis-Python-binding.patch
@@ -0,0 +1,25 @@
+From a2bba31a77bc6cfa3ef1edbd3e3b52490d5b88cc Mon Sep 17 00:00:00 2001
+From: Marek Goldmann <marek.goldmann at gmail.com>
+Date: Thu, 21 Nov 2013 11:12:22 +0100
+Subject: [PATCH] Support for older Redis Python binding
+
+---
+ lib/cache.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/cache.py b/lib/cache.py
+index 8cfaae3..6aac82b 100644
+--- a/lib/cache.py
++++ b/lib/cache.py
+@@ -30,7 +30,7 @@ def init():
+ for k, v in cache.iteritems():
+ redis_opts[k] = v
+ logging.info('Redis config: {0}'.format(redis_opts))
+- redis_conn = redis.StrictRedis(host=redis_opts['host'],
++ redis_conn = redis.Redis(host=redis_opts['host'],
+ port=int(redis_opts['port']),
+ db=int(redis_opts['db']),
+ password=redis_opts['password'])
+--
+1.8.4.2
+
diff --git a/docker-registry.service b/docker-registry.service
index 9e9ab0d..5c90ea0 100644
--- a/docker-registry.service
+++ b/docker-registry.service
@@ -5,10 +5,10 @@ Requires=redis.service
[Service]
Type=simple
Environment=DOCKER_REGISTRY_CONFIG=/etc/docker-registry.yml
-EnvironmentFile=-/etc/docker-registry
-WorkingDirectory=/usr/lib/python2.7/site-packages/docker-registry
+EnvironmentFile=-/etc/sysconfig/docker-registry
+WorkingDirectory=#WORKDIR#
ExecStart=/usr/bin/gunicorn --access-logfile - --debug --max-requests 100 --graceful-timeout 3600 -t 3600 -k gevent -b ${REGISTRY_ADDRESS}:${REGISTRY_PORT} -w $GUNICORN_WORKERS wsgi:application
-#Restart=on-failure
+Restart=on-failure
[Install]
WantedBy=multi-user.target
diff --git a/docker-registry.spec b/docker-registry.spec
index 5fa38d4..589fce3 100644
--- a/docker-registry.spec
+++ b/docker-registry.spec
@@ -1,20 +1,35 @@
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
+%if 0%{?fedora} >= 19 || 0%{?rhel} >= 7
+%bcond_without systemd
+%endif
+
Summary: Registry server for Docker
Name: docker-registry
Version: 0.6.0
-Release: 2%{?dist}
+Release: 3%{?dist}
License: ASL 2.0
URL: https://github.com/dotcloud/docker-registry
Source: https://github.com/dotcloud/docker-registry/archive/%{version}.tar.gz
Source1: docker-registry.service
Source2: docker-registry.sysconfig
+Source3: docker-registry.sysvinit
+
+# Support for older Redis Python binding in EPEL
+Patch0: Support-for-older-Redis-Python-binding.patch
BuildRequires: python2-devel
-BuildRequires: systemd
-Requires(post): systemd
-Requires(preun): systemd
-Requires(postun): systemd
+
+%if %{with systemd}
+BuildRequires: systemd
+Requires(post): systemd
+Requires(preun): systemd
+Requires(postun): systemd
+%else
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(postun): initscripts
+%endif
Requires: python-boto
Requires: python-flask
@@ -41,38 +56,69 @@ Registry server for Docker (hosting/delivering of repositories and images).
# It's not the main one (yet?)
rm -rf contrib/golang_impl
+%if !%{with systemd}
+%patch0 -p1
+%endif
+
%install
install -d %{buildroot}%{_bindir}
-install -d %{buildroot}%{_unitdir}
-install -d %{buildroot}%{_sysconfdir}
+install -d %{buildroot}%{_sysconfdir}/sysconfig
install -d %{buildroot}%{_sharedstatedir}/%{name}
-
install -d %{buildroot}%{python_sitelib}/%{name}
+install -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
+
+%if %{with systemd}
+install -d %{buildroot}%{_unitdir}
install -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
-install -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/%{name}
+
+# Make sure we set proper WorkingDir in the systemd service file
+sed -i "s|#WORKDIR#|%{python_sitelib}/%{name}|" %{buildroot}%{_unitdir}/%{name}.service
+%else
+install -d %{buildroot}%{_initddir}
+install -p -m 755 %{SOURCE3} %{buildroot}%{_initddir}/%{name}
+
+# Make sure we set proper wrking dir in the sysvinit file
+sed -i "s|#WORKDIR#|%{python_sitelib}/%{name}|" %{buildroot}%{_initddir}/%{name}
+%endif
cp -r lib registry test %{buildroot}%{python_sitelib}/%{name}
cp wsgi.py %{buildroot}%{python_sitelib}/%{name}
cp config_sample.yml %{buildroot}%{_sysconfdir}/%{name}.yml
-
echo "local:
storage: local
storage_path: %{_sharedstatedir}/%{name}" >> %{buildroot}%{_sysconfdir}/%{name}.yml
%post
+%if %{with systemd}
%systemd_post %{name}.service
+%else
+/sbin/chkconfig --add %{name}
+%endif
%preun
+%if %{with systemd}
%systemd_preun %{name}.service
+%else
+if [ $1 -eq 0 ] ; then
+ /sbin/service %{name} stop >/dev/null 2>&1
+ /sbin/chkconfig --del %{name}
+fi
+%endif
%postun
+%if %{with systemd}
%systemd_postun_with_restart %{name}.service
+%else
+if [ "$1" -ge "1" ] ; then
+ /sbin/service %{name} condrestart >/dev/null 2>&1 || :
+fi
+%endif
%files
%dir %{python_sitelib}/%{name}
-%config(noreplace) %{_sysconfdir}/%{name}
+%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %{_sysconfdir}/%{name}.yml
%{python_sitelib}/%{name}/lib/*.py
%{python_sitelib}/%{name}/lib/*.pyc
@@ -89,11 +135,19 @@ echo "local:
%{python_sitelib}/%{name}/*.py
%{python_sitelib}/%{name}/*.pyc
%{python_sitelib}/%{name}/*.pyo
-%{_unitdir}/%{name}.service
%dir %{_sharedstatedir}/%{name}
%doc LICENSE README.md
+%if %{with systemd}
+%{_unitdir}/%{name}.service
+%else
+%{_initddir}/%{name}
+%endif
%changelog
+* Mon Dec 02 2013 Marek Goldmann <mgoldman at redhat.com> - 0.6.0-3
+- EPEL support
+- Comments in the sysconfig/docker-registry file
+
* Wed Nov 27 2013 Marek Goldmann <mgoldman at redhat.com> - 0.6.0-2
- Added license and readme
diff --git a/docker-registry.sysconfig b/docker-registry.sysconfig
index 4d4b834..93c8755 100644
--- a/docker-registry.sysconfig
+++ b/docker-registry.sysconfig
@@ -1,6 +1,14 @@
-REGISTRY_ADDRESS=0.0.0.0
-REGISTRY_PORT=5000
+# The Docker registry configuration file
+DOCKER_REGISTRY_CONFIG=/etc/docker-registry.yml
+# The configuration to use from DOCKER_REGISTRY_CONFIG file
SETTINGS_FLAVOR=local
+# Address to bind the registry to
+REGISTRY_ADDRESS=0.0.0.0
+
+# Port to bind the registry to
+REGISTRY_PORT=5000
+
+# Number of workers to handle the connections
GUNICORN_WORKERS=8
diff --git a/docker-registry.sysvinit b/docker-registry.sysvinit
new file mode 100644
index 0000000..7a206b3
--- /dev/null
+++ b/docker-registry.sysvinit
@@ -0,0 +1,114 @@
+#!/bin/sh
+#
+# /etc/rc.d/init.d/docker-registry
+#
+# Registry server for Docker
+#
+# chkconfig: 2345 93 93
+# description: Registry server for Docker
+
+### BEGIN INIT INFO
+# Provides: docker-registry
+# Required-Start: $network
+# Required-Stop:
+# Should-Start:
+# Should-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: start and stop Docker registry
+# Description: Registry server for Docker
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/usr/bin/python"
+prog="docker-registry"
+pidfile="/var/run/$prog.pid"
+lockfile="/var/lock/subsys/$prog"
+logfile="/var/log/$prog"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+
+ if ! [ -f $pidfile ]; then
+ cd #WORKDIR#
+ printf "Starting $prog:\t"
+ $exec /usr/bin/gunicorn --access-logfile - --debug --max-requests 100 --graceful-timeout 3600 -t 3600 -k gevent -b ${REGISTRY_ADDRESS}:${REGISTRY_PORT} -w $GUNICORN_WORKERS wsgi:application &>> $logfile &
+ pid=$!
+ echo $pid > $pidfile
+ touch $lockfile
+ success
+ echo
+ else
+ failure
+ echo
+ printf "$pidfile still exists...\n"
+ exit 7
+ fi
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc -p $pidfile $prog
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ restart
+}
+
+force_reload() {
+ restart
+}
+
+rh_status() {
+ status -p $pidfile $prog
+}
+
+rh_status_q() {
+ rh_status >/dev/null 2>&1
+}
+
+case "$1" in
+ start)
+ rh_status_q && exit 0
+ $1
+ ;;
+ stop)
+ rh_status_q || exit 0
+ $1
+ ;;
+ restart)
+ $1
+ ;;
+ reload)
+ rh_status_q || exit 7
+ $1
+ ;;
+ force-reload)
+ force_reload
+ ;;
+ status)
+ rh_status
+ ;;
+ condrestart|try-restart)
+ rh_status_q || exit 0
+ restart
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ exit 2
+esac
+
+exit $?
More information about the scm-commits
mailing list