Skip to content

Dockerize the application#190

Merged
codebestia merged 1 commit intomainfrom
feat/dockerize-application
Nov 4, 2025
Merged

Dockerize the application#190
codebestia merged 1 commit intomainfrom
feat/dockerize-application

Conversation

@codebestia
Copy link
Member

@codebestia codebestia commented Nov 4, 2025

Description

Dockerizing the project to support frontend, backend and indexer

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Other (please describe)

Checklist:

  • I have read the contributing guidelines.
  • I have updated the documentation (if applicable).
  • My changes do not break existing functionality.
  • I have added tests that cover my changes (if applicable).
  • All new and existing tests pass.
  • I have included screenshots or GIFs to demonstrate the changes (if applicable).

Summary by CodeRabbit

  • Chores
    • Implemented Docker containerization enabling coordinated deployment of backend, frontend, database, and indexing services with automated orchestration.
    • Added multi-stage production build configuration for the frontend with performance optimization and static asset serving.
    • Updated package manager specifications and workspace configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

Walkthrough

The changes introduce Docker containerization and orchestration infrastructure for the project. A .dockerignore file excludes build artifacts and dependencies. Four Dockerfiles define container images for backend (Python 3.12), frontend development, and frontend production (multi-stage build). A docker-compose.yml orchestrates five services: PostgreSQL database, backend, frontend, MongoDB, and a Starknet indexer with shared networking and volumes. A minor configuration update specifies the npm package manager version in frontend metadata.

Changes

Cohort / File(s) Summary
Docker Infrastructure
\.dockerignore, backend/dockerfile, frontend/dockerfile, frontend/dockerfile\.production
Added .dockerignore with common build artifact patterns. Backend Dockerfile uses python:3.12-slim-bullseye with bytecode/buffering disabled, port 5000 exposed. Frontend dev Dockerfile uses node:22-bullseye-slim with Turbo support and port 3000. Frontend production Dockerfile implements two-stage build (node:18-alpine builder → nginx:stable-alpine) with SPA routing fallback, gzip compression, and asset caching.
Orchestration Configuration
docker-compose\.yml
Added complete multi-service composition defining five services (db, backend, frontend, indexer, mongo) with PostgreSQL 14, shared bridge network (spherre_network), persistent volumes (spherre-db-data, mongo_data), service dependencies, health checks, environment variables, and port mappings (8000 backend, 3000 frontend, 5432 database, 27017 MongoDB).
Package Configuration
frontend/package\.json
Added packageManager field specifying npm@10.9.2.
Project Metadata
qa
Replaced 18 project/workspace entries with a single entry (dashboard-integration), indicating branch/workspace consolidation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas requiring attention:

  • Dockerfile optimization: Verify layer caching strategies, particularly in multi-stage frontend production build and dependency installation ordering
  • docker-compose service configuration: Validate network connectivity between services, volume mount paths, and environment variable configurations (especially database credentials and service URLs)
  • Backend Dockerfile: Confirm the start script path and port mapping (5000 internally) aligns with backend configuration
  • Frontend production build: Review fallback logic between npm and yarn, and SPA routing configuration for index.html rewrite

Poem

🐰 From scripts to containers, we hop with delight,
Docker and Compose bring services to light,
PostgreSQL hops, Node builds tall,
With volumes and networks, orchestrating it all! 🐳

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Dockerize the application' accurately summarizes the main change—adding Docker configuration files for containerization.
Description check ✅ Passed The description covers the main purpose and includes a type of change selection, but omits several required template sections like Related Issue and How Has This Been Tested.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/dockerize-application

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codebestia codebestia merged commit 7606848 into main Nov 4, 2025
3 of 4 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (4)
backend/dockerfile (1)

1-17: Add non-root user for production security.

Running containers as root is a security risk. Add an explicit non-root user in the Dockerfile.

 FROM python:3.12-slim-bullseye

 ENV PYTHONDONTWRITEBYTECODE 1
 ENV PYTHONUNBUFFERED 1

 WORKDIR /home/spherre_backend/src

+RUN groupadd -r appuser && useradd -r -g appuser appuser

 COPY backend .

 RUN pip install --no-cache-dir -r requirements.txt

+RUN chown -R appuser:appuser /home/spherre_backend/src
+USER appuser

 EXPOSE 5000

 RUN chmod +x ./start

 CMD ["./start"]
frontend/dockerfile.production (1)

12-14: Prefer npm ci for reproducible builds.

