Skip to content
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

feat: add Docker Compose for next-app & websockets. #121

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing

Thank you for your interest in contributing to this repository. To ensure a smooth and collaborative environment, please follow these guidelines. Before contributing, set up the project locally using the steps outlined in [README.md](./README.md).

## Why these guidelines ?

Our goal is to create a healthy and inclusive space for contributions. Remember that open-source contribution is a collaborative effort, not a competition.

## General guidelines

- Work only on one issue at a time since it will provide an opportunity for others to contribute as well.

- Note that each open-source repository generally has its own guidelines, similar to these. Always read them before starting your contributions.

## How to get an issue assigned

- To get an issue assigned, provide a small description as to how you are planning to tackle this issue.

> Ex - If the issue is about UI changes, you should create a design showing how you want it to look on the UI (make it using figma, paint, etc)

- This will allow multiple contributors to discuss their approach to tackle the issue. The maintainer will then assign the issue.

## After getting the issue assigned

- Create your own branch instead of working directly on the main branch.

- Provide feedback every 24-48 hours if an issue is assigned to you. Otherwise, it may be reassigned.

- When submitting a pull request, please provide a screenshot or a screen-recording showcasing your work.

## Don't while contributing

- Avoid comments like "Please assign this issue to me" or "can i work on this issue ?"

- Refrain from tagging the maintainer to assign issues or review pull requests.

- Don't make any pull request for issues you are not assigned to. It will be closed without merging.

