diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..a81c05fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# Directories +**/bin +**/obj +**/out +**/TestResults +**/.vs +**/.vscode +.git +.github +.gitignore +.gitmodules + +# Files +**/*.md +**/*.log +**/*.user +**/*.suo +**/*.userprefs +**/.DS_Store +**/Thumbs.db + +# Exclude non-C# language folders +cpp/ +python/ +rust/ +Settings/ + +# Keep only necessary files for build +!csharp/ +!Dockerfile +!docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..874c6c3f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Use the .NET 6 SDK for building +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /app + +# Copy solution and project files +COPY csharp/Platform.Data.Doublets.Gql.sln ./ +COPY csharp/Platform.Data.Doublets.Gql.Schema/Platform.Data.Doublets.Gql.Schema.csproj ./Platform.Data.Doublets.Gql.Schema/ +COPY csharp/Platform.Data.Doublets.Gql.Server/Platform.Data.Doublets.Gql.Server.csproj ./Platform.Data.Doublets.Gql.Server/ +COPY csharp/Platform.Data.Doublets.Gql.Tests/Platform.Data.Doublets.Gql.Tests.csproj ./Platform.Data.Doublets.Gql.Tests/ + +# Restore packages +RUN dotnet restore + +# Copy source code +COPY csharp/ ./ + +# Build and publish the application +RUN dotnet publish Platform.Data.Doublets.Gql.Server/Platform.Data.Doublets.Gql.Server.csproj -c Release -o out --no-restore + +# Use the .NET 6 runtime for the final image +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime +WORKDIR /app + +# Copy the published application +COPY --from=build /app/out . + +# Create directory for database files +RUN mkdir -p /app/data + +# Set environment variables +ENV ASPNETCORE_URLS=http://+:80 +ENV ASPNETCORE_ENVIRONMENT=Production + +# Expose port 80 +EXPOSE 80 + +# Run the application with the database path in the data volume +ENTRYPOINT ["dotnet", "Platform.Data.Doublets.Gql.Server.dll", "/app/data/db.links"] \ No newline at end of file diff --git a/README.md b/README.md index 889bd58f..6b0cd488 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,32 @@ http://linksplatform.ddns.net:29018/v1/graphql ## Start locally +### Option 1: Using Docker (Recommended) + +The easiest way to run the GQL server is using Docker: + +```bash +# Build and run with docker-compose +docker-compose up -d + +# Or build and run manually +docker build -t doublets-gql . +docker run -p 29018:80 -v $(pwd)/data:/app/data doublets-gql +``` + +Navigate to: +* http://localhost:29018/ui/playground +* http://localhost:29018/ui/graphiql +* http://localhost:29018/ui/altair +* http://localhost:29018/ui/voyager + +Or make request at: +http://localhost:29018/v1/graphql + +The database file will be stored in the `./data` directory on your host machine. + +### Option 2: Using .NET directly + Execute: ``` cd csharp/Platform.Data.Doublets.Gql.Server diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..df7db3bd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.8' + +services: + gql-server: + build: . + ports: + - "29018:80" + volumes: + - ./data:/app/data + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://+:80 + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:80/ui/playground"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s \ No newline at end of file