Lines 12–14 conditionally choose between npm ci, yarn install --frozen-lockfile, and npm install. The fallback chain adds complexity. If npm ci is available (package-lock.json exists), use it consistently rather than falling back to yarn or npm install.

-RUN if [ -f package-lock.json ]; then npm ci; \
-    elif [ -f yarn.lock ]; then npm install -g yarn && yarn install --frozen-lockfile; \
-    else npm install; fi
+RUN npm ci --prefer-offline || npm install

This ensures reproducible builds from lock files when available.

docker-compose.yml (2)

21-33: Add explicit depends_on to ensure service startup order.

Currently, there are no depends_on constraints between frontend/backend and db. While compose will attempt to start all services, there's no guarantee that the database is ready before backend/frontend try to connect. Add explicit dependencies:

   backend:
     container_name: spherre_backend
     build:
       context: ./
       dockerfile: ./backend/dockerfile
+    depends_on:
+      db:
+        condition: service_healthy
     volumes:
       ...

   frontend:
     container_name: spherre_frontend
     build:
       context: ./
       dockerfile: ./frontend/dockerfile
+    depends_on:
+      backend:
+        condition: service_started
     volumes:
       ...

This ensures db is healthy before backend starts, and backend is available before frontend tries to connect.

Also applies to: 35-46


1-76: Document environment variables and configuration.

The docker-compose file references multiple environment variables (e.g., ${DB_USER}, ${DB_PASSWORD}, ${DB_NAME}, ${INFURA_KEY}) but doesn't specify where they come from or what defaults exist. Create an .env.example file documenting all required and optional variables, and add a README section explaining how to set up the compose environment (e.g., copy .env.example to .env and fill in values).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17e9dad and a3fda29.

📒 Files selected for processing (7)
  • .dockerignore (1 hunks)
  • backend/dockerfile (1 hunks)
  • docker-compose.yml (1 hunks)
  • frontend/dockerfile (1 hunks)
  • frontend/dockerfile.production (1 hunks)
  • frontend/package.json (1 hunks)
  • qa (0 hunks)
💤 Files with no reviewable changes (1)
  • qa
🔇 Additional comments (4)
frontend/package.json (1)

5-5: Good addition—but verify npm version alignment with dependencies.

The packageManager field correctly pins npm 10.9.2 for consistency. However, line 38 lists "npm": "^11.2.0" in dependencies, which allows npm 11.x. This version mismatch could cause confusion or conflicts if npm 11.2.0 is installed globally but the packageManager enforces 10.9.2.

Consider aligning the npm dependency version with the pinned packageManager version for consistency.

.dockerignore (1)

1-95: Excellent .dockerignore coverage.

The .dockerignore file is comprehensive and well-organized, properly excluding build artifacts, dependencies, secrets, and editor files from Docker builds. This will significantly reduce build context size and build times. No issues identified.

frontend/dockerfile.production (1)

51-51: Verify Next.js build output directory.

Line 51 copies from /app/build, but Next.js default output is .next/, not build/. If your build generates .next/, this COPY will fail silently, leaving an empty nginx directory.

Verify the correct output directory by checking your Next.js build output, then update the path accordingly:

-COPY --from=builder /app/build /usr/share/nginx/html
+COPY --from=builder /app/.next/static /usr/share/nginx/html/_next/static
+COPY --from=builder /app/public /usr/share/nginx/html

(Adjust based on your actual build output structure.)

backend/dockerfile (1)

15-15: Ignore this review comment—the assumption is incorrect.

The backend/start script exists in the repository and is properly included in the Docker build. The Dockerfile correctly copies the entire backend directory (line 9) before executing chmod +x ./start (line 15), so the file is present when the chmod command runs. No validation issue exists.

Likely an incorrect or invalid review comment.


RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Port mismatch: Dockerfile exposes 5000, but docker-compose maps 8000.

Line 13 exposes port 5000, but docker-compose.yml (line 33) maps "8000:8000". Typically, the Dockerfile exposes the application's internal port, and docker-compose maps it to a host port. This inconsistency suggests either:

  • The backend actually runs on port 8000 (update Dockerfile to EXPOSE 8000), or
  • The compose should map "5000:5000" if the app runs on 5000.

Clarify and align the port definitions.


🏁 Script executed:

#!/bin/bash
# Verify the Dockerfile content
echo "=== backend/dockerfile ==="
cat backend/dockerfile

