diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6677e3a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +backend +node_modules +dist +build +.gitignore +.git +.env.* +.github +yarn.lock \ No newline at end of file diff --git a/.gitignore b/.gitignore index 14256c2..41c6dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Node modules node_modules/ package-lock.json +*/yarn.lock +yarn.lock # Logs logs *.log diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..c3443bf --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,14 @@ +FROM node:20-alpine + +WORKDIR /app + + +COPY package.json . + +RUN npm install + +COPY . . + +EXPOSE 5173 + +CMD ["npm","run","dev"] diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..6fb1532 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,44 @@ +# Stage 1: Build the frontend +FROM node:20-alpine AS build + +# Set the working directory +WORKDIR /app + +# Copy package.json +COPY package.json . + +# Install production dependencies using Yarn +RUN npm install --production +# Copy the rest of the application files +COPY . . + +# Build the frontend using Yarn +RUN npm run build + +# Stage 2: Serve the application with Nginx +FROM nginx:alpine + +# Copy the build output from the previous stage to Nginx's serve directory +COPY --from=build /app/dist /usr/share/nginx/html + +# Remove the default Nginx configuration file +RUN rm /etc/nginx/conf.d/default.conf + +# Create a new Nginx configuration file +RUN echo $'\ +server { \n\ + listen 3000; \n\ + server_name localhost; \n\ + root /usr/share/nginx/html; \n\ + index index.html; \n\ + \n\ + location / { \n\ + try_files $uri $uri/ /index.html; \n\ + } \n\ +}' > /etc/nginx/conf.d/default.conf + +# Expose port 3000 +EXPOSE 3000 + +# Start Nginx +CMD ["nginx", "-g", "daemon off;"] diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..352bc33 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,5 @@ +node_modules +.gitignore +.git +.env.* +yarn.lock \ No newline at end of file diff --git a/backend/Dockerfile.dev b/backend/Dockerfile.dev new file mode 100644 index 0000000..1cdb258 --- /dev/null +++ b/backend/Dockerfile.dev @@ -0,0 +1,20 @@ +# Use a lightweight Node.js Alpine image +FROM node:20-alpine + +# Set the working directory +WORKDIR /app + +# Copy package.json and yarn.lock files for dependency installation +COPY package.json ./ + +# Install all dependencies using Yarn +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Expose the port for the application +EXPOSE 5000 + +# Start the server in dev mode using Yarn +CMD ["npm","run", "dev"] diff --git a/backend/Dockerfile.prod b/backend/Dockerfile.prod new file mode 100644 index 0000000..9f35a10 --- /dev/null +++ b/backend/Dockerfile.prod @@ -0,0 +1,20 @@ +# Use a lightweight Node.js Alpine image +FROM node:20-alpine + +# Set the working directory +WORKDIR /app + +# Copy package.json and yarn.lock files for dependency installation +COPY package.json ./ + +# Install production dependencies using Yarn +RUN npm install --production + +# Copy the rest of the application files +COPY . . + +# Expose the port for the application +EXPOSE 5000 + +# Start the server in production mode using Yarn +CMD ["npm","run", "start"] diff --git a/backend/package.json b/backend/package.json index 53bd64b..9891c08 100644 --- a/backend/package.json +++ b/backend/package.json @@ -3,7 +3,8 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "start": "nodemon server.js", + "dev": "nodemon server.js", + "start": "node server.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e2cdd0f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,70 @@ +services: + frontend: + image: frontend + container_name: frontend-container + build: + context: . + dockerfile: Dockerfile.dev + ports: + - "5173:5173" + env_file: + - .env + volumes: + - .:/app + - /app/node_modules + depends_on: + - backend + networks: + - app-network-1 + profiles: + - dev + backend: + image: backend + container_name: backend-container + build: + context: ./backend + dockerfile: Dockerfile.dev + ports: + - "5000:5000" + env_file: + - ./backend/.env + volumes: + - ./backend:/app + - /app/node_modules + networks: + - app-network-1 + profiles: + - dev + frontend-prod: + image: frontend-prod + container_name: frontend-prod-container + build: + context: . + dockerfile: Dockerfile.prod + ports: + - "3000:3000" + env_file: + - .env + depends_on: + - backend-prod + networks: + - app-network-2 + profiles: + - prod + backend-prod: + image: backend-prod + container_name: backend-prod-container + build: + context: backend + dockerfile: Dockerfile.prod + ports: + - "5000:5000" + env_file: + - backend/.env + networks: + - app-network-2 + profiles: + - prod +networks: + app-network-1: + app-network-2: diff --git a/package.json b/package.json index 7b1e40b..d51abfc 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "lint": "eslint .", - "preview": "vite preview" + "preview": "vite preview", + "docker:dev":"docker compose --profile dev up --build", + "docker:prod":"docker compose --profile prod up -d --build" }, "dependencies": { "@emotion/react": "^11.11.3", @@ -22,7 +24,10 @@ "react-dom": "^18.3.1", "react-hot-toast": "^2.4.1", "react-icons": "^5.3.0", - "react-router-dom": "^6.28.0" + "react-router-dom": "^6.28.0", + "postcss": "^8.4.47", + "autoprefixer": "^10.4.20", + "tailwindcss": "^3.4.14" }, "devDependencies": { "@eslint/js": "^9.13.0", @@ -44,9 +49,7 @@ "jasmine": "^5.9.0", "passport": "^0.7.0", "passport-local": "^1.0.0", - "postcss": "^8.4.47", "supertest": "^7.1.4", - "tailwindcss": "^3.4.14", "vite": "^5.4.10" } }