diff --git a/notebook/Dockerfile b/notebook/Dockerfile new file mode 100644 index 0000000..9d591b6 --- /dev/null +++ b/notebook/Dockerfile @@ -0,0 +1,15 @@ +FROM ubuntu:latest + +MAINTAINER Prashant Shahi "prashantshahi567@gmail.com" + +RUN apt-get update -y && \ + apt-get install -y python-pip python-dev build-essential + +COPY . /app +WORKDIR /app + +RUN pip install -r requirements.txt + +ENTRYPOINT ["python"] + +CMD ["run.py"] \ No newline at end of file diff --git a/notebook/INSTALL.sh b/notebook/INSTALL.sh new file mode 100644 index 0000000..f00552a --- /dev/null +++ b/notebook/INSTALL.sh @@ -0,0 +1,14 @@ + +# Building Docker Image for Flask App using the Dockerfile (using Ubuntu:latest) +docker build -t flaskapp:latest . + +# Downloading Light MongoDB container and building the image +docker pull mvertes/alpine-mongo + +# Making Containers of MongoDB Client Docker Image +docker run -d -p 27017:27017 --name mongoclient mvertes/alpine-mongo + +# Making Container of FlaskApp Docker Image and linking to Mongoclient Container +docker run -d -p 5000:5000 --link mongoclient --name flaskapp flaskapp:latest + +echo " * Notebook FlaskApp should be live at http://localhost:5000/" \ No newline at end of file diff --git a/notebook/README.md b/notebook/README.md index 4baba5f..8eb83e4 100644 --- a/notebook/README.md +++ b/notebook/README.md @@ -8,14 +8,31 @@ These instructions will get you a copy of the project up and running on your loc ### Pre-requisites -1. [Flask](http://flask.pocoo.org/docs/1.0/installation/) -2. [MongoDB](https://docs.mongodb.com/manual/installation/) +1. [Flask](http://flask.pocoo.org/) +2. [MongoDB](https://docs.mongodb.com/) +3. [Docker](https://docs.docker.com/install/) ### Installation ``` git clone the repository + cd into the repository/notebook -python run.py + +chmod +x *.sh + +./INSTALL.sh ``` -Visit `localhost:5000` on your browser \ No newline at end of file + +### Run FlaskApp + +Note: Except for the first time + +`./START.sh` + +### Terminate FlaskApp + +`./STOP.sh` + + +Visit `localhost:5000` on your browser diff --git a/notebook/START.sh b/notebook/START.sh new file mode 100644 index 0000000..b1d38cd --- /dev/null +++ b/notebook/START.sh @@ -0,0 +1,7 @@ +# Start MongoDB Client Docker Container +docker start mongoclient + +# Start FlaskApp Container +docker start flaskapp + +echo " * Notebook FlaskApp should be started at http://localhost:5000/ " \ No newline at end of file diff --git a/notebook/STOP.sh b/notebook/STOP.sh new file mode 100644 index 0000000..30f07b2 --- /dev/null +++ b/notebook/STOP.sh @@ -0,0 +1,7 @@ +# Start MongoDB Client Docker Container +docker stop mongoclient + +# Start FlaskApp Container +docker stop flaskapp + +echo " * Notebook FlaskApp should be stopped " \ No newline at end of file diff --git a/notebook/requirements.txt b/notebook/requirements.txt new file mode 100644 index 0000000..41374ec --- /dev/null +++ b/notebook/requirements.txt @@ -0,0 +1,3 @@ +FLASK==1.0.2 +BSON +PYMONGO \ No newline at end of file diff --git a/notebook/run.py b/notebook/run.py index a6b08cd..dce8742 100644 --- a/notebook/run.py +++ b/notebook/run.py @@ -1,12 +1,15 @@ +import os from flask import Flask, flash, render_template, redirect, request from bson.objectid import ObjectId from datetime import datetime from pymongo import MongoClient app = Flask(__name__) -client = MongoClient('mongodb://localhost:27017/') +client = MongoClient(os.environ['MONGOCLIENT_PORT_27017_TCP_ADDR'],27017) db = client.todo + +@app.route('/') @app.route('/note', methods=['GET']) def get_notes(): notes = []