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
24 changes: 23 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FROM node:10.16-alpine
FROM mysql:latest
ARG ROOT_PASSWORD=admin
ENV MYSQL_ROOT_PASSWORD=${ROOT_PASSWORD}
ARG SETUP_DATABASE=picpay_db
ENV MYSQL_DATABASE=${SETUP_DATABASE}
EXPOSE 3306
CMD ["mysqld"]

FROM node:10.16-alpine
EXPOSE 19000
EXPOSE 19001
EXPOSE 19002
Expand All @@ -10,5 +17,20 @@ RUN apk update && apk add
RUN npm install -g expo-cli
CMD npm i -f && npm start

FROM mongo:latest
ENV AUTH yes
ENV MONGODB_ADMIN_USER admin
ENV MONGODB_ADMIN_PASS admin
ENV MONGODB_APPLICATION_DATABASE picpay_db
ENV MONGODB_APPLICATION_USER picpay
ENV MONGODB_APPLICATION_PASS admin
EXPOSE 27017 27017
ADD run.sh /run.sh
ADD set_mongodb_password.sh /set_mongodb_password.sh
RUN chmod +x /run.sh
RUN chmod +x /set_mongodb_password.sh
CMD ["/run.sh"]




37 changes: 36 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,39 @@ services:
environment:
- EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
- REACT_NATIVE_PACKAGER_HOSTNAME=192.168.15.20
command: sh -c "npm start && w"
command: expo start --web
<<<<<<< HEAD

mongo:
container_name: picpay_mongo
build:
context: .
dockerfile: Dockerfile
environment:
- AUTH=yes
- MONGODB_ADMIN_USER=admin
- MONGODB_ADMIN_PASS=admin
- MONGODB_APPLICATION_DATABASE=picpay_db
- MONGODB_APPLICATION_USER=picpay
- MONGODB_APPLICATION_PASS=admin
ports:
- "27017:27017"

mysql:
container_name: picpay_mysql
build:
context: .
dockerfile: Dockerfile
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=picpay_db
- MYSQL_USER=admin
- MYSQL_PASSWORD=admin
- MYSQL_ALLOW_EMPTY_PASSWORD=false
- MYSQL_RANDOM_ROOT_PASSWORD=false
ports:
- "3306:3306"

=======
>>>>>>> 26b882c5b765189276c3dc4d3074cb3882d0397d
28 changes: 28 additions & 0 deletions mongodb_insert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("picpay_db");
var myobj = [
{ name: 'John', address: 'Highway 71'},
{ name: 'Peter', address: 'Lowstreet 4'},
{ name: 'Amy', address: 'Apple st 652'},
{ name: 'Hannah', address: 'Mountain 21'},
{ name: 'Michael', address: 'Valley 345'},
{ name: 'Sandy', address: 'Ocean blvd 2'},
{ name: 'Betty', address: 'Green Grass 1'},
{ name: 'Richard', address: 'Sky st 331'},
{ name: 'Susan', address: 'One way 98'},
{ name: 'Vicky', address: 'Yellow Garden 2'},
{ name: 'Ben', address: 'Park Lane 38'},
{ name: 'William', address: 'Central st 954'},
{ name: 'Chuck', address: 'Main Road 989'},
{ name: 'Viola', address: 'Sideway 1633'}
];
dbo.collection("customers").insertMany(myobj, function(err, res) {
if (err) throw err;
console.log("Number of documents inserted: " + res.insertedCount);
db.close();
});
});
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"chokidar": "^3.5.1",
"expo": "^41.0.0",
"expo-linear-gradient": "~8.1.0",
"mongodb": "^3.6.6",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
Expand Down
17 changes: 17 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -m

mongodb_cmd="mongod"
cmd="$mongodb_cmd"

if [ "$AUTH" == "yes" ]; then
cmd="$cmd --auth"
fi

$cmd &

if [ ! -f /data/db/.mongodb_password_set ]; then
/set_mongodb_password.sh
fi

fg
35 changes: 35 additions & 0 deletions set_mongodb_password.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

MONGODB_ADMIN_USER=${MONGODB_ADMIN_USER:-"admin"}
MONGODB_ADMIN_PASS=${MONGODB_ADMIN_PASS:-"admin"}

MONGODB_APPLICATION_DATABASE=${MONGODB_APPLICATION_DATABASE:-"picpay_db"}
MONGODB_APPLICATION_USER=${MONGODB_APPLICATION_USER:-"picpay"}
MONGODB_APPLICATION_PASS=${MONGODB_APPLICATION_PASS:-"admin"}

while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MongoDB service startup..."
sleep 5
mongo admin --eval "help" >/dev/null 2>&1
RET=$?
done

echo "=> Creating admin user with a password in MongoDB"
mongo admin --eval "db.createUser({user: '$MONGODB_ADMIN_USER', pwd: '$MONGODB_ADMIN_PASS', roles:[{role:'root',db:'admin'}]});"

sleep 3

if [ "$MONGODB_APPLICATION_DATABASE" != "admin" ]; then
echo "=> Creating a ${MONGODB_APPLICATION_DATABASE} database user with a password in MongoDB"
mongo admin -u $MONGODB_ADMIN_USER -p $MONGODB_ADMIN_PASS << EOF
echo "Using $MONGODB_APPLICATION_DATABASE database"
use $MONGODB_APPLICATION_DATABASE
db.createUser({user: '$MONGODB_APPLICATION_USER', pwd: '$MONGODB_APPLICATION_PASS', roles:[{role:'dbOwner', db:'$MONGODB_APPLICATION_DATABASE'}]})
EOF
fi

sleep 1

touch /data/db/.mongodb_password_set

echo "MongoDB configured successfully. You may now connect to the DB."