diff --git a/Dockerfile b/build/Dockerfile similarity index 83% rename from Dockerfile rename to build/Dockerfile index c78760b..da95263 100644 --- a/Dockerfile +++ b/build/Dockerfile @@ -8,21 +8,29 @@ RUN echo "Target: $TARGETARCH" RUN echo "Build: $BUILDPLATFORM" # Copy everything -COPY . ./ +COPY .. ./ # Restore as distinct layers 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 +# update apt-get +RUN apt-get update + # download and unzip EmulatorJS from CDN -RUN apt-get update && apt-get install -y p7zip-full +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 +# clean up apt-get +RUN apt-get clean && rm -rf /var/lib/apt/lists + # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:8.0 ENV INDOCKER=1 WORKDIR /App COPY --from=build-env /App/out . + +# start gaseous-server ENTRYPOINT ["dotnet", "gaseous-server.dll"] diff --git a/build/Dockerfile-EmbeddedDB b/build/Dockerfile-EmbeddedDB new file mode 100644 index 0000000..d6b5180 --- /dev/null +++ b/build/Dockerfile-EmbeddedDB @@ -0,0 +1,56 @@ +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env +ARG TARGETARCH +ARG BUILDPLATFORM +WORKDIR /App +EXPOSE 80 + +RUN echo "Target: $TARGETARCH" +RUN echo "Build: $BUILDPLATFORM" + +# Copy everything +COPY .. ./ +# Restore as distinct layers +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 + +# 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 + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +ENV INDOCKER=1 +WORKDIR /App +COPY --from=build-env /App/out . + +# variables +ENV dbhost=localhost +ENV dbuser=root +ENV dbpass=gaseous +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 +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 + +# clean up apt-get +RUN apt-get clean && rm -rf /var/lib/apt/lists + +# volumes +VOLUME /root/.gaseous-server /var/lib/mysql + +# start services +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/build/mariadb.sh b/build/mariadb.sh new file mode 100644 index 0000000..9851661 --- /dev/null +++ b/build/mariadb.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Wait for the service to start +while ! mysqladmin ping -h localhost --silent; do + sleep 1 +done + +# Set the root password +mariadb -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$MARIADB_ROOT_PASSWORD';" \ No newline at end of file diff --git a/build/supervisord.conf b/build/supervisord.conf new file mode 100644 index 0000000..533b4c6 --- /dev/null +++ b/build/supervisord.conf @@ -0,0 +1,31 @@ +[supervisord] +user=root +nodaemon=true +logfile=/dev/null +logfile_maxbytes=0 +pidfile=/var/run/supervisord.pid +loglevel = INFO + +[program:mariadb] +command=/usr/sbin/mariadbd --user=root +autostart=true +autorestart=true +redirect_stderr=true +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 + +[program:mariadb-setup] +command=bash -c "/usr/sbin/start-mariadb.sh" +autostart=true +autorestart=false +redirect_stderr=true +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 + +[program:gaseous-server] +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