Skip to content

Commit

Permalink
feat: changed base docker base image to dotnet-alpine (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
claitz authored Jul 8, 2024
2 parents 2cfe14b + cccf3e0 commit 43f6a4d
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 53 deletions.
1 change: 1 addition & 0 deletions CoreDatabase/CoreDatabase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions CoreServer/CoreServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
Expand Down
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,51 @@ WORKDIR /build
# Copy the source code to the build container
COPY . .

# Install required tools: unzip, git, and the text processing utilities we might need
# Install required tools and clone the database repository
RUN apt-get update && \
apt-get install -y unzip git sed

# Clone the database repository
RUN git config --global http.sslVerify false
RUN git clone https://github.com/OpenDAoC/OpenDAoC-Database.git /tmp/opendaoc-db
apt-get install -y unzip git sed && \
git config --global http.sslVerify false && \
git clone https://github.com/OpenDAoC/OpenDAoC-Database.git /tmp/opendaoc-db && \
rm -rf /var/lib/apt/lists/*

# Combine the SQL files
WORKDIR /tmp/opendaoc-db/opendaoc-db-core
RUN cat *.sql > combined.sql

# Restore NuGet packages
# Set the working directory back to the build container
WORKDIR /build
RUN dotnet restore DOLLinux.sln

# Copy serverconfig.example.xml to serverconfig.xml
RUN cp /build/CoreServer/config/serverconfig.example.xml /build/CoreServer/config/serverconfig.xml

# Build the application in Release mode
RUN dotnet build DOLLinux.sln -c Release

# Use the official .NET 8.0 Runtime image as the base for the final image
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
# ---- final ----
# Use the official .NET 8.0 Alpine Runtime image as the base for the final image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
LABEL stage=final

# Install a few packages useful for debugging
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y mariadb-client iproute2
# Copy gosu
COPY --from=tianon/gosu /gosu /usr/local/bin/

## Install ICU libraries
RUN apk add --no-cache icu-libs

# Set the working directory in the container
WORKDIR /app

# Copy the build output from the build stage
COPY --from=build /build/Release .
COPY --from=build /build/Release /app

# Copy the combined.sql file from the build stage
COPY --from=build /tmp/opendaoc-db/opendaoc-db-core/combined.sql /tmp/opendaoc-db/combined.sql

# Copy the entrypoint script
COPY --from=build /build/entrypoint.sh /app

# Make the entrypoint script executable
RUN chmod +x /app/entrypoint.sh

# Set the entrypoint
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]
66 changes: 33 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
version: "3.3"

networks:
networks:
opendaoc-network:
driver: bridge

volumes:
opendaoc-db-data:
base-db:

services:
db:
image: mariadb:10.6
stdin_open: true # docker run -i
tty: true # docker run -t
container_name: opendaoc-db
stdin_open: true
tty: true
command: --default-authentication-plugin=mysql_native_password --lower_case_table_names=1 --character-set-server=utf8mb3 --collation-server=utf8mb3_general_ci --innodb_large_prefix=1 --innodb_file_format=Barracuda --innodb_file_per_table=1
restart: always
environment:
Expand All @@ -21,46 +24,43 @@ services:
- opendaoc-network

gameserver:
stdin_open: true # docker run -i
tty: true # docker run -t
image: ghcr.io/opendaoc/opendaoc-core/opendaoc:latest
image: ghcr.io/opendaoc/opendaoc-core:latest
container_name: opendaoc-server
stdin_open: true
tty: true
ports:
- "10300:10300"
- "10400:10400"
depends_on:
- db
environment:
UID: "1000"
GID: "1000"
AUTO_ACCOUNT_CREATION: "True"
CHEAT_LOGGER_NAME: "cheats"
CPU_USE: "8"
DB_AUTOSAVE: "True"
DB_AUTOSAVE_INTERVAL: "10"
DB_CONNECTION_STRING: "server=db;port=3306;database=opendaoc;userid=root;password=my-secret-pw;treattinyasboolean=true"
SERVER_PORT: "10300"
SERVER_IP: "0.0.0.0"
REGION_IP: "0.0.0.0"
REGION_PORT: "10400"
UDP_IP: "0.0.0.0"
UDP_PORT: "10400"
ENABLE_UPNP: "False"
DB_TYPE: "MYSQL"
DETECT_REGION_IP: "True"
SERVER_NAME: "OpenDAoC"
SERVER_NAME_SHORT: "OPENDAOC"
LOG_CONFIG_FILE: "./config/logconfig.xml"
SCRIPT_COMPILATION_TARGET: "./lib/GameServerScripts.dll"
SCRIPT_ASSEMBLIES: ""
ENABLE_COMPILATION: "True"
AUTO_ACCOUNT_CREATION: "True"
ENABLE_UPNP: "False"
GAME_TYPE: "Normal"
CHEAT_LOGGER_NAME: "cheats"
GM_ACTION_LOGGER_NAME: "gmactions"
INVALID_NAMES_FILE: "./config/invalidnames.txt"
DB_TYPE: "MYSQL"
DB_AUTOSAVE: "True"
DB_AUTOSAVE_INTERVAL: "10"
CPU_USE: "8"

LOG_CONFIG_FILE: "./config/logconfig.xml"
REGION_IP: "0.0.0.0"
REGION_PORT: "10400"
SCRIPT_ASSEMBLIES: ""
SCRIPT_COMPILATION_TARGET: "./lib/GameServerScripts.dll"
SERVER_IP: "0.0.0.0"
SERVER_NAME: "OpenDAoC"
SERVER_NAME_SHORT: "OPENDAOC"
SERVER_PORT: "10300"
UDP_IP: "0.0.0.0"
UDP_PORT: "10400"
volumes:
- base-db:/tmp/opendaoc-db

networks:
- opendaoc-network

volumes:
opendaoc-db-data:
base-db:
- opendaoc-network
40 changes: 36 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#!/bin/bash
#!/bin/sh

# Delete the existing serverconfig.xml and create it from scratch
# Default values for UID and GID if not provided
APP_UID=${UID:-1000}
APP_GID=${GID:-1000}

# Check if running as root
if [ "$(id -u)" != "0" ]; then
>&2 echo "ERROR: Not running as root. Please run as root, and pass HOST_UID and HOST_GID."
exit 120
elif [ "${APP_UID}" = "" ]; then
>&2 echo "ERROR: HOST_UID is not set. Please run as root, and pass HOST_UID and HOST_GID."
exit 121
elif [ "${APP_GID}" = "" ]; then
>&2 echo "ERROR: HOST_GID is not set. Please run as root, and pass HOST_UID and HOST_GID."
exit 122
fi

# Handle existing group with the same GID
EXISTING_GROUP_NAME=$(getent group "${APP_GID}" | cut -d: -f1)
if [ "${EXISTING_GROUP_NAME}" != "" ]; then
delgroup "${EXISTING_GROUP_NAME}"
fi

# (Re)create the group 'appgroup'
delgroup appgroup 2>/dev/null || true
addgroup -g "${APP_GID}" appgroup

# (Re)create the user 'appuser'
deluser appuser 2>/dev/null || true
adduser -D -H -u "${APP_UID}" -G appgroup appuser

# Delete the existing serverconfig.xml
rm -f /app/config/serverconfig.xml

# Create serverconfig.xml with environment variables
Expand Down Expand Up @@ -36,6 +66,8 @@ cat << EOF > /app/config/serverconfig.xml
</root>
EOF

# Start the AtlasCore application
cd /app && exec dotnet CoreServer.dll
# Change ownership of the /app directory
chown -R appuser:appgroup /app

# Switch to the non-root user and start the server
exec gosu appuser sh -c "cd /app && exec dotnet CoreServer.dll"

0 comments on commit 43f6a4d

Please sign in to comment.