Skip to content

Commit

Permalink
(BE) User registration / login (#51)
Browse files Browse the repository at this point in the history
* Add login logic

* Add MongoDB replica dockerfiles

* Add yorkie key for dev

* Implement login logic
  • Loading branch information
devleejb authored Jan 17, 2024
1 parent f8c318a commit f017796
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 12 deletions.
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

0 comments on commit f017796

Please sign in to comment.