Skip to content

Commit

Permalink
fix: Added option to run image with unoserver in non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jimisola committed Feb 11, 2024
1 parent 63ccec4 commit 9a58257
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ RUN rm -rf /var/cache/apk/* /tmp/*
RUN pip install --break-system-packages -U unoserver==${VERSION_UNOSERVER}

# setup supervisor
COPY --chown=${UID}:${GID} ${BUILD_CONTEXT}/supervisor /
RUN chmod +x /config/entrypoint.sh && \
COPY --chown=${UID}:${GID} ${BUILD_CONTEXT} /
RUN chmod +x entrypoint.sh && \
# mkdir -p /var/log/supervisor && \
# chown ${UID}:${GID} /var/log/supervisor && \
# mkdir -p /var/run && \
chown -R ${UID}:0 /run && \
chmod -R g=u /run

RUN tree

USER ${UID}
WORKDIR /home/worker
ENV HOME="/home/worker"

VOLUME ["/data"]
EXPOSE 2002
EXPOSE 2003
ENTRYPOINT ["entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
47 changes: 47 additions & 0 deletions build-context/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e -u

# Function to wait for unoserver to start
wait_for_unoserver() {
echo "Waiting for unoserver to start ..."
while [ -z "$(netstat -tln | grep 2002)" ]; do
sleep 1
done
echo "unoserver started."
echo "using: $(libreoffice --version)"
}

export PS1='\u@\h:\w\$ '

# default parameters for supervisord
export SUPERVISOR_INTERACTIVE_CONF='/supervisor/conf/interactive/supervisord.conf'
export SUPERVISOR_NON_INTERACTIVE_CONF='/supervisor/conf/non_interactive/supervisord.conf'
export UNIX_HTTP_SERVER_PASSWORD=${UNIX_HTTP_SERVER_PASSWORD:-$(cat /proc/sys/kernel/random/uuid)}

echo "using: $(libreoffice --version)"

# if tty then assume that container is interactive
if [ ! -t 0 ]; then
echo "Running unoserver-docker in non-interactive."
echo "For interactive mode use '-it', e.g. 'docker run -v /tmp:/data -it unoserver/unoserver-docker'."

# run supervisord in foreground
supervisord -c "$SUPERVISOR_NON_INTERACTIVE_CONF"
else
echo "Running unoserver-docker in interactive mode."
echo "For non-interactive mode omit '-it', e.g. 'docker run -p 2002-2003:2002-2003 unoserver/unoserver-docker'."


# run supervisord as detached
supervisord -c "$SUPERVISOR_INTERACTIVE_CONF"

# wait until unoserver started and listens on port 2002.
wait_for_unoserver

# if commands have been passed to container run them and exit, else start bash
if [[ $# -gt 0 ]]; then
eval "$@"
else
/bin/bash
fi
fi
41 changes: 41 additions & 0 deletions build-context/supervisor/conf/non_interactive/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[supervisord]
pidfile = /var/run/supervisord.pid
nodaemon=true

# Note that at log level debug, the supervisord log file will record the stderr/stdout output
# of its child processes and extended info info about process state changes,
# which is useful for debugging a process which isn’t starting properly.
# and also makes it available using `docker logs [container]`
#logfile = /var/log/supervisor/supervisord.log
logfile = /dev/stdout
logfile_maxbytes = 0
loglevel = info

# needed for supervisor to work
[unix_http_server]
file = /var/run/supervisor.sock
chmod = 0700
username = admin
password = %(ENV_UNIX_HTTP_SERVER_PASSWORD)s

# needed for supervisor to work
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

# [inet_http_server]
# port = 127.0.0.1:9001
# username = admin
# password = %(ENV_INET_HTTP_SERVER_PASSWORD)

[supervisorctl]
serverurl = unix:///var/run/supervisor.sock

[program:unoserver]
command = unoserver
autorestart=true

#stdout_logfile = /var/log/supervisor/%(program_name)s.log
stdout_logfile = /dev/stdout
stderr_logfile = /dev/stderr
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0

0 comments on commit 9a58257

Please sign in to comment.