From 080fd9caa31e366540aeaf420699b40ceed9cbec Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Wed, 29 Aug 2018 00:04:19 +0530 Subject: [PATCH 1/2] Added Dockerfile and shell scripts --- notebook/Dockerfile | 15 +++++++++++++++ notebook/INSTALL.sh | 14 ++++++++++++++ notebook/README.md | 21 ++++++++++++++++++--- notebook/START.sh | 7 +++++++ notebook/STOP.sh | 7 +++++++ notebook/requirements.txt | 3 +++ notebook/run.py | 5 ++++- 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 notebook/Dockerfile create mode 100644 notebook/INSTALL.sh create mode 100644 notebook/START.sh create mode 100644 notebook/STOP.sh create mode 100644 notebook/requirements.txt 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..4b3661b 100644 --- a/notebook/README.md +++ b/notebook/README.md @@ -8,14 +8,29 @@ 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 + +./INSTALL.sh ``` + +### Run FlaskApp + +Note: Except for the first time + +`./START.sh` + +### Terminate FlaskApp + +`./STOP.sh` + + Visit `localhost:5000` on your browser \ No newline at end of file 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 = [] From 0ac880717a118d8154b6498b72a40e3bc81f3f60 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Wed, 29 Aug 2018 16:06:06 +0530 Subject: [PATCH 2/2] Updated README.md --- notebook/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notebook/README.md b/notebook/README.md index 4b3661b..8eb83e4 100644 --- a/notebook/README.md +++ b/notebook/README.md @@ -19,6 +19,8 @@ git clone the repository cd into the repository/notebook +chmod +x *.sh + ./INSTALL.sh ``` @@ -33,4 +35,4 @@ Note: Except for the first time `./STOP.sh` -Visit `localhost:5000` on your browser \ No newline at end of file +Visit `localhost:5000` on your browser