echo -e "\n=== docker-compose.yml ==="
cat docker-compose.yml

echo -e "\n=== Check ./start script ==="
ls -la backend/start 2>/dev/null || echo "File not found: backend/start"

echo -e "\n=== Check requirements.txt ==="
ls -la backend/requirements.txt 2>/dev/null || echo "File not found: backend/requirements.txt"

Length of output: 2198


🏁 Script executed:

#!/bin/bash
# Check the start script to determine actual application port
echo "=== backend/start script content ==="
cat backend/start

echo -e "\n=== Check backend/.env or similar config ==="
ls -la backend/.env* 2>/dev/null || echo "No .env files found in backend/"

# Search for port configuration in backend Python files
echo -e "\n=== Search for port configuration in backend code ==="
rg -n "port|PORT|5000|8000" backend/ --type=py -C2 | head -50

Length of output: 4303


🏁 Script executed:

#!/bin/bash
# Search for app.run() calls to see port configuration
echo "=== Search for app.run() calls ==="
rg -n "app\.run\(" backend/ --type=py -C3

echo -e "\n=== Check create_app function ==="
fd "app\.py" backend/ --type f | xargs -I {} sh -c 'echo "=== {} ===" && head -100 {}'

echo -e "\n=== Search for Flask config with port/host ==="
rg -n "host|port|PORT|HOST" backend/ --type=py | grep -i "run\|config\|listen" | head -20

Length of output: 629


Port mismatch: Dockerfile exposes 5000, but docker-compose maps 8000:8000.

Flask application defaults to port 5000 (no explicit port in app.run(debug=True) at backend/spherre/wsgi.py line 8). The Dockerfile correctly exposes port 5000, but docker-compose.yml line 38 maps "8000:8000", which expects the application on port 8000. This inconsistency will make the backend unreachable.

Fix one of the following:

  • Change docker-compose mapping to "5000:8000" (container port 5000 → host port 8000), or
  • Change Dockerfile to EXPOSE 8000 and configure Flask to listen on 8000
🤖 Prompt for AI Agents
In backend/dockerfile around line 13, EXPOSE 5000 conflicts with docker-compose
mapping of 8000:8000 (service expects container port 8000). Update either the
compose mapping to forward host port 8000 to container port 5000 (use
"8000:5000"), or change Dockerfile to EXPOSE 8000 and configure the Flask app
(backend/spherre/wsgi.py) to listen on port 8000 so ports match.

Comment on lines +18 to +19
env_file:
- ./backend/.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Clarify env_file path and ensure consistency across services.

Line 18–19 specifies env_file: - ./backend/.env for the db service. However:

  1. Backend service (line 21–33) has no env_file specified—it won't inherit environment variables from .env unless they're passed explicitly.
  2. Frontend service (line 35–46) also has no env_file specified—it needs build-time environment variables (e.g., API endpoint).

Decide on a single .env location (root .env or service-specific) and apply it consistently to all services that need it. Example:

   db:
-    env_file:
-      - ./backend/.env
+    env_file:
+      - .env

   backend:
     ...
+    env_file:
+      - .env

   frontend:
     ...
+    env_file:
+      - .env

Document the .env file structure and required variables.


I'll verify the review comment by examining the docker-compose.yml file and checking the environment setup in the repository.


🏁 Script executed:

#!/bin/bash
# Check docker-compose.yml structure and content
if [ -f "docker-compose.yml" ]; then
  echo "=== docker-compose.yml content ==="
  cat docker-compose.yml
else
  echo "docker-compose.yml not found at root"
  fd "docker-compose.yml"
fi

Length of output: 1741


🏁 Script executed:

#!/bin/bash
# Search for .env files in the repository
echo "=== .env files found ==="
fd -e env$ -type f
fd "\.env" -type f

Length of output: 366


🏁 Script executed:

#!/bin/bash
# Check directory structure for backend and frontend
echo "=== Directory structure ==="
find . -maxdepth 2 -type d \( -name "backend" -o -name "frontend" -o -name ".env*" \) | head -20

Length of output: 48


🏁 Script executed:

#!/bin/bash
# Check if .env files exist at expected locations
echo "=== Checking .env file locations ==="
ls -la .env 2>&1 || echo ".env not found at root"
ls -la ./backend/.env 2>&1 || echo ".env not found at ./backend/"
ls -la ./frontend/.env 2>&1 || echo ".env not found at ./frontend/"

Length of output: 295


