diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..51f8f2d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,74 @@ +# .dockerignore - Exclude unnecessary files from Docker build context + +# Git +.git +.gitignore +.gitattributes + +# Documentation +*.md +README* + +# IDE and editor files +.vscode/ +.vs/ +*.swp +*.swo +*~ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Build outputs +bin/ +obj/ +out/ +dist/ + +# Node modules (will be installed in container) +node_modules/ +npm-debug.log* + +# .NET +*.user +*.userosscache +*.sln.docstates +*.userprefs + +# Test results +TestResults/ +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Package files +*.nupkg +*.snupkg + +# Logs +logs +*.log + +# Environment files +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +# Temporary files +*.tmp +*.temp \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..436c7cc --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +# Environment variables for Docker Compose +# Copy this file to .env and update the values + +# Application Configuration +ASPNETCORE_ENVIRONMENT=Production +ASPNETCORE_URLS=http://+:8080 + +# Logging +LOG_LEVEL=Information + +# Optional: External service configurations +# API_KEY=your_api_key_here +# EXTERNAL_SERVICE_URL=https://api.example.com \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e6e584 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# Multi-stage Dockerfile for .NET 9 ASP.NET Core application with pnpm +# Stage 1: Base runtime image +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +# Create non-root user for security +RUN groupadd -r appgroup && useradd -r -g appgroup appuser + +# Stage 2: Node.js build environment for frontend assets +FROM node:20-alpine AS node-build +WORKDIR /src + +# Install pnpm globally +RUN npm install -g pnpm + +# Copy package files and install dependencies +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +# Copy source files and build CSS +COPY . . +RUN pnpm run build + +# Stage 3: .NET SDK for building the application +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +WORKDIR /src + +# Copy project file and restore dependencies +COPY *.csproj . +RUN dotnet restore "BankSampahApp.csproj" + +# Copy source code +COPY . . + +# Copy built frontend assets from node-build stage +COPY --from=node-build /src/wwwroot/css/site.css ./wwwroot/css/ + +# Build the application +RUN dotnet build "BankSampahApp.csproj" -c Release -o /app/build + +# Stage 4: Publish the application +FROM build AS publish +RUN dotnet publish "BankSampahApp.csproj" -c Release -o /app/publish /p:UseAppHost=false + +# Stage 5: Final runtime image +FROM base AS final +WORKDIR /app + +# Copy published application +COPY --from=publish /app/publish . + +# Change ownership to non-root user +RUN chown -R appuser:appgroup /app +USER appuser + +# Configure environment +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:8080 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8080/health || exit 1 + +# Entry point +ENTRYPOINT ["dotnet", "BankSampahApp.dll"] \ No newline at end of file diff --git a/README.md b/README.md index c478a17..29eb2ab 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ bank-sampah/ ### Prerequisites - .NET 9.0 SDK atau lebih baru -- Node.js 18+ dan npm (untuk Tailwind CSS) +- Node.js 18+ dan pnpm (untuk Tailwind CSS) - Visual Studio 2022 17.8+ atau VS Code dengan C# extension ### Langkah Instalasi @@ -61,12 +61,12 @@ bank-sampah/ 2. **Install dependencies Node.js** ```bash - npm install + pnpm install ``` 3. **Build CSS dengan Tailwind** ```bash - npm run build-css + pnpm run build-css ``` 4. **Restore .NET packages** @@ -88,7 +88,7 @@ bank-sampah/ ```bash # Terminal 1: Watch CSS changes -npm run build-css +pnpm run build-css # Terminal 2: Run aplikasi dengan hot reload dotnet watch run @@ -100,7 +100,7 @@ dotnet watch run ```bash # Build optimized CSS -npm run build +pnpm run build # Publish aplikasi .NET dotnet publish -c Release -o ./publish diff --git a/README.pdf b/README.pdf new file mode 100644 index 0000000..0607ea8 Binary files /dev/null and b/README.pdf differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e888cb7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3.8' + +services: + # Main application service + bank-sampah-app: + build: + context: . + dockerfile: Dockerfile + target: final + container_name: bank-sampah-app + ports: + - "8080:8080" + - "8081:8081" + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://+:8080 + volumes: + # Mount configuration files (optional) + - ./appsettings.Production.json:/app/appsettings.Production.json:ro + # Mount logs directory + - ./logs:/app/logs + networks: + - bank-sampah-network + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + # Nginx reverse proxy (optional) + nginx: + image: nginx:alpine + container_name: bank-sampah-nginx + ports: + - "80:80" + - "443:443" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - ./nginx/ssl:/etc/nginx/ssl:ro + - ./logs/nginx:/var/log/nginx + networks: + - bank-sampah-network + restart: unless-stopped + depends_on: + - bank-sampah-app + +networks: + bank-sampah-network: + driver: bridge \ No newline at end of file