mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-27 01:11:27 +00:00
Containerize Project Lighthouse (#582)
* Add lighthouse docker support * Update to NET 7.0 * Make docker copy git repository info * Add restart policy to compose file * Delete temp folder after copying to data * Only build the docker image once * Fix builds from being dirty * Add su-exec to final image * Run lighthouse as non root user * Add compose file to gitignore * Remove compose file from gitignore Co-authored-by: Dagg <daggintosh@outlook.com>
This commit is contained in:
parent
993d14d90a
commit
263bfb5b23
7 changed files with 145 additions and 71 deletions
1
.dockerignore
Normal file
1
.dockerignore
Normal file
|
@ -0,0 +1 @@
|
|||
**/data
|
40
Dockerfile
Normal file
40
Dockerfile
Normal file
|
@ -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"]
|
|
@ -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
|
|
@ -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"]
|
|
@ -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:
|
||||
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"
|
||||
|
|
15
scripts-and-tools/docker-entrypoint.sh
Normal file
15
scripts-and-tools/docker-entrypoint.sh
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue