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

(BE) User registration / login #51

Merged
merged 5 commits into from
Jan 17, 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
12 changes: 12 additions & 0 deletions backend/docker/mongodb_replica/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG MONGO_VERSION

FROM mongo:${MONGO_VERSION}

# we take over the default & start mongo in replica set mode in a background task
ENTRYPOINT mongod --port $MONGO_REPLICA_PORT --replSet rs0 --bind_ip 0.0.0.0 & MONGOD_PID=$!; \
# we prepare the replica set with a single node and prepare the root user config
INIT_REPL_CMD="rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: '$MONGO_REPLICA_HOST:$MONGO_REPLICA_PORT' }] })"; \
# we wait for the replica set to be ready and then submit the command just above
until ($MONGO_COMMAND admin --port $MONGO_REPLICA_PORT --eval "$INIT_REPL_CMD"); do sleep 1; done; \
# we are done but we keep the container by waiting on signals from the mongo task
echo "REPLICA SET ONLINE"; wait $MONGOD_PID;
24 changes: 24 additions & 0 deletions backend/docker/mongodb_replica/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**1. Build Docker Images:**

```bash
docker-compose build
```

This command builds the Docker images defined in the `docker-compose.yml` file. Ensure that the MongoDB image (specified as `mymongodb:latest`) is built using the Dockerfile provided earlier.

**2. Run Docker Containers:**

```bash
docker-compose up -d
```

This command starts the Docker containers defined in the `docker-compose.yml` file in detached mode (`-d`).

**3. Additional Information:**

- The `mongodb` service represents the MongoDB container, which is configured to run in replica set mode.
- The `mongo-init` service runs a command to initiate the replica set. It sleeps for 5 seconds to allow the MongoDB container to start before executing the initialization script (`init-replica-set.js`).
- The MongoDB container exposes port `27017`, and it is mapped to the host port `27017` for external access.
- The containers are connected to a custom network named `mynetwork` to enable communication between them.

**Note:** Ensure that you have Docker and Docker Compose installed on your system before executing these commands. Adjust the version numbers in the `docker-compose.yml` file if necessary.
25 changes: 25 additions & 0 deletions backend/docker/mongodb_replica/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.8"

services:
# This config is for MongoDB v4
# It's a Replica Set (required for Prisma Client)
mongo:
build:
context: ./
args:
MONGO_VERSION: 4
environment:
MONGO_REPLICA_HOST: 127.0.0.1
MONGO_REPLICA_PORT: 27017
# Use "mongosh" instead of "mongo" for v5+
MONGO_COMMAND: "mongo"
ports:
- "27017:27017"
restart: unless-stopped
healthcheck:
# Use "mongosh" instead of "mongo" for v5+
test:
["CMD", "mongo", "admin", "--port", "27017", "--eval", "db.adminCommand('ping').ok"]
interval: 5s
timeout: 2s
retries: 20
Loading
Loading