From 590a7829b1a055b9c55131873875e4859d56f2c3 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:22:26 +1000 Subject: [PATCH] Another attempt at fixing the Embedded DB Docker image (#388) --- build/Dockerfile-EmbeddedDB | 46 +++++++++++++++++-------------------- build/entrypoint.sh | 12 ++++++++++ build/mariadb.sh | 6 ++--- build/supervisord.conf | 24 ++++++++++++++----- 4 files changed, 54 insertions(+), 34 deletions(-) create mode 100644 build/entrypoint.sh diff --git a/build/Dockerfile-EmbeddedDB b/build/Dockerfile-EmbeddedDB index cd2f4a1..ac68b24 100644 --- a/build/Dockerfile-EmbeddedDB +++ b/build/Dockerfile-EmbeddedDB @@ -23,6 +23,7 @@ RUN dotnet publish "gaseous-server/gaseous-server.csproj" --use-current-runtime # RUN mkdir -p out/wwwroot/emulators/EmulatorJS # RUN wget https://cdn.emulatorjs.org/releases/4.0.12.7z # RUN 7z x -y -oout/wwwroot/emulators/EmulatorJS 4.0.12.7z + RUN wget --recursive --no-parent https://cdn.emulatorjs.org/latest/ RUN mkdir -p out/wwwroot/emulators/EmulatorJS RUN cp -fr cdn.emulatorjs.org/latest/* out/wwwroot/emulators/EmulatorJS @@ -35,10 +36,19 @@ WORKDIR /App COPY --from=build-env /App/out . # variables -ENV dbhost=localhost -ENV dbuser=root -ENV dbpass=gaseous -ENV MARIADB_ROOT_PASSWORD=$dbpass +ARG PUID=1000 +ARG PGID=1000 +ARG dbhost=localhost +ARG dbuser=root +ARG dbpass=gaseous +ARG MARIADB_ROOT_PASSWORD=$dbpass + +ENV PUID=${PUID} +ENV PGID=${PGID} +ENV dbhost=${dbhost} +ENV dbuser=${dbuser} +ENV dbpass=${dbpass} +ENV MARIADB_ROOT_PASSWORD=${dbpass} # install mariadb RUN DEBIAN_FRONTEND=noninteractive && \ @@ -50,32 +60,18 @@ RUN chmod +x /usr/sbin/start-mariadb.sh # install supervisord RUN apt-get install -y supervisor COPY ../build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +RUN mkdir -p /var/run/supervisord +RUN mkdir -p /var/log/supervisord # clean up apt-get RUN apt-get clean && rm -rf /var/lib/apt/lists -# set user name -ENV USER=gaseous -ENV GROUP=gaseous - -# configure user -ENV PUID=1000 -ENV PGID=1000 -RUN groupadd -g $PGID $USER -RUN useradd -u $PUID -g $GROUP -m $USER -G sudo -RUN usermod -p "*" $USER - -# create home directory -RUN mkdir -p /home/$USER/.gaseous-server /var/lib/mysql - -# set permissions -RUN chown -R $USER:$GROUP /App /home/$USER/.gaseous-server /var/lib/mysql /run/mysqld - -# switch to user -USER $USER +# copy entrypoint +COPY ../build/entrypoint.sh /usr/sbin/entrypoint.sh +RUN chmod +x /usr/sbin/entrypoint.sh # volumes -VOLUME /home/$USER/.gaseous-server /var/lib/mysql +VOLUME /home/gaseous/.gaseous-server /var/lib/mysql # start services -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +ENTRYPOINT [ "/usr/sbin/entrypoint.sh" ] diff --git a/build/entrypoint.sh b/build/entrypoint.sh new file mode 100644 index 0000000..7e2f381 --- /dev/null +++ b/build/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# create the user +echo "Creating user gaseous with UID ${PUID} and GID ${PGID}" +groupadd -g ${PGID} gaseous +useradd -u ${PUID} -g ${PGID} -m gaseous -G sudo +usermod -p "*" gaseous +mkdir -p /home/gaseous/.gaseous-server /var/lib/mysql +chown -R ${PUID}:${PGID} /App /home/gaseous/.gaseous-server /var/lib/mysql /run/mysqld + +# Start supervisord and services +/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf diff --git a/build/mariadb.sh b/build/mariadb.sh index 5db51b7..1088c90 100644 --- a/build/mariadb.sh +++ b/build/mariadb.sh @@ -1,16 +1,16 @@ -#!/bin/bash +#!/bin/sh # start the database server without network or grant tables /usr/sbin/mariadbd --datadir=/var/lib/mysql --skip-grant-tables --skip-networking & # wait for the server to start -sleep 2 +sleep 5 # change the root password mariadb -u root -e "FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY '$MARIADB_ROOT_PASSWORD'; FLUSH PRIVILEGES;" # stop the server -sleep 1 +sleep 5 killall mariadbd # start the server normally diff --git a/build/supervisord.conf b/build/supervisord.conf index acf9971..9ccc04b 100644 --- a/build/supervisord.conf +++ b/build/supervisord.conf @@ -1,12 +1,23 @@ [supervisord] -# user=abc nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/var/run/supervisord.pid -loglevel = INFO +logfile=/var/log/supervisord/supervisord.log +logfile_maxbytes=50 +logfile_backups=5 +pidfile=/var/run/supervisord/supervisord.pid +loglevel = info + +[unix_http_server] +file=/var/run/supervisord/supervisor.sock +chmod=0700 + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///var/run/supervisord/supervisor.sock [program:mariadb] +user=gaseous command=bash -c "/usr/sbin/start-mariadb.sh" autostart=true autorestart=true @@ -15,9 +26,10 @@ stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0 [program:gaseous-server] +user=gaseous command=dotnet /App/gaseous-server.dll autostart=true autorestart=true redirect_stderr=true stdout_logfile=/dev/fd/1 -stdout_logfile_maxbytes=0 \ No newline at end of file +stdout_logfile_maxbytes=0