Skip to content

Commit

Permalink
migration to seperate repo from web-microframework
Browse files Browse the repository at this point in the history
  • Loading branch information
darkn3rd committed Nov 24, 2018
0 parents commit 6a800e5
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "python"
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!
```
12 changes: 12 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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/<username>') # 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
5 changes: 5 additions & 0 deletions chocolate.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="python2" />
<package id="pip" />
</packages>
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '2'
services:
flask:
restart: always
build: .
ports:
- "5000:5000"
volumes:
- .:/code
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flask>=0.10.1
itsdangerous>=0.24
Jinja2>=2.8
MarkupSafe>=0.23
Werkzeug>=0.11.4

0 comments on commit 6a800e5

Please sign in to comment.