diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..22f8d96 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +bin/ +obj/ +.git/ +.vs/ +.vscode/ +node_modules/ +packages/ +*.tmp +*.swp +*.swo +.env +.env.local +.dockerignore +Dockerfile* +docker-compose* +README.md \ No newline at end of file diff --git a/Docker-README.md b/Docker-README.md new file mode 100644 index 0000000..376bead --- /dev/null +++ b/Docker-README.md @@ -0,0 +1,65 @@ +# ShiftScheduler Docker Setup + +This directory contains Docker configuration files for running the ShiftScheduler application in containers. + +## Files + +- `Dockerfile` - Production dockerfile that clones the repository from GitHub +- `Dockerfile.local` - Development dockerfile that uses local source files +- `docker-compose.yml` - Docker Compose configuration for easy deployment +- `.dockerignore` - Files to exclude from Docker build context + +## Usage + +### Option 1: Using Local Source (Recommended for Development) + +```bash +# Build using local source files +docker build -f Dockerfile.local -t shiftscheduler:local . + +# Run the container +docker run -p 5000:5000 shiftscheduler:local +``` + +### Option 2: Using Git Repository Clone (Production) + +```bash +# Build using git repository clone +docker build -t shiftscheduler:latest . + +# Run the container +docker run -p 5000:5000 shiftscheduler:latest +``` + +### Option 3: Using Docker Compose (Easiest) + +```bash +# Start the application +docker-compose up --build + +# Run in background +docker-compose up -d --build + +# Stop the application +docker-compose down +``` + +## Accessing the Application + +Once running, the application will be available at: +- http://localhost:5000 + +## Notes + +- The production Dockerfile clones the latest version from the GitHub repository +- The local Dockerfile uses the current source files for development +- The application runs on port 5000 inside the container +- Environment is set to Production by default in Docker containers + +## Troubleshooting + +If you encounter SSL certificate issues during build, you can: + +1. Use the local Dockerfile instead: `docker build -f Dockerfile.local -t shiftscheduler .` +2. Build with network host mode: `docker build --network=host -t shiftscheduler .` +3. Configure Docker to use system certificates if needed \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9eb554 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Use the official .NET 9.0 SDK image for building +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env + +# Set working directory +WORKDIR /source + +# Copy the project files from current directory +# Note: In production, replace this with git clone or download from repository +# For example: RUN git clone https://github.com/clayschaad/ShiftScheduler.git . +COPY . . + +# Restore dependencies +RUN dotnet restore + +# Build the application +RUN dotnet build --configuration Release --no-restore + +# Publish the application +RUN dotnet publish Server/ShiftScheduler.Server.csproj --configuration Release --no-build --output /app/publish + +# Use the official .NET 9.0 runtime image for the final stage +FROM mcr.microsoft.com/dotnet/aspnet:9.0 + +# Set working directory +WORKDIR /app + +# Copy the published application from the build stage +COPY --from=build-env /app/publish . + +# Expose the HTTP port (5000 is the default from launchSettings.json) +EXPOSE 5000 + +# Set environment variables for production +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:5000 + +# Run the application +ENTRYPOINT ["dotnet", "ShiftScheduler.Server.dll"] \ No newline at end of file diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..082146e --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,37 @@ +# Use the official .NET 9.0 SDK image for building +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env + +# Set working directory +WORKDIR /source + +# Copy the project files from current directory (for local development) +# In production, you would clone the repository here instead +COPY . . + +# Restore dependencies +RUN dotnet restore + +# Build the application +RUN dotnet build --configuration Release --no-restore + +# Publish the application +RUN dotnet publish Server/ShiftScheduler.Server.csproj --configuration Release --no-build --output /app/publish + +# Use the official .NET 9.0 runtime image for the final stage +FROM mcr.microsoft.com/dotnet/aspnet:9.0 + +# Set working directory +WORKDIR /app + +# Copy the published application from the build stage +COPY --from=build-env /app/publish . + +# Expose the HTTP port (5000 is the default from launchSettings.json) +EXPOSE 5000 + +# Set environment variables for production +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:5000 + +# Run the application +ENTRYPOINT ["dotnet", "ShiftScheduler.Server.dll"] \ No newline at end of file diff --git a/Dockerfile.production b/Dockerfile.production new file mode 100644 index 0000000..15a9870 --- /dev/null +++ b/Dockerfile.production @@ -0,0 +1,45 @@ +# Production Dockerfile for ShiftScheduler +# This version clones the repository from GitHub to always get the latest version + +# Use the official .NET 9.0 SDK image for building +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env + +# Set working directory +WORKDIR /source + +# Install git for cloning the repository +RUN apt-get update && \ + apt-get install -y git && \ + rm -rf /var/lib/apt/lists/* + +# Clone the git repository to always have the actual version of ShiftScheduler +RUN git clone https://github.com/clayschaad/ShiftScheduler.git . || \ + git -c http.sslVerify=false clone https://github.com/clayschaad/ShiftScheduler.git . + +# Restore dependencies +RUN dotnet restore + +# Build the application +RUN dotnet build --configuration Release --no-restore + +# Publish the application +RUN dotnet publish Server/ShiftScheduler.Server.csproj --configuration Release --no-build --output /app/publish + +# Use the official .NET 9.0 runtime image for the final stage +FROM mcr.microsoft.com/dotnet/aspnet:9.0 + +# Set working directory +WORKDIR /app + +# Copy the published application from the build stage +COPY --from=build-env /app/publish . + +# Expose the HTTP port (5000 is the default from launchSettings.json) +EXPOSE 5000 + +# Set environment variables for production +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:5000 + +# Run the application +ENTRYPOINT ["dotnet", "ShiftScheduler.Server.dll"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5d8f394 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + shiftscheduler: + build: + context: . + dockerfile: Dockerfile + ports: + - "5000:5000" + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://+:5000 + restart: unless-stopped + container_name: shiftscheduler-app + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/", "||", "exit", "1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s \ No newline at end of file