From 611c909535819122ce4d9e7cc0206bc98b98f34a Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Wed, 28 Aug 2024 20:03:16 +0400 Subject: [PATCH 1/4] use a named pipe and --log-file to output logs --- .gitattributes | 5 +++++ Dockerfile | 3 ++- docker-entrypoint.sh | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 docker-entrypoint.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..951b138 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Force Unix style line endings for files that will be copied into the Docker image +*.sh text eol=lf + +# Auto detect text files and perform LF normalization on the rest +* text=auto diff --git a/Dockerfile b/Dockerfile index 5207be4..a9fe268 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM alpine:3.20.2 -CMD [ "/usr/bin/svnserve", "--daemon", "--foreground", "--root", "/var/opt/svn" ] +COPY docker-entrypoint.sh / +CMD [ "/docker-entrypoint.sh" ] EXPOSE 3690 HEALTHCHECK CMD netstat -ln | grep 3690 || exit 1 VOLUME [ "/var/opt/svn" ] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..d5ded25 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +# create a pipe for svnserve logs +rm -f /var/svn/svnlogs +mkfifo /var/svn/svnlogs + +# run the SVN service in the background +/usr/bin/svnserve --daemon --root /var/opt/svn --log-file=/var/svn/svnlogs & +# remember the PID of the SVN server +SVNSERVE_PID=$! + +# redirect svnserve logs to stdout +cat /var/svn/svnlogs + +# stop the SVN server running in the background +kill -s SIGTERM $SVNSERVE_PID From a2305cea5224f6ac3ee2acd639eb2991b47328a6 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Thu, 29 Aug 2024 15:45:29 +0400 Subject: [PATCH 2/4] reordered Docker layers define the entrypoint after installing dependencies, so the dependencies can be cached for subsequent builds --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9fe268..8739b00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,15 @@ FROM alpine:3.20.2 -COPY docker-entrypoint.sh / -CMD [ "/docker-entrypoint.sh" ] EXPOSE 3690 + HEALTHCHECK CMD netstat -ln | grep 3690 || exit 1 + VOLUME [ "/var/opt/svn" ] WORKDIR /var/opt/svn RUN apk add --no-cache \ subversion==1.14.3-r2 \ wget==1.24.5-r0 + +COPY docker-entrypoint.sh / +CMD [ "/docker-entrypoint.sh" ] From ce38cc835ea61a9b7a3944788b3916ac75929af0 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Thu, 29 Aug 2024 16:27:09 +0400 Subject: [PATCH 3/4] use trap to redirect SIGTERM Also replaced cat with a while to avoid creating a subshell. Together, this allows for proper handling of the SIGTERM signal when stopping the container. --- docker-entrypoint.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d5ded25..d08713f 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,12 +7,14 @@ rm -f /var/svn/svnlogs mkfifo /var/svn/svnlogs # run the SVN service in the background -/usr/bin/svnserve --daemon --root /var/opt/svn --log-file=/var/svn/svnlogs & +/usr/bin/svnserve --daemon --foreground --root /var/opt/svn --log-file=/var/svn/svnlogs & # remember the PID of the SVN server SVNSERVE_PID=$! -# redirect svnserve logs to stdout -cat /var/svn/svnlogs +# redirect SIGTERM to the SVN service +trap "kill -s SIGTERM $SVNSERVE_PID" SIGTERM -# stop the SVN server running in the background -kill -s SIGTERM $SVNSERVE_PID +# redirect svnserve logs to stdout +while read -r line < /var/svn/svnlogs; do + printf '%s\n' "$line" +done From 14d06d90d87d9b08949fb5b133f03ebb5ff96ce2 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Fri, 30 Aug 2024 16:47:50 +0400 Subject: [PATCH 4/4] replace CMD with ENTRYPOINT --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8739b00..f37240e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ RUN apk add --no-cache \ wget==1.24.5-r0 COPY docker-entrypoint.sh / -CMD [ "/docker-entrypoint.sh" ] +ENTRYPOINT docker-entrypoint.sh