🏁 Script executed:

#!/bin/bash
# Extract lines 18-46 from docker-compose.yml to see the full context
echo "=== Lines 18-46 from docker-compose.yml ==="
sed -n '18,46p' docker-compose.yml

Length of output: 735


🏁 Script executed:

#!/bin/bash
# Check if there are any README or documentation files explaining .env setup
echo "=== Environment/setup documentation ==="
fd -e md | xargs grep -l "env" 2>/dev/null | head -5

Length of output: 67


🏁 Script executed:

#!/bin/bash
# Look for .env.example or .env.sample files
echo "=== Example env files ==="
fd -i "env" -type f | grep -E "(example|sample|template|\.env)" | head -10

Length of output: 196


🏁 Script executed:

#!/bin/bash
# Check docker-compose syntax and structure more carefully
echo "=== Full docker-compose.yml ==="
head -60 docker-compose.yml

Length of output: 1490


🏁 Script executed:

#!/bin/bash
# Determine working directory context for docker-compose paths
echo "=== Current directory structure ==="
ls -la

Length of output: 1068


🏁 Script executed:

#!/bin/bash
# Check for any build configuration or Dockerfiles
echo "=== Dockerfile locations ==="
fd "Dockerfile" -type f

Length of output: 199


🏁 Script executed:

#!/bin/bash
# Look for environment variable usage in backend and frontend directories
echo "=== Backend structure ==="
ls -la backend/ 2>/dev/null || echo "backend directory not found"
echo ""
echo "=== Frontend structure ==="
ls -la frontend/ 2>/dev/null || echo "frontend directory not found"

Length of output: 2219


🏁 Script executed:

#!/bin/bash
# Check if compose file references any environment variables
echo "=== Grep for env_file in docker-compose.yml ==="
rg -n "env_file" docker-compose.yml
echo ""
echo "=== Grep for environment in docker-compose.yml ==="
rg -n "environment:" docker-compose.yml

Length of output: 155


🏁 Script executed:

#!/bin/bash
# Get complete docker-compose.yml with line numbers for precise context
echo "=== Full docker-compose.yml with line numbers ==="
cat -n docker-compose.yml

Length of output: 2288


🏁 Script executed:

#!/bin/bash
# Check root directory contents
pwd
ls -la

Length of output: 1051


🏁 Script executed:

#!/bin/bash
# Verify paths work correctly from docker-compose location
echo "=== Path verification from docker-compose.yml directory ==="
cd "$(dirname docker-compose.yml || echo '.')"
pwd
ls -la ./backend/.env 2>&1 || echo "./backend/.env not accessible from here"
ls -la .env 2>&1 || echo ".env not accessible from here"

Length of output: 262


🏁 Script executed:

#!/bin/bash
# Check for docker-compose override files
echo "=== Docker-compose related files ==="
fd "docker-compose" -type f

Length of output: 207


🏁 Script executed:

#!/bin/bash
# List all files in root directory
echo "=== Root directory contents ==="
ls -la | head -30

Length of output: 1064


🏁 Script executed:

#!/bin/bash
# Search for .env anywhere
echo "=== All .env* files ==="
find . -name ".env*" -type f 2>/dev/null

Length of output: 46


🏁 Script executed:

#!/bin/bash
# Final check: show actual backend and frontend service definitions
echo "=== Services in docker-compose.yml ==="
rg -n "^\s*(db|backend|frontend):" docker-compose.yml -A 20

Length of output: 1556


🏁 Script executed:

#!/bin/bash
# Check for env_file path resolution docs
echo "=== Docker-compose version and context ==="
head -5 docker-compose.yml

Length of output: 125


🏁 Script executed:

#!/bin/bash
# Get backend and frontend service definitions more precisely
echo "=== Service definitions ==="
sed -n '/^  db:/,/^  [a-z]/p' docker-compose.yml
echo "---"
sed -n '/^  backend:/,/^  [a-z]/p' docker-compose.yml
echo "---"
sed -n '/^  frontend:/,/^  [a-z]/p' docker-compose.yml

Length of output: 1162


🏁 Script executed:

#!/bin/bash
# List ALL files to understand repository structure
echo "=== Repository structure ==="
find . -maxdepth 3 -type f | sort | head -50

Length of output: 1255


🏁 Script executed:

#!/bin/bash
# Get first 100 lines of docker-compose.yml
head -100 docker-compose.yml

Length of output: 1706


