Skip to content

Commit

Permalink
Add Docker build files and instructions (#13)
Browse files Browse the repository at this point in the history
* Add Docker build files and instructions

* pr reviews

---------

Co-authored-by: violet <avioletheart@localhost>
Co-authored-by: Oliveriver <oliveriver1@gmail.com>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent 0504ea7 commit 1fc2338
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mssql-data
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions client/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
http://:8080 {
file_server /* {
root /dist
}
handle_path /api/* {
reverse_proxy http://backend:8080
}
}
18 changes: 18 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
15 changes: 15 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
.AllowAnyMethod());
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

0 comments on commit 1fc2338

Please sign in to comment.