forked from 13somesh/MealMatters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Dockerfile-backend | ||
|
||
# Use Node.js as the base image | ||
FROM node:20 | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json | ||
COPY server/package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy the server directory and the startup script | ||
COPY server/ ./ | ||
COPY startup.sh ./ | ||
|
||
# Make the script executable | ||
RUN chmod +x startup.sh | ||
|
||
# Expose the backend port | ||
EXPOSE 5002 | ||
|
||
# Command to run the startup script | ||
CMD ["./startup.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Dockerfile-frontend | ||
|
||
# Use Node.js as the base image | ||
FROM node:20 | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json | ||
COPY client/package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy the client directory | ||
COPY client/ . | ||
|
||
# Expose the frontend port | ||
EXPOSE 5173 | ||
|
||
# Command to run the app | ||
CMD ["npm", "run", "dev"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Running the MealMatters Application with Docker Compose | ||
|
||
This guide will help you set up and run the MealMatters application using Docker and Docker Compose. It includes instructions for installing Docker on various operating systems, setting up the project, and running the application. | ||
|
||
## Installing Docker | ||
|
||
### Linux | ||
|
||
1. **Update your package index:** | ||
```bash | ||
sudo apt-get update | ||
``` | ||
2. **Install Docker:** | ||
```bash | ||
sudo apt-get install docker-ce docker-ce-cli containerd.io | ||
``` | ||
3. **Verify the installation:** | ||
```bash | ||
sudo docker run hello-world | ||
``` | ||
|
||
For detailed instructions, visit the [Docker installation guide for Linux](https://docs.docker.com/engine/install/ubuntu/). | ||
|
||
### Windows | ||
|
||
1. **Download Docker Desktop for Windows** from the [official Docker website](https://docs.docker.com/docker-for-windows/install/). | ||
2. **Run the installer** and follow the instructions. | ||
3. **Start Docker Desktop** from your applications or programs menu. | ||
|
||
### macOS | ||
|
||
1. **Download Docker Desktop for Mac** from the [official Docker website](https://docs.docker.com/docker-for-mac/install/). | ||
2. **Open the downloaded file** and drag the Docker icon to your Applications folder. | ||
3. **Start Docker Desktop** from your Applications folder. | ||
|
||
### Docker Compose | ||
|
||
Docker Compose should be automatically installed with Docker Desktop for Windows and macOS. For Linux, follow the instructions at [Install Docker Compose](https://docs.docker.com/compose/install/). | ||
|
||
## Project Structure | ||
|
||
Ensure your project directory is structured as follows: | ||
|
||
``` | ||
MealMatters/ | ||
│ | ||
├── client/ # Frontend source files | ||
│ ├── (frontend files) | ||
│ └── package.json | ||
│ | ||
├── server/ # Backend source files | ||
│ ├── (backend files) | ||
│ └── package.json | ||
│ | ||
├── Dockerfile-frontend # Dockerfile for the frontend | ||
├── Dockerfile-backend # Dockerfile for the backend | ||
├── docker-compose.yml # Docker Compose file | ||
└── startup.sh # Startup script for the backend | ||
``` | ||
|
||
## Dockerfiles and Docker Compose File | ||
|
||
Set up `Dockerfile-frontend`, `Dockerfile-backend`, `docker-compose.yml`, and `startup.sh` as previously outlined. | ||
|
||
## Running the Application | ||
|
||
1. **Build and Run with Docker Compose:** | ||
In your project's root directory, run: | ||
|
||
```bash | ||
docker-compose up --build | ||
``` | ||
2. **Accessing the Application:** | ||
- The frontend is available at `http://localhost:5173`. | ||
- The backend API is at `http://localhost:5000`. | ||
|
||
3. **Stopping the Application:** | ||
To stop, press `Ctrl+C`. To remove containers, run: | ||
|
||
```bash | ||
docker-compose down | ||
``` | ||
|
||
## Additional Notes | ||
|
||
- **JWT Secret:** Generated dynamically by `startup.sh` on each container start. Previous JWT tokens become invalid after each restart | ||
|
||
. | ||
- **Data Persistence:** MongoDB data persists in a Docker volume as defined in `docker-compose.yml`. | ||
- **Security:** Handle sensitive information carefully, especially in production. | ||
|
||
## Conclusion | ||
|
||
This guide provides a comprehensive overview of setting up and running the MealMatters application using Docker and Docker Compose. For more information or troubleshooting, refer to the [Docker documentation](https://docs.docker.com/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
version: '3.8' | ||
services: | ||
client: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile-frontend | ||
ports: | ||
- "5173:5173" | ||
depends_on: | ||
- server | ||
|
||
server: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile-backend | ||
ports: | ||
- "5000:5000" | ||
environment: | ||
- MONGO_URL=mongodb://mongo:27017/mealMatters | ||
- PORT=5000 | ||
depends_on: | ||
- mongo | ||
|
||
mongo: | ||
image: mongo:latest | ||
environment: | ||
- MONGO_INITDB_ROOT_USERNAME=mongoadmin | ||
- MONGO_INITDB_ROOT_PASSWORD=secret | ||
volumes: | ||
- mongodb_data:/data/db | ||
|
||
volumes: | ||
mongodb_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# Generate a new JWT secret | ||
export JWT_SECRET=$(openssl rand -base64 32) | ||
|
||
# Start the Node.js application | ||
npm start |