Install MongoDB
# Ubuntu 18.04 LTS
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt install mongodb-org
sudo systemctl enable mongod
sudo systemctl start mongod
# whitelist IPs : https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04
# Validate: mongo --eval 'db.runCommand({ connectionStatus: 1})'
Admin config
#1) disable security (/etc/mongod.conf) --> Restart Mongodb
#> security:
#> authorization: "disabled"
#2) drop admin user if exist
mongo admin --eval 'db.dropUser("superadmin")'
#3) create admin user
mongo admin --eval 'db.createUser( { user: "superadmin", pwd: "MyPass1234", roles: [ { role: "clusterAdmin", db: "admin" }, { role: "userAdminAnyDatabase", db: "admin" } ] } )'
#4) enable security (/etc/mongod.conf) --> Restart Mongodb
#> security:
#> authorization: "enabled"
App user config
mongo admin --eval 'db.createUser( { user: "todo", pwd: "todo", roles: [ { role: "readWrite", db: "test" } ] } )'
Network config
- Replace the value of bindIp in /etc/mongod.conf
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mongod.conf
- Install go
- Checkout source code
- Run
go build
Check connectivity with DB
nc -zv <db-hostname> 27017
From source code
export DB_CONNECTION=mongodb://user:pass@localhost:27017 \
DB_NAME=test
go run main.go
Or From build artifact
export DB_CONNECTION=mongodb://user:pass@localhost:27017 \
DB_NAME=test
/artifact-build-file
1 - Create Systemd Service Todo which populates (2) & manages (3)
-> notify: systemctl reload-daemon
2 - Put env vars in seperated file ( /etc/todo.env
)
3 - Move build file from /tmp/todo
to a standard place (/usr/local/bin/todo
)
-> notify: systemctl restart todo
- systemd service
- Install nodejs
- Checkout source code
- Run
npm install
# Set REACT_APP_API_ENDPOINT, then
npm start
npm install pm2 -g
# Set REACT_APP_API_ENDPOINT, then
# Start App with pm2
pm2 start node_modules/react-scripts/scripts/start.js --name todo