Happy Contributing!
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<h1 align='center'>Muzer - 100xDevs</h1>

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [With Docker](#with-docker)
- [Without Docker](#without-docker)
- [Usage](#usage)
- [Contributing](#contributing)
- [Contributors](#contributors)

## Installation

### With Docker

1. Clone the repository:
```bash
git clone https://github.com/code100x/muzer.git
```

2. Navigate to the project directory:
```bash
cd muzer
```

3. Create a `.env` file based on the `.env.example` file and configure everything in both the `next-app` and `ws` folders.

4. Run the following command to start the application:
```bash
docker compose --env-file ./next-app/.env --env-file ./ws/.env up -d
```

### Without Docker

1. Clone the repository:
```bash
git clone https://github.com/code100x/muzer.git
```

2. Navigate to the project directory:
```bash
cd muzer
```

3. Now Install the dependencies:
```bash
cd next-app
pnpm install
cd ..
cd ws
pnpm install
```
4. Create a `.env` file based on the `.env.example` file and configure everything in both the `next-app` and `ws` folders.

5. For postgres, you need to run the following command:
```bash
docker run -d \
--name muzer-db \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
-e POSTGRES_DB=mydatabase \
-p 5432:5432 \
postgres
```

6. For redis, you need to run the following command:
```bash
docker run -d \
--name muzer-redis \
-e REDIS_USERNAME=admin \
-e REDIS_PASSWORD=root \
-e REDIS_PORT=6379 \
-e REDIS_HOST="127.0.0.1" \
-e REDIS_BROWSER_STACK_PORT=8001 \
redis/redis-stack:latest
```

7. Now do the following:
```bash
cd next-app
pnpm postinstall
cd ..
cd ws
pnpm postinstall
```

8. Run the following command to start the application:
```bash
cd next-app
pnpm dev
cd ..
cd ws
pnpm dev
```

9. To access the prisma studio, run the following command:
```bash
cd next-app
pnpm run prisma:studio
```

## Usage

1. Access the application in your browser at http://localhost:3000
2. Access the redis stack at http://localhost:8001/redis-stack/browser
3. Access the prisma studio at http://localhost:5555

## Contributing

We welcome contributions from the community! To contribute to Muzer, follow these steps:

1. Fork the repository.

2. Create a new branch (`git checkout -b feature/fooBar`).

3. Make your changes and commit them (`git commit -am 'Add some fooBar'`).

4. Push to the branch (`git push origin -u feature/fooBar`).

5. Create a new Pull Request.

For major changes, please open an issue first to discuss what you would like to change.

Read our [contribution guidelines](./CONTRIBUTING.md) for more details.

## Contributors

<a href="https://github.com/code100x/muzer/graphs/contributors">
<img src="https://contrib.rocks/image?repo=code100x/muzer" />
</a>

If you continue to face issues, please open a GitHub issue with details about the problem you're experiencing.
107 changes: 107 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
services:
app:
container_name: muzer-docker
build:
context: ./next-app/
dockerfile: Dockerfile.dev
env_file:
- path: ./next-app/.env
ports:
- ${APP_PORT}:3000
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
develop:
watch:
- action: sync
path: ./next-app
target: /usr/src/app
ignore:
- node_modules/
- action: rebuild
path: ./next-app/package.json
target: /usr/src/app
ignore:
- node_modules/

postgres:
container_name: prisma-postgres
image: postgres:alpine
restart: always
env_file:
- path: ./next-app/.env
ports:
- ${POSTGRES_PORT}:5432
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5

prisma-studio:
container_name: prisma-studio
image: timothyjmiller/prisma-studio:latest
restart: unless-stopped
env_file:
- path: ./next-app/.env
depends_on:
- app
ports:
- ${PRISMA_STUDIO_PORT}:5555

redis:
container_name: redis-server
image: redis/redis-stack:latest
restart: always
env_file:
- path: ./ws/.env
ports:
- ${REDIS_PORT}:6379
- ${REDIS_BROWSER_STACK_PORT}:8001
environment:
REDIS_ARGS: "--requirepass ${REDIS_PASSWORD} --user ${REDIS_USERNAME} on >${REDIS_PASSWORD} ~* allcommands --user default off nopass nocommands"
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5

websockets:
container_name: websockets
restart: always
build:
context: ./ws/
dockerfile: Dockerfile.dev
env_file:
- path: ./ws/.env
ports:
- ${PORT}:8080
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
develop:
watch:
- action: sync
path: ./ws
target: /usr/src/app
ignore:
- node_modules/
- action: rebuild
path: ./ws/package.json
target: /usr/src/app
ignore:
- node_modules/

volumes:
postgres-data:
external: false
redis-data:
external: false
4 changes: 3 additions & 1 deletion next-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.env
.git
.gitignore
.env.example
4 changes: 2 additions & 2 deletions next-app/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM node:22-alpine AS installer

WORKDIR /usr/src/app
RUN npm i pnpm -g
RUN corepack enable pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --ignore-scripts
COPY . .
Expand All @@ -12,6 +12,6 @@ RUN pnpm postinstall
FROM node:22-alpine AS dev

WORKDIR /usr/src/app
RUN npm i pnpm -g
RUN corepack enable pnpm
COPY --from=installer /usr/src/app/ ./
CMD [ "pnpm", "dev:docker" ]
4 changes: 2 additions & 2 deletions next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"lint": "next lint",
"prisma:studio": "npx prisma studio",
"postinstall": "prisma generate",
"prisma:migrate": "prisma migrate",
"dev:docker": "pnpm prisma:migrate && pnpm dev",
"prisma:migrate": "prisma migrate dev",
"dev:docker": "pnpm prisma:migrate & pnpm dev",
"format:fix": "prettier --write \"**/*.{ts,tsx,json}\"",
"format:check": "prettier --check \"**/*.{ts,tsx,json}\""
},
Expand Down
4 changes: 4 additions & 0 deletions ws/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.git
.gitignore
.env.example
5 changes: 3 additions & 2 deletions ws/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ DATABASE_URL=""

REDIS_USERNAME=""
REDIS_PORT=6379
REDIS_HOST="127.0.0.1"
REDIS_PASSWORD=""
REDIS_HOST="127.0.0.1" # for docker change it to "redis"
REDIS_PASSWORD=""
REDIS_BROWSER_STACK_PORT=8001
18 changes: 18 additions & 0 deletions ws/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:22-alpine AS installer

WORKDIR /usr/src/app
RUN corepack enable pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --ignore-scripts
COPY . .
RUN pnpm postinstall


FROM node:22-alpine AS dev

WORKDIR /usr/src/app
RUN corepack enable pnpm
COPY --from=installer /usr/src/app/ ./
CMD [ "pnpm", "dev" ]


5 changes: 3 additions & 2 deletions ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "ws",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "app.ts",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "nodemon src/app.ts",
"start": "node dist/app.js",
"build": "prisma generate && npx tsc -b"
"build": "pnpm postinstall && npx tsc -b",
"postinstall": "npx prisma generate"
},
"keywords": [],
"author": "",
Expand Down
Loading