mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Added Coolify related docker files
This commit is contained in:
parent
98dfad76aa
commit
f73fc4b4c4
3 changed files with 277 additions and 0 deletions
73
Dockerfile_coolify
Normal file
73
Dockerfile_coolify
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
# Base image
|
||||||
|
FROM python:3.12.3-slim-bookworm as base
|
||||||
|
|
||||||
|
# Install Nginx, curl, and build-essential
|
||||||
|
RUN apt update && apt install -y nginx curl build-essential \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& rm /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
|
# Install Node tools
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_21.x | bash - \
|
||||||
|
&& apt-get install -y nodejs \
|
||||||
|
&& npm install -g corepack pm2
|
||||||
|
|
||||||
|
# Frontend Build
|
||||||
|
FROM base AS deps
|
||||||
|
|
||||||
|
ARG NEXT_PUBLIC_LEARNHOUSE_API_URL
|
||||||
|
ARG NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL
|
||||||
|
ARG NEXT_PUBLIC_LEARNHOUSE_DOMAIN
|
||||||
|
|
||||||
|
ENV NEXT_PUBLIC_LEARNHOUSE_API_URL=${NEXT_PUBLIC_LEARNHOUSE_API_URL}
|
||||||
|
ENV NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL=${NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}
|
||||||
|
ENV NEXT_PUBLIC_LEARNHOUSE_DOMAIN=${NEXT_PUBLIC_LEARNHOUSE_DOMAIN}
|
||||||
|
|
||||||
|
WORKDIR /app/web
|
||||||
|
COPY ./apps/web/package.json ./apps/web/pnpm-lock.yaml* ./
|
||||||
|
COPY ./apps/web /app/web
|
||||||
|
RUN rm -f .env*
|
||||||
|
RUN if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Final image
|
||||||
|
FROM base as runner
|
||||||
|
RUN addgroup --system --gid 1001 system \
|
||||||
|
&& adduser --system --uid 1001 app \
|
||||||
|
&& mkdir .next \
|
||||||
|
&& chown app:system .next
|
||||||
|
COPY --from=deps /app/web/public ./app/web/public
|
||||||
|
COPY --from=deps --chown=app:system /app/web/.next/standalone ./app/web/
|
||||||
|
COPY --from=deps --chown=app:system /app/web/.next/static ./app/web/.next/static
|
||||||
|
|
||||||
|
# Backend Build
|
||||||
|
WORKDIR /app/api
|
||||||
|
COPY ./apps/api/pyproject.toml ./
|
||||||
|
COPY ./apps/api/uv.lock ./
|
||||||
|
|
||||||
|
# Install dependencies with proper flags and fallback to pip if needed
|
||||||
|
RUN pip install --upgrade pip && \
|
||||||
|
pip install uv && \
|
||||||
|
(uv pip sync --system --python=python3.12 || pip install -e .) && \
|
||||||
|
pip install uvicorn # Ensure at least the ASGI server is available
|
||||||
|
|
||||||
|
COPY ./apps/api ./
|
||||||
|
|
||||||
|
# Run the backend
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ./extra/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
ENV PORT=8000 LEARNHOUSE_PORT=9000 HOSTNAME=0.0.0.0
|
||||||
|
COPY ./extra/start.sh /app/start.sh
|
||||||
|
|
||||||
|
# Add near the end of your Dockerfile_coolify
|
||||||
|
RUN echo '#!/bin/bash\n\
|
||||||
|
echo "Enhanced patching of NextAuth cookies..."\n\
|
||||||
|
find /app/web/.next -type f -name "*.js" -exec sed -i "s/domain:[^,}]*,/domain: undefined,/g" {} \\;\n\
|
||||||
|
find /app/web/.next -type f -name "*.js" -exec sed -i "s/domain: *process.env.LEARNHOUSE_COOKIE_DOMAIN/domain: undefined/g" {} \\;\n\
|
||||||
|
find /app/web/.next -type f -name "*.js" -exec sed -i "s/\.domain\s*=\s*[^;]*;/\.domain = undefined;/g" {} \\;\n\
|
||||||
|
echo "Patch complete."\n\
|
||||||
|
sh /app/start.sh' > /app/patched-start.sh && chmod +x /app/patched-start.sh
|
||||||
|
|
||||||
|
# Use the patched start script
|
||||||
|
CMD ["/app/patched-start.sh"]
|
||||||
100
README_Coolify.md
Normal file
100
README_Coolify.md
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
# LearnHouse Deployment Guide for Coolify
|
||||||
|
|
||||||
|
This document provides instructions for deploying LearnHouse using Coolify, ensuring proper configuration and persistent storage.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- A Coolify instance up and running
|
||||||
|
- Access to the LearnHouse GitHub repository
|
||||||
|
- Domain name for your LearnHouse instance
|
||||||
|
- Email provider credentials (if using email functionality)
|
||||||
|
|
||||||
|
## Deployment Steps
|
||||||
|
|
||||||
|
### 1. Create a New Resource in Coolify
|
||||||
|
|
||||||
|
- Log in to your Coolify dashboard
|
||||||
|
- Click on "Create Resource"
|
||||||
|
- Select "GitHub Repository" as the source
|
||||||
|
|
||||||
|
### 2. Configure Docker Compose Build
|
||||||
|
|
||||||
|
- Select "Docker Compose" as the build method
|
||||||
|
- Choose `docker-compose-coolify.yml` as the compose file
|
||||||
|
- Make sure the "Volume" configuration is set to store persistent data
|
||||||
|
|
||||||
|
### 3. Configure Domain Settings
|
||||||
|
|
||||||
|
- Add your domain (e.g., `learnhouse.example.com`) in the resource settings
|
||||||
|
- Enable HTTPS if needed (recommended for production)
|
||||||
|
- Configure any necessary redirects
|
||||||
|
|
||||||
|
### 4. Environment Variables
|
||||||
|
|
||||||
|
Add the following environment variables. Replace placeholder values with your actual configuration:
|
||||||
|
|
||||||
|
```
|
||||||
|
# LearnHouse Core Configuration
|
||||||
|
LEARNHOUSE_SITE_NAME=Your LMS Name
|
||||||
|
LEARNHOUSE_SITE_DESCRIPTION=Your platform description
|
||||||
|
LEARNHOUSE_SELF_HOSTED=true
|
||||||
|
LEARNHOUSE_SSL=true
|
||||||
|
LEARNHOUSE_CONTACT_EMAIL=contact@example.com
|
||||||
|
|
||||||
|
# Domain Configuration
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_DOMAIN=learnhouse.example.com
|
||||||
|
LEARNHOUSE_COOKIE_DOMAIN=learnhouse.example.com
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN=learnhouse.example.com
|
||||||
|
|
||||||
|
# Authentication
|
||||||
|
NEXTAUTH_SECRET=your_generated_secret_key
|
||||||
|
NEXTAUTH_URL=https://learnhouse.example.com
|
||||||
|
|
||||||
|
# API URLs
|
||||||
|
NEXT_PUBLIC_API_URL=https://learnhouse.example.com/api/v1/
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_API_URL=https://learnhouse.example.com/api/v1/
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL=https://learnhouse.example.com/
|
||||||
|
|
||||||
|
# Organization Settings
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG=false
|
||||||
|
NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG=default
|
||||||
|
|
||||||
|
# Database Configuration
|
||||||
|
POSTGRES_USER=learnhouse
|
||||||
|
POSTGRES_PASSWORD=strong_database_password
|
||||||
|
POSTGRES_DB=learnhouse
|
||||||
|
LEARNHOUSE_SQL_CONNECTION_STRING=postgresql://learnhouse:strong_database_password@db:5432/learnhouse
|
||||||
|
|
||||||
|
# Redis Configuration
|
||||||
|
REDIS_PASSWORD=strong_redis_password
|
||||||
|
LEARNHOUSE_REDIS_CONNECTION_STRING=redis://default:strong_redis_password@redis:6379/learnhouse
|
||||||
|
|
||||||
|
# ChromaDB Configuration
|
||||||
|
LEARNHOUSE_CHROMADB_HOST=chromadb
|
||||||
|
|
||||||
|
# Email Configuration (optional)
|
||||||
|
LEARNHOUSE_EMAIL_PROVIDER=resend
|
||||||
|
LEARNHOUSE_RESEND_API_KEY=re_your_resend_api_key
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Start the Build Process
|
||||||
|
|
||||||
|
- Click on "Deploy" to start the build and deployment process
|
||||||
|
- Monitor the build logs for any errors
|
||||||
|
- Once complete, verify that your LearnHouse instance is accessible at your domain
|
||||||
|
|
||||||
|
### 6. Verify Persistent Storage
|
||||||
|
|
||||||
|
- After deployment, upload some content (course materials, organization logos, etc.)
|
||||||
|
- Restart the service to confirm that uploaded files persist across restarts
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- **File uploads not persisting**: Ensure the volume mount in `docker-compose-coolify.yml` points to `/app/api/content` which is where the application stores uploaded files.
|
||||||
|
- **Database connection errors**: Verify the database credentials and connection string.
|
||||||
|
- **UI rendering issues**: Check that all Next.js related environment variables are correctly set.
|
||||||
|
|
||||||
|
## Additional Resources
|
||||||
|
|
||||||
|
- [LearnHouse Documentation](https://docs.learnhouse.io/)
|
||||||
|
- [Coolify Documentation](https://coolify.io/docs)
|
||||||
104
docker-compose-coolify.yml
Normal file
104
docker-compose-coolify.yml
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
version: "3.9"
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile_coolify
|
||||||
|
args:
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_API_URL=${NEXT_PUBLIC_LEARNHOUSE_API_URL}
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL=${NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_DOMAIN=${NEXT_PUBLIC_LEARNHOUSE_DOMAIN}
|
||||||
|
# Mount the persistent volume to the actual uploads directory (/app/api/content)
|
||||||
|
volumes:
|
||||||
|
- app-uploads:/app/api/content
|
||||||
|
environment:
|
||||||
|
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
|
||||||
|
- NEXTAUTH_URL=${NEXTAUTH_URL}
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG=${NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG}
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG=${NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG}
|
||||||
|
- NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN=${NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN}
|
||||||
|
- LEARNHOUSE_COOKIE_DOMAIN=${LEARNHOUSE_COOKIE_DOMAIN}
|
||||||
|
- LEARNHOUSE_SQL_CONNECTION_STRING=${LEARNHOUSE_SQL_CONNECTION_STRING}
|
||||||
|
- LEARNHOUSE_REDIS_CONNECTION_STRING=${LEARNHOUSE_REDIS_CONNECTION_STRING}
|
||||||
|
- LEARNHOUSE_CHROMADB_HOST=${LEARNHOUSE_CHROMADB_HOST}
|
||||||
|
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
chromadb:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test:
|
||||||
|
- CMD
|
||||||
|
- curl
|
||||||
|
- '-f'
|
||||||
|
- 'http://127.0.0.1:80'
|
||||||
|
interval: 2s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 10
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.learnhouse.rule=Host(`${LEARNHOUSE_DOMAIN}`)"
|
||||||
|
- "traefik.http.routers.learnhouse.entrypoints=websecure"
|
||||||
|
- "traefik.http.services.learnhouse.loadbalancer.server.port=80"
|
||||||
|
- "traefik.http.routers.learnhouse.tls=true"
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=${POSTGRES_USER}
|
||||||
|
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||||
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 4s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7.2.3
|
||||||
|
command: redis-server --requirepass ${REDIS_PASSWORD}
|
||||||
|
restart: always
|
||||||
|
# ports:
|
||||||
|
# - "6379:6379"
|
||||||
|
volumes:
|
||||||
|
- redis-data:/data
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- REDIS_PASSWORD=${REDIS_PASSWORD}
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 4s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
chromadb:
|
||||||
|
image: chromadb/chroma:0.5.16
|
||||||
|
environment:
|
||||||
|
- CHROMA_SERVER_HOST=localhost # Only bind to container's localhost
|
||||||
|
- CHROMA_SERVER_HTTP_PORT=8000 # Keep internal port consistent
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
redis-data:
|
||||||
|
app-uploads:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: traefik
|
||||||
|
external: true
|
||||||
Loading…
Add table
Add a link
Reference in a new issue