🏁 Script executed:

#!/bin/bash
# Final comprehensive check
echo "=== COMPREHENSIVE CHECK ==="
echo "pwd: $(pwd)"
echo ""
echo "Files in current directory:"
ls -la
echo ""
echo "docker-compose.yml exists: $([ -f docker-compose.yml ] && echo YES || echo NO)"
echo ""
if [ -f docker-compose.yml ]; then
  wc -l docker-compose.yml
  echo ""
  cat docker-compose.yml
fi

Length of output: 2876


🏁 Script executed:

#!/bin/bash
# Alternative: check git to see what files changed
echo "=== Git status and recent changes ==="
git status 2>/dev/null || echo "Not a git repo"
git diff HEAD -- docker-compose.yml 2>/dev/null || echo "No git diff available"

Length of output: 234


Remove the incorrect path reference and establish consistent env_file usage across all services.

The review comment is valid but requires refinement. Current state:

  • db service references non-existent ./backend/.env (only .env.example exists)
  • backend and frontend services lack env_file entirely despite likely needing environment variables
  • db service also defines placeholder variables (${DB_USER}, ${DB_PASSWORD}, ${DB_NAME}) with no source

The path ./backend/.env is inappropriate for the db service. Instead, establish a root .env and apply consistently:

   db:
-    env_file:
-      - ./backend/.env
+    env_file:
+      - .env

   backend:
     build:
       context: ./
       dockerfile: ./backend/dockerfile
+    env_file:
+      - .env

   frontend:
     build:
       context: ./
       dockerfile: ./frontend/dockerfile
+    env_file:
+      - .env

Create .env at repository root with required variables (example based on current usage):

