Skip to content

Commit b582a86

Browse files
committed
Add Docker support with Dockerfile and docker-compose.yml; configure reverse proxy in Program.cs
1 parent 0cd3335 commit b582a86

4 files changed

Lines changed: 242 additions & 2 deletions

File tree

.dockerignore

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# .dockerignore for AutoComplete.Playground
2+
# Excludes unnecessary files from Docker build context
3+
4+
# Git
5+
.git/
6+
.gitignore
7+
.gitattributes
8+
9+
# Documentation
10+
*.md
11+
!README.md
12+
docs/
13+
CLAUDE.md
14+
15+
# IDE
16+
.vs/
17+
.vscode/
18+
.idea/
19+
*.suo
20+
*.user
21+
*.userosscache
22+
*.sln.docstates
23+
24+
# Build outputs
25+
**/bin/
26+
**/obj/
27+
**/out/
28+
**/publish/
29+
30+
# NuGet
31+
*.nupkg
32+
*.snupkg
33+
packages/
34+
.nuget/
35+
36+
# Test results
37+
TestResults/
38+
*.trx
39+
*.coverage
40+
*.coveragexml
41+
42+
# User-specific files
43+
*.rsuser
44+
*.suo
45+
*.user
46+
*.userosscache
47+
*.sln.docstates
48+
49+
# Mono auto generated files
50+
mono_crash.*
51+
52+
# Build results
53+
[Dd]ebug/
54+
[Dd]ebugPublic/
55+
[Rr]elease/
56+
[Rr]eleases/
57+
x64/
58+
x86/
59+
[Ww][Ii][Nn]32/
60+
[Aa][Rr][Mm]/
61+
[Aa][Rr][Mm]64/
62+
bld/
63+
[Ll]og/
64+
[Ll]ogs/
65+
66+
# Visual Studio cache/options directory
67+
.vs/
68+
69+
# Visual Studio Code
70+
.vscode/
71+
*.code-workspace
72+
73+
# JetBrains Rider
74+
.idea/
75+
*.sln.iml
76+
77+
# User settings
78+
appsettings.Development.json
79+
**/Properties/launchSettings.json
80+
81+
# macOS
82+
.DS_Store
83+
.AppleDouble
84+
.LSOverride
85+
86+
# Windows
87+
Thumbs.db
88+
ehthumbs.db
89+
Desktop.ini
90+
$RECYCLE.BIN/
91+
92+
# Linux
93+
*~
94+
.directory
95+
96+
# Temporary files
97+
*.tmp
98+
*.temp
99+
*.log
100+
*.cache
101+
102+
# Sample/test data
103+
samples/AI-Examples/
104+
tests/
105+
**/TestData/
106+
107+
# Deployment files (don't include in image)
108+
docker-compose*.yml
109+
Dockerfile*
110+
.dockerignore

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Multi-stage Dockerfile for AutoComplete.Playground
2+
# Optimized for .NET 9.0 Blazor Server deployment on Coolify
3+
4+
# Stage 1: Build
5+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
6+
WORKDIR /src
7+
8+
# Copy solution and project files
9+
COPY ["EasyAppDev.Blazor.AutoComplete.sln", "./"]
10+
COPY ["samples/AutoComplete.Playground/AutoComplete.Playground.csproj", "samples/AutoComplete.Playground/"]
11+
COPY ["src/EasyAppDev.Blazor.AutoComplete/EasyAppDev.Blazor.AutoComplete.csproj", "src/EasyAppDev.Blazor.AutoComplete/"]
12+
COPY ["src/EasyAppDev.Blazor.AutoComplete.AI/EasyAppDev.Blazor.AutoComplete.AI.csproj", "src/EasyAppDev.Blazor.AutoComplete.AI/"]
13+
COPY ["src/EasyAppDev.Blazor.AutoComplete.Generators/EasyAppDev.Blazor.AutoComplete.Generators.csproj", "src/EasyAppDev.Blazor.AutoComplete.Generators/"]
14+
COPY ["Directory.Build.props", "./"]
15+
COPY ["global.json", "./"]
16+
17+
# Restore dependencies
18+
RUN dotnet restore "samples/AutoComplete.Playground/AutoComplete.Playground.csproj"
19+
20+
# Copy all source files
21+
COPY . .
22+
23+
# Build and publish the application
24+
WORKDIR "/src/samples/AutoComplete.Playground"
25+
RUN dotnet publish "AutoComplete.Playground.csproj" \
26+
-c Release \
27+
-o /app/publish \
28+
--no-restore \
29+
/p:UseAppHost=false
30+
31+
# Stage 2: Runtime
32+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
33+
WORKDIR /app
34+
35+
# Install curl for health checks
36+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
37+
38+
# Create non-root user for security
39+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
40+
USER appuser
41+
42+
# Copy published application
43+
COPY --from=build --chown=appuser:appuser /app/publish .
44+
45+
# Expose port (Coolify will map this)
46+
EXPOSE 8080
47+
48+
# Set environment variables
49+
ENV ASPNETCORE_URLS=http://+:8080 \
50+
ASPNETCORE_ENVIRONMENT=Production \
51+
DOTNET_RUNNING_IN_CONTAINER=true \
52+
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
53+
54+
# Health check
55+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
56+
CMD curl --fail http://localhost:8080/ || exit 1
57+
58+
# Start the application
59+
ENTRYPOINT ["dotnet", "AutoComplete.Playground.dll"]

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: '3.8'
2+
3+
services:
4+
autocomplete-playground:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
container_name: autocomplete-playground
9+
ports:
10+
- "8080:8080"
11+
environment:
12+
# ASP.NET Core Configuration
13+
- ASPNETCORE_ENVIRONMENT=Production
14+
- ASPNETCORE_URLS=http://+:8080
15+
16+
# OpenAI Configuration (CHANGE THESE VALUES)
17+
# For security, use .env file or pass via command line
18+
- OpenAI__ApiKey=${OPENAI_API_KEY:-your-api-key-here}
19+
- OpenAI__Model=${OPENAI_MODEL:-text-embedding-3-small}
20+
21+
# Logging
22+
- Logging__LogLevel__Default=Information
23+
- Logging__LogLevel__Microsoft.AspNetCore=Warning
24+
25+
# Optional: Configure allowed hosts
26+
- AllowedHosts=*
27+
28+
restart: unless-stopped
29+
30+
healthcheck:
31+
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
32+
interval: 30s
33+
timeout: 10s
34+
retries: 3
35+
start_period: 60s
36+
37+
# Resource limits (adjust based on your needs)
38+
deploy:
39+
resources:
40+
limits:
41+
cpus: '1.0'
42+
memory: 512M
43+
reservations:
44+
cpus: '0.5'
45+
memory: 256M
46+
47+
# Logging configuration
48+
logging:
49+
driver: "json-file"
50+
options:
51+
max-size: "10m"
52+
max-file: "3"
53+
54+
networks:
55+
default:
56+
name: autocomplete-network

samples/AutoComplete.Playground/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
var builder = WebApplication.CreateBuilder(args);
66

7+
// Configure for running behind reverse proxy (Coolify/Nginx)
8+
builder.Services.Configure<ForwardedHeadersOptions>(options =>
9+
{
10+
options.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedFor
11+
| Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto;
12+
options.KnownNetworks.Clear();
13+
options.KnownProxies.Clear();
14+
});
15+
716
// Add services to the container.
817
builder.Services.AddRazorComponents()
918
.AddInteractiveServerComponents();
@@ -13,6 +22,9 @@
1322

1423
var app = builder.Build();
1524

25+
// Use forwarded headers for proper proxy support
26+
app.UseForwardedHeaders();
27+
1628
// Configure the HTTP request pipeline.
1729
if (!app.Environment.IsDevelopment())
1830
{
@@ -21,8 +33,11 @@
2133
app.UseHsts();
2234
}
2335

24-
app.UseHttpsRedirection();
25-
36+
// Only redirect to HTTPS in development (Coolify handles SSL termination)
37+
if (app.Environment.IsDevelopment())
38+
{
39+
app.UseHttpsRedirection();
40+
}
2641

2742
app.UseAntiforgery();
2843

0 commit comments

Comments
 (0)