-
Notifications
You must be signed in to change notification settings - Fork 126
Solve inconsistent setup by adding full Docker & Compose support for backend and frontend #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: Docker Build and Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, develop ] | ||
| pull_request: | ||
| branches: [ main, develop ] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Build Backend | ||
| run: | | ||
| cd Backend | ||
| docker build -t inpactai-backend:test . | ||
|
|
||
| - name: Build Frontend | ||
| run: | | ||
| cd Frontend | ||
| docker build -t inpactai-frontend:test . | ||
|
|
||
| - name: Start services | ||
| run: | | ||
| docker compose up -d | ||
| sleep 30 | ||
|
Comment on lines
+30
to
+33
|
||
|
|
||
| - name: Check backend health | ||
| run: | | ||
| curl -f http://localhost:8000/ || exit 1 | ||
|
|
||
| - name: Check frontend health | ||
| run: | | ||
| curl -f http://localhost:5173/ || exit 1 | ||
|
Comment on lines
+30
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI will fail without environment setup and uses fragile health checks. The workflow starts services without creating required Apply this diff to fix the issues: + - name: Setup environment files
+ run: |
+ cp Backend/.env.example Backend/.env
+ cp Frontend/.env.example Frontend/.env
+ # Set minimal test credentials
+ echo "REDIS_HOST=redis" >> Backend/.env
+ echo "REDIS_PORT=6379" >> Backend/.env
+
- name: Start services
run: |
docker compose up -d
- sleep 30
+
+ - name: Wait for services to be healthy
+ run: |
+ timeout 120 bash -c 'until docker compose ps | grep -q "healthy"; do sleep 2; done' || true
+ docker compose ps
- name: Check backend health
run: |
- curl -f http://localhost:8000/ || exit 1
+ timeout 30 bash -c 'until curl -f http://localhost:8000/; do sleep 2; done'
- name: Check frontend health
run: |
- curl -f http://localhost:5173/ || exit 1
+ timeout 30 bash -c 'until curl -f http://localhost:5173/; do sleep 2; done'
🤖 Prompt for AI Agents |
||
|
|
||
| - name: Show logs on failure | ||
| if: failure() | ||
| run: | | ||
| docker compose logs | ||
|
|
||
| - name: Cleanup | ||
| if: always() | ||
| run: | | ||
| docker compose down -v | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||
| __pycache__ | ||||||
| *.pyc | ||||||
| *.pyo | ||||||
| *.pyd | ||||||
| .Python | ||||||
| *.so | ||||||
| .env | ||||||
| .venv | ||||||
|
Comment on lines
+7
to
+8
|
||||||
| .env | |
| .venv |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| user=postgres | ||
| password=your_postgres_password | ||
| host=your_postgres_host | ||
| port=5432 | ||
| dbname=postgres | ||
| GROQ_API_KEY=your_groq_api_key | ||
| SUPABASE_URL=your_supabase_url | ||
| SUPABASE_KEY=your_supabase_key | ||
| GEMINI_API_KEY=your_gemini_api_key | ||
| YOUTUBE_API_KEY=your_youtube_api_key | ||
| REDIS_HOST=redis | ||
| REDIS_PORT=6379 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM python:3.10-slim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gcc \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| libpq-dev \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY requirements.txt . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN pip install --no-cache-dir -r requirements.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPOSE 8000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add non-root user for security. The container currently runs as root, which is a security risk even in development environments. Running as a non-privileged user follows the principle of least privilege. Apply this diff to add a non-root user: FROM python:3.10-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
+RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
+USER appuser
+
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| FROM python:3.10-slim AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| gcc \ | ||
| libpq-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir --user -r requirements.txt | ||
|
|
||
| FROM python:3.10-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| libpq5 \ | ||
| && rm -rf /var/lib/apt/lists/* \ | ||
| && groupadd -r appuser && useradd -r -g appuser appuser | ||
|
|
||
| COPY --from=builder /root/.local /root/.local | ||
| COPY . . | ||
|
|
||
| RUN chown -R appuser:appuser /app | ||
|
|
||
| USER appuser | ||
|
|
||
| ENV PATH=/root/.local/bin:$PATH | ||
|
Comment on lines
+22
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Non-root user cannot access packages in /root/.local. The builder installs packages to Apply this diff to install packages to a location accessible by -COPY --from=builder /root/.local /root/.local
+COPY --from=builder --chown=appuser:appuser /root/.local /home/appuser/.local
COPY . .
RUN chown -R appuser:appuser /app
USER appuser
-ENV PATH=/root/.local/bin:$PATH
+ENV PATH=/home/appuser/.local/bin:$PATH🤖 Prompt for AI Agents
Comment on lines
+22
to
+29
|
||
|
|
||
| EXPOSE 8000 | ||
|
|
||
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| # Docker Architecture Diagram | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────────────────────────────────────┐ | ||
| │ Docker Host Machine │ | ||
| │ │ | ||
| │ ┌─────────────────────────────────────────────────────────────┐ │ | ||
| │ │ Docker Network: inpactai-network │ │ | ||
| │ │ │ │ | ||
| │ │ ┌──────────────────┐ ┌──────────────────┐ ┌────────┐│ │ | ||
| │ │ │ Frontend │ │ Backend │ │ Redis ││ │ | ||
| │ │ │ Container │ │ Container │ │ Container │ | ||
| │ │ │ │ │ │ │ ││ │ | ||
| │ │ │ Node 18-alpine │ │ Python 3.10-slim │ │ Redis 7││ │ | ||
| │ │ │ Vite Dev Server │◄───┤ FastAPI + uvicorn │ Alpine ││ │ | ||
| │ │ │ Port: 5173 │ │ Port: 8000 │◄───┤ Port: ││ │ | ||
| │ │ │ │ │ │ │ 6379 ││ │ | ||
| │ │ └──────────────────┘ └──────────────────┘ └────────┘│ │ | ||
| │ │ │ │ │ │ │ | ||
| │ │ │ Volume Mount │ Volume Mount │ │ │ | ||
| │ │ │ (Hot Reload) │ (Hot Reload) │ │ │ | ||
| │ │ ▼ ▼ ▼ │ │ | ||
| │ │ ┌──────────────┐ ┌─────────────┐ ┌──────────┐│ │ | ||
| │ │ │ ./Frontend │ │ ./Backend │ │redis_data││ │ | ||
| │ │ │ /app │ │ /app │ │ Volume ││ │ | ||
| │ │ └──────────────┘ └─────────────┘ └──────────┘│ │ | ||
| │ └─────────────────────────────────────────────────────────────┘ │ | ||
| │ │ | ||
| │ Port Mappings: │ | ||
| │ ┌─────────────┬──────────────┬────────────────────────────────┐ │ | ||
| │ │ Host:5173 │ ──────────► │ frontend:5173 (React + Vite) │ │ | ||
| │ │ Host:8000 │ ──────────► │ backend:8000 (FastAPI) │ │ | ||
| │ │ Host:6379 │ ──────────► │ redis:6379 (Cache) │ │ | ||
| │ └─────────────┴──────────────┴────────────────────────────────┘ │ | ||
| │ │ | ||
| │ Environment Files: │ | ||
| │ ┌────────────────────────────────────────────────────────────┐ │ | ||
| │ │ Backend/.env → Backend Container │ │ | ||
| │ │ Frontend/.env → Frontend Container │ │ | ||
| │ └────────────────────────────────────────────────────────────┘ │ | ||
| │ │ | ||
| └───────────────────────────────────────────────────────────────────────┘ | ||
|
|
||
| User Browser | ||
| │ | ||
| ▼ | ||
| http://localhost:5173 ──► Frontend Container ──► React UI | ||
| │ | ||
| │ API Calls | ||
| ▼ | ||
| http://backend:8000 ──► Backend Container ──► FastAPI | ||
| │ | ||
| │ Cache/PubSub | ||
| ▼ | ||
| redis:6379 ──► Redis Container | ||
|
|
||
|
|
||
| Communication Flow: | ||
| ────────────────────── | ||
|
|
||
| 1. User accesses http://localhost:5173 | ||
| └─► Docker routes to Frontend Container | ||
|
|
||
| 2. Frontend makes API call to /api/* | ||
| └─► Vite proxy forwards to http://backend:8000 | ||
| └─► Docker network resolves 'backend' to Backend Container | ||
|
|
||
| 3. Backend connects to Redis | ||
| └─► Uses REDIS_HOST=redis environment variable | ||
| └─► Docker network resolves 'redis' to Redis Container | ||
|
|
||
| 4. Backend connects to Supabase | ||
| └─► Uses credentials from Backend/.env | ||
| └─► External connection via internet | ||
|
|
||
|
|
||
| Service Dependencies: | ||
| ───────────────────── | ||
|
|
||
| redis (no dependencies) | ||
| │ | ||
| └─► backend (depends on redis) | ||
| │ | ||
| └─► frontend (depends on backend) | ||
|
|
||
|
|
||
| Health Checks: | ||
| ────────────── | ||
|
|
||
| Redis: redis-cli ping | ||
| Backend: curl http://localhost:8000/ | ||
| Frontend: No health check (depends on backend health) | ||
|
|
||
|
|
||
| Volume Mounts: | ||
| ────────────── | ||
|
|
||
| Development: | ||
| ./Backend:/app (Hot reload for Python) | ||
| ./Frontend:/app (Hot reload for Vite) | ||
| /app/__pycache__ (Excluded) | ||
| /app/node_modules (Excluded) | ||
|
|
||
| Production: | ||
| redis_data:/data (Persistent Redis storage only) | ||
|
|
||
|
|
||
| Build Process: | ||
| ────────────── | ||
|
|
||
| Development: | ||
| 1. Copy package files | ||
| 2. Install dependencies | ||
| 3. Copy source code | ||
| 4. Start dev server with hot reload | ||
|
|
||
| Production: | ||
| Stage 1: Build | ||
| 1. Copy package files | ||
| 2. Install dependencies | ||
| 3. Copy source code | ||
| 4. Build optimized bundle | ||
|
|
||
| Stage 2: Serve | ||
| 1. Copy built artifacts | ||
| 2. Use minimal runtime (nginx for frontend) | ||
| 3. Serve optimized files | ||
|
|
||
|
|
||
| Network Isolation: | ||
| ────────────────── | ||
|
|
||
| Internal Network (inpactai-network): | ||
| - frontend ←→ backend (HTTP) | ||
| - backend ←→ redis (TCP) | ||
|
|
||
| External Access: | ||
| - Host machine → All containers (via port mapping) | ||
| - Backend → Supabase (via internet) | ||
|
||
| - Backend → External APIs (via internet) | ||
|
|
||
|
|
||
| Security Model: | ||
| ─────────────── | ||
|
|
||
| Development: | ||
| - Root user in containers (for hot reload) | ||
| - Source code mounted as volumes | ||
| - Debug logging enabled | ||
|
|
||
| Production: | ||
| - Non-root user in containers | ||
| - No volume mounts (except data) | ||
| - Production logging | ||
| - Resource limits enforced | ||
| - Optimized images | ||
| ``` | ||
|
|
||
| ## Quick Command Reference | ||
|
|
||
| ```bash | ||
| Start: docker compose up --build | ||
| Stop: docker compose down | ||
| Logs: docker compose logs -f | ||
| Rebuild: docker compose up --build | ||
| Clean: docker compose down -v | ||
| ``` | ||
|
|
||
| ## Service URLs | ||
|
|
||
| | Service | Internal | External | | ||
| |---------|----------|----------| | ||
| | Frontend | frontend:5173 | http://localhost:5173 | | ||
| | Backend | backend:8000 | http://localhost:8000 | | ||
| | Redis | redis:6379 | localhost:6379 | | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow builds Backend and Frontend images separately with custom tags, but then runs 'docker compose up' which will rebuild the images again according to docker-compose.yml, ignoring the previously built images. Either use the pre-built images or remove the separate build steps to avoid redundant builds.