Skip to content

Commit

Permalink
Finished Docker files. Commands will be added to README.md/Documentat…
Browse files Browse the repository at this point in the history
…ion later.
  • Loading branch information
g0ulash committed Oct 19, 2017
1 parent 407f455 commit 453e315
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#FROM python:3.5-alpine
FROM python:3.5-jessie
ADD ./ /sb/
WORKDIR /sb/

#ARG PASS

#RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

Expand All @@ -10,11 +13,15 @@ ADD ./ /sb/

RUN pip install --upgrade pip

RUN pip install -r /sb/requirements.txt
#RUN pip install -r /sb/requirements.txt

WORKDIR /sb/app/
#CMD python3 ./insert_admin.py --password ${PASS}

RUN sed -i -e 's/redis_ip : localhost/redis_ip : redis/g' ./app/config.cfg
RUN sed -i -e 's/mongo_ip : localhost/mongo_ip : mongo/g' ./app/config.cfg

RUN sed -i -e 's/redis_ip : localhost/redis_ip : redis/g' ./config.cfg
RUN sed -i -e 's/mongo_ip : localhost/mongo_ip : mongo/g' ./config.cfg
RUN pip install .

WORKDIR /sb/app/

CMD ["python3", "./app.py"]
6 changes: 6 additions & 0 deletions docker-compose.front-end.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'
services:
sb-ui:
image: "nthiterationlab/streamingbandit-ui:latest"
ports:
- "80:80"
33 changes: 33 additions & 0 deletions insert_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
from pymongo import MongoClient
from bcrypt import hashpw, checkpw, gensalt
import yaml
import os
import argparse

def insert_admin():
dirs = os.listdir()
if 'app' in dirs:
f = open("app/config.cfg", 'r')
else:
f = open("./config.cfg", 'r')
settings = yaml.load(f)
mongo_client = MongoClient(settings['mongo_ip'], settings['mongo_port'])
mongo_db = mongo_client['userinfo']
userinfo = mongo_db['userinfo']
f.close()

parser = argparse.ArgumentParser(description = "Add admin user to MongoDB")
parser.add_argument('-p', '--password', type = str, help = "Admin password", required = True)

if userinfo.find({'username':'admin'}).count() > 0:
print("Admin already exists")
else:
args = parser.parse_args()
password = args.password
hashed = hashpw(password.encode('utf-8'), gensalt())
userinfo.insert_one({"username":"admin","password":hashed,"user_id":0})
print("Successfully added an admin user with password {}!".format(password))

if __name__ == "__main__":
insert_admin()

0 comments on commit 453e315

Please sign in to comment.