Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ target/

cover/
output.html

# mongo keyfile
keyfile
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Installation

```
openssl rand -base64 756 > keyfile
docker-compose build
docker-compose up
```
Expand Down
60 changes: 48 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
version: '3'
---
version: '3.8'

volumes:
mongo1_data:
mongo1_config:

services:
mongo:
image: mongo:7.0
container_name: mongo
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
MONGO_INITDB_DATABASE: test
# MONGODB_ROOT_PASSWORD: example
# MONGODB_REPLICA_SET_MODE: primary
# MONGODB_REPLICA_SET_NAME: rs0
# MONGODB_REPLICA_SET_KEY: replicaSetKey
entrypoint:
- bash
- -c
- |
cp /keyfile /mongo_keyfile
chmod 400 /mongo_keyfile
chown 999:999 /mongo_keyfile
exec docker-entrypoint.sh $$@
command: "mongod --bind_ip_all --replSet rs0 --keyFile /mongo_keyfile"

volumes:
- ./keyfile:/keyfile
- "mongo1_data:/data/db"
- "mongo1_config:/data/configdb"

mongo-setup:
image: mongo:7.0
container_name: mongo_setup
depends_on:
- mongo
restart: on-failure
entrypoint: ["/bin/bash", "/setup_mongo.sh"]
volumes:
- ./setup_mongo.sh:/setup_mongo.sh

api:
build:
context: .
dockerfile: Dockerfile
environment:
SANDBOX_MODE: 'True'
depends_on:
- mongo
mongo-setup:
condition: service_completed_successfully
volumes:
- "./src/openprocurement:/app/src/openprocurement:delegated"
- "./docs:/app/docs:delegated"
Expand All @@ -16,16 +62,6 @@ services:
- "8000:80"
command: ["gunicorn", "--bind", "0.0.0.0:80", "-k", "gevent", "--paste", "etc/service.ini", "--graceful-timeout=60", "--timeout=3600"]

mongo:
image: 'bitnami/mongodb:4.4.10'
environment:
MONGODB_ROOT_PASSWORD: example
MONGODB_REPLICA_SET_MODE: primary
MONGODB_REPLICA_SET_NAME: rs0
MONGODB_REPLICA_SET_KEY: replicaSetKey
ports:
- 27017:27017

# replica:
# image: 'bitnami/mongodb:latest'
# environment:
Expand Down
54 changes: 54 additions & 0 deletions setup_mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# TODO: This script assumes the following
# you named the container where your mongod runs 'mongo'
# you changed MONGO_INITDB_DATABASE to 'test'
# you set MONGO_INITDB_ROOT_USERNAME to 'root'
# you set MONGO_INITDB_ROOT_PASSWORD to 'example'
# you set the replica set name to 'rs0' (--replSet)
until mongosh --host mongo:27017 --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
printf '.'
sleep 1
done

cd /
echo '
try {
var config = {
"_id": "rs0", // TODO update this with your replica set name
"version": 1,
"members": [
{
"_id": 0,
"host": "mongo:27017", // TODO rename this host
"priority": 2
},
]
};
rs.initiate(config, { force: true });
rs.status();
sleep(5000);
// creates another user
admin = db.getSiblingDB("admin");
admin.createUser(
{
user: "otheradmin",
pwd: "othersecret",
roles: [ { role: "readWrite", db: "myowndb" },
{ role: "readWrite", db: "admin" } ,

]
}
);
} catch(e) {
rs.status().ok
}
' > /config-replica.js



sleep 10
# TODO update user, password, authenticationDatabase and host accordingly
mongosh -u root -p "example" --authenticationDatabase admin --host mongo:27017 /config-replica.js

# if the output of the container mongo_setup exited with code 0, everything is probably okay