Skip to content

Commit

Permalink
All images now support rootless (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Sep 7, 2024
1 parent f0783fc commit 7dfb0b5
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 159 deletions.
48 changes: 36 additions & 12 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ RUN dotnet restore "gaseous-server/gaseous-server.csproj" -a $TARGETARCH
# Build and publish a release
RUN dotnet publish "gaseous-server/gaseous-server.csproj" --use-current-runtime --self-contained true -c Release -o out -a $TARGETARCH

# disabled for 1.7.4 as the next version EmulatorJS is not yet available
# # update apt-get
# RUN apt-get update
# update apt-get
RUN apt-get update

# # download and unzip EmulatorJS from CDN
# RUN apt-get install -y p7zip-full
# 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 apt-get install -y p7zip-full
RUN mkdir -p out/wwwroot/emulators/EmulatorJS
RUN cp -fr cdn.emulatorjs.org/latest/* out/wwwroot/emulators/EmulatorJS
RUN rm -Rf cdn.emulatorjs.org
RUN wget https://cdn.emulatorjs.org/releases/4.0.12.7z
RUN 7z x -y -oout/wwwroot/emulators/EmulatorJS 4.0.12.7z

# clean up apt-get
RUN apt-get clean && rm -rf /var/lib/apt/lists
Expand All @@ -37,5 +32,34 @@ ENV INDOCKER=1
WORKDIR /App
COPY --from=build-env /App/out .

# start gaseous-server
ENTRYPOINT ["dotnet", "gaseous-server.dll"]
# variables
ARG PUID=1000
ARG PGID=1000
ARG dbhost=localhost
ARG dbuser=root
ARG dbpass=gaseous

ENV PUID=${PUID}
ENV PGID=${PGID}
ENV dbhost=${dbhost}
ENV dbuser=${dbuser}
ENV dbpass=${dbpass}

# install supervisord
RUN apt-get update && apt-get install -y supervisor
COPY ../build/standard/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

# copy entrypoint
COPY ../build/standard/entrypoint.sh /usr/sbin/entrypoint.sh
RUN chmod +x /usr/sbin/entrypoint.sh

# volumes
VOLUME /home/gaseous/.gaseous-server

# start services
ENTRYPOINT [ "/usr/sbin/entrypoint.sh" ]
46 changes: 28 additions & 18 deletions build/Dockerfile-EmbeddedDB
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ RUN dotnet restore "gaseous-server/gaseous-server.csproj" -a $TARGETARCH
# Build and publish a release
RUN dotnet publish "gaseous-server/gaseous-server.csproj" --use-current-runtime --self-contained true -c Release -o out -a $TARGETARCH

# disabled for 1.7.4 as the next version EmulatorJS is not yet available
# # update apt-get
# RUN apt-get update
# update apt-get
RUN apt-get update

# # download and unzip EmulatorJS from CDN
# RUN apt-get install -y p7zip-full
# 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 apt-get install -y p7zip-full
RUN mkdir -p out/wwwroot/emulators/EmulatorJS
RUN cp -fr cdn.emulatorjs.org/latest/* out/wwwroot/emulators/EmulatorJS
RUN rm -Rf cdn.emulatorjs.org
RUN wget https://cdn.emulatorjs.org/releases/4.0.12.7z
RUN 7z x -y -oout/wwwroot/emulators/EmulatorJS 4.0.12.7z

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
Expand All @@ -35,27 +30,42 @@ 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 && \
apt-get update && apt-get install -y mariadb-server
RUN mkdir -p /run/mysqld
COPY ../build/mariadb.sh /usr/sbin/start-mariadb.sh
COPY ../build/embeddeddb/mariadb.sh /usr/sbin/start-mariadb.sh
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
COPY ../build/embeddeddb/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

# copy entrypoint
COPY ../build/embeddeddb/entrypoint.sh /usr/sbin/entrypoint.sh
RUN chmod +x /usr/sbin/entrypoint.sh

# volumes
VOLUME /root/.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" ]
18 changes: 18 additions & 0 deletions build/embeddeddb/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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 -d /home/gaseous -G sudo
usermod -p "*" gaseous
mkdir -p /home/gaseous/.gaseous-server
chown -R ${PUID} /App /home/gaseous/.gaseous-server
chgrp -R ${PGID} /App /home/gaseous/.gaseous-server

# Set MariaDB permissions
mkdir -p /var/lib/mysql /var/log/mariadb /run/mysqld
chown -R ${PUID} /var/lib/mysql /var/log/mariadb /run/mysqld
chgrp -R ${PGID} /var/lib/mysql /var/log/mariadb /run/mysqld

# Start supervisord and services
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
25 changes: 25 additions & 0 deletions build/embeddeddb/mariadb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# install the database
echo "Installing MariaDB"
/usr/bin/mariadb-install-db --datadir=/var/lib/mysql --user=gaseous

# start the database server without network or grant tables
echo "Starting MariaDB"
/usr/sbin/mariadbd --datadir=/var/lib/mysql --skip-grant-tables --skip-networking &

# wait for the server to start
sleep 5

# change the root password
echo "Setting MariaDB root password"
mariadb -u root -e "FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY '$MARIADB_ROOT_PASSWORD'; ALTER USER 'gaseous'@'localhost' IDENTIFIED BY '$MARIADB_ROOT_PASSWORD'; FLUSH PRIVILEGES; SHUTDOWN;"

# stop the server
sleep 5
echo "Stopping MariaDB"
killall mariadbd

# start the server normally
echo "Starting MariaDB"
/usr/sbin/mariadbd --datadir=/var/lib/mysql --user=gaseous
37 changes: 37 additions & 0 deletions build/embeddeddb/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[supervisord]
user=root
nodaemon=true
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
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

[program:gaseous-server]
user=gaseous
command=dotnet /App/gaseous-server.dll
environment=HOME="/home/gaseous",USER="gaseous"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
9 changes: 0 additions & 9 deletions build/mariadb.sh

This file was deleted.

13 changes: 13 additions & 0 deletions build/standard/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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 -d /home/gaseous -G sudo
usermod -p "*" gaseous
mkdir -p /home/gaseous/.gaseous-server
chown -R ${PUID} /App /home/gaseous/.gaseous-server
chgrp -R ${PGID} /App /home/gaseous/.gaseous-server

# Start supervisord and services
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
28 changes: 28 additions & 0 deletions build/standard/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[supervisord]
user=root
nodaemon=true
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:gaseous-server]
user=gaseous
command=dotnet /App/gaseous-server.dll
environment=HOME="/home/gaseous",USER="gaseous"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
31 changes: 0 additions & 31 deletions build/supervisord.conf

This file was deleted.

3 changes: 2 additions & 1 deletion docker-compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
container_name: gaseous-server
build:
context: ./
dockerfile: ./build/Dockerfile
restart: unless-stopped
networks:
- gaseous
Expand All @@ -12,7 +13,7 @@ services:
ports:
- 5198:80
volumes:
- gs:/root/.gaseous-server
- gs:/home/gaseous/.gaseous-server
environment:
- TZ=Australia/Sydney
- dbhost=gsdb
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
ports:
- 5198:80
volumes:
- gs:/root/.gaseous-server
- gs:/home/gaseous/.gaseous-server
environment:
- TZ=Australia/Sydney
- dbhost=gsdb
Expand Down
12 changes: 6 additions & 6 deletions gaseous-server/Classes/DatabaseMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void PostUpgradeScript(int TargetSchemaVersion, Database.databaseT
db.ExecuteNonQuery(sql);
break;

case 1022:
case 1023:
// load country list
Logging.Log(Logging.LogType.Information, "Database Upgrade", "Adding country look up table contents");

Expand Down Expand Up @@ -151,10 +151,10 @@ public static void PostUpgradeScript(int TargetSchemaVersion, Database.databaseT
}

// this is a safe background task
BackgroundUpgradeTargetSchemaVersions.Add(1022);
BackgroundUpgradeTargetSchemaVersions.Add(1023);
break;

case 1023:
case 1024:
// create profiles for all existing users
sql = "SELECT * FROM Users;";
data = db.ExecuteCMD(sql);
Expand Down Expand Up @@ -197,8 +197,8 @@ public static void UpgradeScriptBackgroundTasks()
MySql_1002_MigrateMetadataVersion();
break;

case 1022:
MySql_1022_MigrateMetadataVersion();
case 1023:
MySql_1023_MigrateMetadataVersion();
break;
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ public static void MySql_1002_MigrateMetadataVersion()
}
}

public static void MySql_1022_MigrateMetadataVersion()
public static void MySql_1023_MigrateMetadataVersion()
{
FileSignature fileSignature = new FileSignature();

Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// kick off any delayed upgrade tasks
// run 1002 background updates in the background on every start
DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1002);
DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1022);
DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1023);
// start the task
ProcessQueue.QueueItem queueItem = new ProcessQueue.QueueItem(
ProcessQueue.QueueItemType.BackgroundDatabaseUpgrade,
Expand Down
Loading

0 comments on commit 7dfb0b5

Please sign in to comment.