-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
🧩 Problem
"It works on my machine" is a risk for a complex blockchain project like CropChain. Between different Node versions, OS-specific dependencies, and environment variables, setting up the project can be slow for new contributors.
Impact: Dockerization ensures that the environment in development, testing, and production (Ethereum/Polygon deployment) is 100% identical.
✨ Proposed Change
Create a multi-stage Dockerfile to optimize image size and a docker-compose.yml to orchestrate the Frontend, Backend, and a local MongoDB instance.
Technical Requirements:
- Dockerfile (Root/Production):
- Stage 1 (Base): Use
node:18-alpineas the base image. - Stage 2 (Builder): Install dependencies, copy source code, and run
npm run buildfor the React frontend. - Stage 3 (Runner): A slim production-ready image that only contains the necessary
/distfiles and Node.js runtime.
- Stage 1 (Base): Use
- Docker Compose:
- Define a
dbservice using the officialmongo:latestimage. - Define a
backendservice linked to the database. - Define a
frontendservice (Vite/React).
- Define a
- Environment Management:
- Ensure the Docker setup can read from a
.envfile for sensitive data (Infura URLs, Private Keys, MongoDB URI).
- Ensure the Docker setup can read from a
- Optimization:
- Add a
.dockerignorefile to excludenode_modules,build, and.gitfolders to keep the build context light.
- Add a
✅ Acceptance Criteria
- A functional
Dockerfileexists that builds both the client and server. - Running
docker-compose upstarts the DB, Backend, and Frontend simultaneously. - The Docker image is optimized (under 400MB).
- Documentation added to
README.mdunder a new "Docker Setup" section. - The app is accessible at
localhost:3000(Frontend) andlocalhost:3001(Backend) within the container network.
🛠️ Implementation Hint
For the Frontend build in Docker, remember to pass your VITE_ or REACT_APP_ environment variables during the build stage, otherwise, they won't be baked into the static files!
# Example Snippet
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run buildReactions are currently unavailable