Skip to content

Commit

Permalink
Another attempt at fixing the Embedded DB Docker image (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Jul 8, 2024
1 parent ae75fc1 commit 590a782
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
46 changes: 21 additions & 25 deletions build/Dockerfile-EmbeddedDB
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 && \
Expand All @@ -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" ]
12 changes: 12 additions & 0 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions build/mariadb.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 18 additions & 6 deletions build/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
stdout_logfile_maxbytes=0

0 comments on commit 590a782

Please sign in to comment.