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..a41c0d2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,32 @@ 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 + +You may have to wait a few seconds after the `docker compose up -d` command before the server is ready, while the database is being set up. + +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 local +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..dcb7fbd --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,15 @@ +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 + +RUN echo "#!/bin/sh" >> /app/docker-entrypoint.sh \ + && echo "~/.dotnet/tools/dotnet-ef database update" >> /app/docker-entrypoint.sh \ + && echo "dotnet /app/bin/5dDiplomacyWithMultiverseTimeTravel.dll" >> /app/docker-entrypoint.sh \ + && chmod +x /app/docker-entrypoint.sh + +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();