diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b319d8fb --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/data diff --git a/.gitignore b/.gitignore index c7f26cda..98acbbd6 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,4 @@ BACKUP* backup* *.tmp -*.bin \ No newline at end of file +*.bin diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ef5f2025 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# Build stage +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +WORKDIR /ProjectLighthouse +COPY *.sln ./ +COPY **/*.csproj ./ + +RUN dotnet sln list | grep ".csproj" \ + | while read -r line; do \ + mkdir -p $(dirname $line); \ + mv $(basename $line) $(dirname $line); \ + done; + +RUN dotnet restore + +COPY . . +RUN dotnet publish -c Release -o /ProjectLighthouse/publish --no-restore + +# Final running container +FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS final + +# Add non-root user +RUN addgroup -S lighthouse --gid 1001 && \ +adduser -S lighthouse -G lighthouse -h /lighthouse --uid 1001 && \ +mkdir -p /lighthouse/data && \ +mkdir -p /lighthouse/app && \ +mkdir -p /lighthouse/temp && \ +apk add --no-cache icu-libs su-exec + +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false + +# Copy build files +COPY --from=build /ProjectLighthouse/publish /lighthouse/app +COPY --from=build /ProjectLighthouse/ProjectLighthouse/StaticFiles /lighthouse/temp/StaticFiles +COPY --from=build /ProjectLighthouse/scripts-and-tools/docker-entrypoint.sh /lighthouse + +RUN chown -R lighthouse:lighthouse /lighthouse && \ +chmod +x /lighthouse/docker-entrypoint.sh && \ +cp /lighthouse/app/appsettings.json /lighthouse/temp + +ENTRYPOINT ["/lighthouse/docker-entrypoint.sh"] diff --git a/ProjectLighthouse/.dockerignore b/ProjectLighthouse/.dockerignore deleted file mode 100644 index cd967fc3..00000000 --- a/ProjectLighthouse/.dockerignore +++ /dev/null @@ -1,25 +0,0 @@ -**/.dockerignore -**/.env -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/.idea -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/azds.yaml -**/bin -**/charts -**/docker-compose* -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -LICENSE -README.md \ No newline at end of file diff --git a/ProjectLighthouse/Dockerfile b/ProjectLighthouse/Dockerfile deleted file mode 100644 index cd416564..00000000 --- a/ProjectLighthouse/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base -WORKDIR /app -EXPOSE 10060 - -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build -WORKDIR /src -COPY ["ProjectLighthouse/ProjectLighthouse.csproj", "ProjectLighthouse/"] -RUN dotnet restore "ProjectLighthouse/ProjectLighthouse.csproj" -COPY . . -WORKDIR "/src/ProjectLighthouse" -RUN dotnet build "ProjectLighthouse.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "ProjectLighthouse.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "ProjectLighthouse.dll"] diff --git a/docker-compose.yml b/docker-compose.yml index e35dd091..d84ba34d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,90 @@ -# MySQL Docker compose file for development purposes. DO NOT USE IN PRODUCTION! - version: '3' - -services: - lighthouse-db: - image: mysql - environment: - MYSQL_DATABASE: 'lighthouse' - MYSQL_ROOT_PASSWORD: 'lighthouse' - ports: - - '3306:3306' - expose: - - '3306' # Expose port to localhost:3306 - volumes: - - lighthouse-db:/var/lib/mysql - lighthouse-redis: - image: redis/redis-stack - ports: - - '6379:6379' - - '8001:8001' - expose: - - '6379' - - '8001' - - volumes: - lighthouse-db: \ No newline at end of file + database: + redis: +services: + gameserver: + image: lighthouse:latest + container_name: gameserver + build: . + restart: unless-stopped + ports: + - "10061:10061" + environment: + SERVER: GameServer + healthcheck: + test: wget --spider -t1 -nv http://localhost:10061/LITTLEBIGPLANETPS3_XML/status || exit 1 + timeout: 10s + retries: 5 + depends_on: + db: + condition: service_healthy + redis: + condition: service_started + volumes: + - "./data:/lighthouse/data:z" + website: + image: lighthouse:latest + container_name: website + restart: unless-stopped + ports: + - "10060:10060" + environment: + SERVER: Website + healthcheck: + test: wget --spider -t1 -nv http://localhost:10060/status || exit 1 + timeout: 10s + retries: 5 + depends_on: + db: + condition: service_started + redis: + condition: service_started + gameserver: + condition: service_healthy + volumes: + - "./data:/lighthouse/data:z" + api: + image: lighthouse:latest + container_name: api + restart: unless-stopped + ports: + - "10062:10062" + environment: + SERVER: API + healthcheck: + test: wget --spider -t1 -nv http://localhost:10062/api/v1/status || exit 1 + timeout: 10s + retries: 5 + depends_on: + db: + condition: service_started + redis: + condition: service_started + gameserver: + condition: service_healthy + volumes: + - "./data:/lighthouse/data:z" + db: + image: mariadb + container_name: db + restart: unless-stopped + ports: + - "3306:3306" + environment: + MARIADB_ROOT_PASSWORD: lighthouse + MARIADB_DATABASE: lighthouse + healthcheck: + test: "/usr/bin/mysql --user=root --password=lighthouse --execute \"SHOW DATABASES;\"" + timeout: 20s + retries: 10 + volumes: + - "database:/var/lib/mysql" + redis: + image: redis/redis-stack-server + container_name: redis + restart: unless-stopped + ports: + - "6379:6379" + volumes: + - "redis:/var/lib/redis" diff --git a/scripts-and-tools/docker-entrypoint.sh b/scripts-and-tools/docker-entrypoint.sh new file mode 100644 index 00000000..48bab418 --- /dev/null +++ b/scripts-and-tools/docker-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +chown -R lighthouse:lighthouse /lighthouse/data + +if [ -d "/lighthouse/temp" ]; then + cp -rf /lighthouse/temp/* /lighthouse/data + rm -rf /lighthouse/temp +fi + +# run from cmd + +cd /lighthouse/data +exec su-exec lighthouse:lighthouse dotnet /lighthouse/app/LBPUnion.ProjectLighthouse.Servers."$SERVER".dll + +exit $? # Expose error code from dotnet command