DB_USER=postgres
DB_PASSWORD=<secure_password>
DB_NAME=<database_name>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
env_file:
- ./backend/.env
db:
env_file:
- .env
backend:
build:
context: ./
dockerfile: ./backend/dockerfile
env_file:
- .env
frontend:
build:
context: ./
dockerfile: ./frontend/dockerfile
env_file:
- .env
🤖 Prompt for AI Agents
In docker-compose.yml around lines 18-19, the db service incorrectly references
./backend/.env (which doesn't exist) and only the db uses env_file while
backend/frontend lack any, leaving ${DB_USER}/${DB_PASSWORD}/${DB_NAME}
undefined; fix by removing the ./backend/.env reference, create a
repository-root .env containing DB_USER, DB_PASSWORD, DB_NAME (and any other
shared vars), and update docker-compose.yml to add env_file: - ./.env to the db,
backend, and frontend services so all services pull their environment from the
same root .env and the placeholder variables resolve correctly.

dockerfile: ./backend/dockerfile
volumes:
- ./backend:/home/spherre_backend/src
- /var/run/docker.sock:/var/run/docker.sock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Remove docker.sock mounts unless explicitly needed.

Lines 28 and 42 mount /var/run/docker.sock into both backend and frontend containers. This grants the containers full Docker daemon access—a significant security risk.

Clarify why each service needs docker.sock access:

  • Backend: If needed for CI/CD or internal orchestration, document it and consider using a more restricted socket (e.g., rootless Docker or a socket proxy).
  • Frontend: It's unusual for a frontend dev/build service to need Docker access. Remove unless there's a specific reason (e.g., integration tests).

If not essential, remove these mounts to reduce attack surface.

Also applies to: 42-42


I'll examine the docker-compose.yml file and related configuration to validate the security concerns raised in the review comment.


---

🏁 Script executed:

```shell
#!/bin/bash
# Retrieve docker-compose.yml to inspect docker.sock mounts and service configuration
if [ -f "docker-compose.yml" ]; then
  cat docker-compose.yml
elif [ -f "docker-compose.yaml" ]; then
  cat docker-compose.yaml
else
  echo "docker-compose file not found in root directory"
  find . -maxdepth 3 -name "docker-compose*" -type f 2>/dev/null
fi

Length of output: 1706


🏁 Script executed:

#!/bin/bash
# Search for any documentation or comments explaining docker socket usage
rg -n "docker\.sock|docker daemon" --type yaml --type md -C 3

Length of output: 758


🏁 Script executed:

#!/bin/bash
# Check if there are any build scripts or CI/CD configs that might explain the need
fd -e "Dockerfile" -e "docker-compose*" -e "*.sh" | head -20

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Look for any comments or documentation in the repository root about Docker setup
ls -la | grep -i readme
[ -f "README.md" ] && head -100 README.md

Length of output: 3792


🏁 Script executed:

#!/bin/bash
# Examine frontend and backend service definitions more closely
rg -n "frontend|backend" --type yaml -C 5 | head -80

Length of output: 1525


Now I need to check if the backend and frontend code actually use Docker daemon access. Let me search for Docker-related imports and usage.


---

🏁 Script executed:

```shell
#!/bin/bash
# Search for Docker library imports in backend
echo "=== Checking backend for Docker library usage ==="
rg -n "import docker|from docker|Docker" backend/ --type py -C 2

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Search for Docker usage in frontend
echo "=== Checking frontend for Docker library usage ==="
rg -n "docker" frontend/ --type ts --type tsx --type js --type jsx -C 2

Length of output: 78


🏁 Script executed:

#!/bin/bash
# Inspect backend dockerfile to understand what the service does
echo "=== Backend Dockerfile ==="
if [ -f "backend/dockerfile" ]; then
  cat backend/dockerfile
fi

Length of output: 267


🏁 Script executed:

#!/bin/bash
# Inspect frontend dockerfile
echo "=== Frontend Dockerfile ==="
if [ -f "frontend/dockerfile" ]; then
  cat frontend/dockerfile
fi

Length of output: 375


🏁 Script executed:

#!/bin/bash
# Check backend source for any subprocess or container orchestration
echo "=== Checking for subprocess/container orchestration in backend ==="
rg -n "subprocess|popen|exec|system|docker|container" backend/ --type py -C 2 | head -100

Length of output: 8798


Remove unnecessary docker.sock mounts—no code justification found.

Lines 28 and 42 mount /var/run/docker.sock into both backend and frontend containers. After inspecting the codebase:

  • Backend: Flask service with no Docker library imports or daemon interactions detected
  • Frontend: Next.js dev server with no Docker usage detected

Neither service has a legitimate reason for Docker daemon access. These mounts should be removed immediately to reduce the attack surface.

🤖 Prompt for AI Agents
In docker-compose.yml around lines 28 and 42, the docker.sock mount
(/var/run/docker.sock:/var/run/docker.sock) is unnecessary for both backend and
frontend services and increases attack surface; remove those volume mounts from
both service definitions so containers no longer bind the host Docker daemon,
then run docker-compose config to validate the file and ensure no other services
require docker.sock before merging.

image: apibara/starknet:7a540aab7addef4fc20e67224570185748fd3919
container_name: apibara
command: >
--rpc https://starknet-sepolia.infura.io/v3/YOUR_INFURA_KEY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Replace hardcoded INFURA_KEY placeholder with environment variable.

Line 52 contains YOUR_INFURA_KEY as a literal string in the indexer command. This will fail at runtime. Instead, inject the key via an environment variable:

     command: >
-      --rpc https://starknet-sepolia.infura.io/v3/YOUR_INFURA_KEY
+      --rpc https://starknet-sepolia.infura.io/v3/${INFURA_KEY}
       --sink mongo
       --sink-url mongodb://mongo:27017/apibara
     environment:
       - LOG_LEVEL=info
+      - INFURA_KEY=${INFURA_KEY}

Then document that INFURA_KEY must be set in the .env file or passed at runtime.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
--rpc https://starknet-sepolia.infura.io/v3/YOUR_INFURA_KEY
command: >
--rpc https://starknet-sepolia.infura.io/v3/${INFURA_KEY}
--sink mongo
--sink-url mongodb://mongo:27017/apibara
environment:
- LOG_LEVEL=info
- INFURA_KEY=${INFURA_KEY}
🤖 Prompt for AI Agents
In docker-compose.yml around line 52, the indexer command contains the literal
YOUR_INFURA_KEY which will fail at runtime; replace that hardcoded string with
the environment variable reference (e.g., use ${INFURA_KEY}) so Docker injects
the real key at startup, ensure the service's environment or an env_file
includes INFURA_KEY, and update README/.env docs to state that INFURA_KEY must
be set in the .env file or passed at runtime.

apt-get install -y python3 make g++ && \
rm -rf /var/lib/apt/lists/*

COPY frontend/package.json ./
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Copy package-lock.json for reproducible builds.

Line 9 copies only package.json. For reproducible installs, also copy package-lock.json (or yarn.lock) to leverage npm ci instead of install, which uses locked versions.

-COPY frontend/package.json ./
+COPY frontend/package.json frontend/package-lock.json* ./

Then use npm ci --prefer-offline instead of npm install --force on line 13 to ensure deterministic builds.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COPY frontend/package.json ./
COPY frontend/package.json frontend/package-lock.json* ./
🤖 Prompt for AI Agents
In frontend/dockerfile around line 9, the Dockerfile currently copies only
package.json which prevents deterministic installs; copy package-lock.json (or
yarn.lock if you use Yarn) alongside package.json so the lockfile is available
in the image, then change the install step to use npm ci --prefer-offline
(instead of npm install --force) to perform a reproducible, locked install.

Comment on lines +11 to +13
ENV TURBO_DISABLED=1

RUN npm install -g turbo && npm install --force
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Contradictory Turbo configuration—either use it or remove it.

Line 11 sets ENV TURBO_DISABLED=1 to disable Turbo caching, but line 13 installs it globally with npm install -g turbo. If Turbo is disabled, installing it is unnecessary overhead. If Turbo is needed, remove the TURBO_DISABLED=1 setting.

Also, npm install --force on line 13 bypasses peer dependency conflicts and can mask dependency issues. Avoid --force unless peer dependencies genuinely conflict; first diagnose why conflicts exist.

🤖 Prompt for AI Agents
In frontend/dockerfile around lines 11–13, ENV TURBO_DISABLED=1 conflicts with
installing turbo globally and npm install --force masks peer-dependency
problems; either remove the ENV TURBO_DISABLED=1 line if you intend to use
turbo, or remove the npm install -g turbo line if you intend to keep turbo
disabled, and in both cases replace npm install --force with a plain npm install
after resolving peer dependency issues (or explicitly add necessary dependency
fixes) so you don't bypass conflicts.

@@ -0,0 +1,54 @@
# Multi-stage Dockerfile for a React frontend
# Stage 1: build
FROM node:18-alpine AS builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Node version mismatch between dev and production Dockerfiles.

The development Dockerfile (line 1 of frontend/dockerfile) uses node:22-bullseye-slim, but this production Dockerfile uses node:18-alpine. Version differences can cause build inconsistencies, different transpilation behavior, and unexpected runtime differences.

Align both Dockerfiles to the same Node.js LTS version, or document why they differ.


I'll verify the claims in this review comment by examining the development Dockerfile and checking the build configuration.


---

🏁 Script executed:

```shell
#!/bin/bash
# Check the development Dockerfile for Node.js version
fd -t f "^dockerfile$" frontend/ && cat frontend/dockerfile | head -20

Length of output: 340


🏁 Script executed:

#!/bin/bash
# Search for Next.js build output configuration
rg -nP "output.*dir|\.next|build.*dir" --type=json --type=js --type=ts frontend/ -C2 | head -50

Length of output: 250


🏁 Script executed:

#!/bin/bash
# Check if there's a next.config file specifying build output
fd -t f "next\.config" frontend/

Length of output: 23



---

🏁 Script executed:

```shell
#!/bin/bash
# View full production Dockerfile to check line 51 and build paths
cat frontend/dockerfile.production

Length of output: 1660


🏁 Script executed:

#!/bin/bash
# Check next.config.ts for custom build output configuration
cat frontend/next.config.ts | head -40

Length of output: 584


Node.js version mismatch AND incorrect build output directory in production Dockerfile.

Two critical issues:

  1. Node version mismatch: Development Dockerfile uses node:22-bullseye-slim but production uses node:18-alpine. Version differences cause build inconsistencies and unexpected runtime behavior. Align both to the same Node.js LTS version.

  2. Build output path error (line 51): The Dockerfile copies from /app/build, but Next.js outputs to /app/.next/ by default. Since next.config.ts has no custom output directory configuration, the production build will fail with no files to copy.

Fix line 51 to: COPY --from=builder /app/.next /usr/share/nginx/html (or verify if a custom build output is configured).

🤖 Prompt for AI Agents
In frontend/dockerfile.production around line 3 and referencing the COPY at line
51, the Dockerfile uses node:18-alpine which mismatches the development
Dockerfile (node:22-bullseye-slim) and the production COPY copies /app/build
while Next.js outputs to /app/.next by default; update the FROM to the same Node
LTS image used in development (e.g., node:22-bullseye-slim) and change the build
artifact copy to pull from /app/.next to the nginx html directory (or, if
next.config.ts defines a custom output, update the path to that custom directory
instead).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant