From 6a800e561d50b409c373f7f851f24b16fb96ea4e Mon Sep 17 00:00:00 2001 From: Joaquin Menchaca Date: Fri, 23 Nov 2018 20:22:11 -0800 Subject: [PATCH] migration to seperate repo from web-microframework --- Brewfile | 1 + Dockerfile | 16 +++++++++++ README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++ Vagrantfile | 12 ++++++++ app.py | 17 ++++++++++++ chocolate.config | 5 ++++ docker-compose.yml | 9 ++++++ requirements.txt | 5 ++++ 8 files changed, 134 insertions(+) create mode 100644 Brewfile create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 Vagrantfile create mode 100755 app.py create mode 100644 chocolate.config create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..e4463f9 --- /dev/null +++ b/Brewfile @@ -0,0 +1 @@ +brew "python" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..642e293 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:2-onbuild + +# Create app directory +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# Install app dependencies +COPY requirements.txt /usr/src/app/ +RUN pip install -r requirements.txt + +# Bundle app source +COPY . /usr/src/app + +EXPOSE 5000 +ENTRYPOINT ["python"] +CMD ["app.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..631e259 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# **Flask WebMF** + +## **Using on Mac OS X Host** + +* Prerequisites: + * Install XCode Command Line Tools + * Install Brew `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` + +### **Install** + +```bash +$ brew install python +$ # Install/Setup virtualenv (optional) +$ pip install virtualenv +$ pip install virtualenvwrapper +$ mkdir ${HOME}/.virtualenvs +$ source /usr/local/bin/virtualenvwrapper.sh +``` + +## **Run** + +```bash +$ pip install flask # install flask library +$ ./app.py # run program +``` + +### **Run Using Virtualenv** + +This uses [virtualenv](https://virtualenv.pypa.io/en/latest/), so that libraries are installed in locally in only your account. + +```bash +$ mkvirtualenv flaskenv # create segregated environment +$ pip install -r requirements.txt # install flask library locally +$ ./app.py # run program +$ ## Run Tests Here (see below) +$ deactivate # exit segregated environment +``` + +## **Using Docker or Vagrant** + +See [Tools Readme](../TOOLS.md) for more information on install, setup, and start Docker or Vagrant. + +### **Build and Run with Docker Compose** + +```bash +$ docker-compose up -d +``` + +### **Build and Run with Vagrant** + +```bash +$ vagrant up +``` + +## **Testing Results** + +```bash +$ [ -z ${DOCKER_MACHINE_NAME} ] || WEBSERVER=$(docker-machine ip ${DOCKER_MACHINE_NAME}) +$ WEBSERVER=${WEBSERVER:-localhost} +$ PORT=5000 +$ curl -i ${WEBSERVER}:${PORT} +HTTP/1.0 200 OK +Content-Type: text/html; charset=utf-8 +Content-Length: 13 +Server: Werkzeug/0.11.4 Python/2.7.11 +Date: Sun, 13 Mar 2016 07:02:41 GMT + +Hello World! +``` diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..0eb59dd --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,12 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + config.vm.box = "ubuntu/trusty64" + config.vm.network "forwarded_port", guest: 5000, host: 5000 + + config.vm.provision "docker" do |docker| + docker.build_image "/vagrant", args: "-t vagrant/flask-web" + docker.run "vagrant/flask-web" , args: "-p 5000:5000" + end +end diff --git a/app.py b/app.py new file mode 100755 index 0000000..e6cd4a3 --- /dev/null +++ b/app.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +from flask import Flask +app = Flask(__name__) + +@app.route('/') +@app.route('/hello') # this route is not working +@app.route('/hello/') +def hello_world(): + return 'Hello World!\n' + +@app.route('/hello/') # dynamic route +def hello_user(username): + # show the user profile for that user + return 'Why Hello %s!\n' % username + +if __name__ == '__main__': + app.run(host='0.0.0.0') # open for everyone diff --git a/chocolate.config b/chocolate.config new file mode 100644 index 0000000..fe9a279 --- /dev/null +++ b/chocolate.config @@ -0,0 +1,5 @@ + + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3ef9f9c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '2' +services: + flask: + restart: always + build: . + ports: + - "5000:5000" + volumes: + - .:/code diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d39f2d7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +Flask>=0.10.1 +itsdangerous>=0.24 +Jinja2>=2.8 +MarkupSafe>=0.23 +Werkzeug>=0.11.4