diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b30021 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mssql-data diff --git a/README.md b/README.md index 6c52525..ed865b2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,30 @@ Code contributions from others are welcome, although the creators retain the rig ## Installation +The server, client and database can be easily ran in Docker: + +- Install [Docker](https://docker.com/) and docker-compose (generally included in a docker installation) +- Clone the repository +- Run: `docker compose build frontend backend` +- Run: `docker compose up -d` +- Access the game frontend at http://localhost:5173 + +Database files will be stored in `mssql-data` directory. + +To read the server logs, run `docker compose logs -f backend`. + +To update the code in the future, run these commands: +``` +docker compose down -rmi +git pull +docker compose build frontend backend +docker compose up -d +``` + +If you cannot use Docker or would like a development setup, follow the instructions below. + +## Development setup + The two components - found in the `server` and `client` directories - may be run together or independently. The client always requires a server instance (local or remote) for the game to function beyond the welcome and setup screens. The `prototype` directory contains the original proof of concept from 2021. None of its contents are required for running the latest version of 5D Diplomacy. diff --git a/client/Caddyfile b/client/Caddyfile new file mode 100644 index 0000000..1eb2a30 --- /dev/null +++ b/client/Caddyfile @@ -0,0 +1,8 @@ +http://:8080 { + file_server /* { + root /dist + } + handle_path /api/* { + reverse_proxy http://backend:8080 + } +} diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..9d223de --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine:latest AS builder + +RUN apk add nodejs yarn + +WORKDIR /app +COPY . . + +RUN yarn +RUN VITE_SERVER_URL=/api yarn build + +FROM alpine:latest + +RUN apk add caddy +COPY Caddyfile /etc/Caddyfile + +COPY --from=builder /app/dist /dist + +ENTRYPOINT [ "caddy", "run", "-c", "/etc/Caddyfile" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e80af79 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + frontend: + build: client/ + ports: + - 127.0.0.1:5173:8080 + restart: always + backend: + build: server/ + environment: + - "ConnectionStrings__Database=Server=mssql;Database=diplomacy;User=SA;Password=Passw0rd@;Encrypt=True;TrustServerCertificate=True" + restart: always + mssql: + image: mcr.microsoft.com/mssql/server:2022-latest + user: root + environment: + - ACCEPT_EULA=y + - "MSSQL_SA_PASSWORD=Passw0rd@" + volumes: + - './mssql-data/data:/var/opt/mssql/data' + - './mssql-data/log:/var/opt/mssql/log' + - './mssql-data/secrets:/var/opt/mssql/secrets' diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1 @@ +bin/ diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..be1f596 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +WORKDIR /app + +COPY . /app +RUN dotnet build -c Release -o bin + +RUN dotnet tool install --global dotnet-ef + +CMD ["/app/docker-entrypoint.sh"] diff --git a/server/Program.cs b/server/Program.cs index 6df3d5e..34cb194 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -31,7 +31,6 @@ .AllowAnyMethod()); } -app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); diff --git a/server/appsettings.json b/server/appsettings.json index dedfabe..6e26f48 100644 --- a/server/appsettings.json +++ b/server/appsettings.json @@ -2,7 +2,6 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" } }, "ConnectionStrings": { diff --git a/server/docker-entrypoint.sh b/server/docker-entrypoint.sh new file mode 100755 index 0000000..d917858 --- /dev/null +++ b/server/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +~/.dotnet/tools/dotnet-ef database update + +dotnet /app/bin/5dDiplomacyWithMultiverseTimeTravel.dll