-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.2
kwmccabe edited this page Apr 17, 2018
·
18 revisions
v0.2 - start.sh, stop.sh, entrypoint.sh, gunicorn-access.log, gunicorn-errors.log, volumes, .gitignore
- +4 -0 [A] .gitignore
- +7 -6 [M] README.md
- +4 -0 [A] bin/start.sh
- +4 -0 [A] bin/stop.sh
- +3 -1 [M] docker-compose.yml
- +4 -0 [A] web/.dockerignore
- +4 -2 [M] web/Dockerfile
- +13 -0 [A] web/entrypoint.sh
- +7 -0 [M] web/flaskapp.py
- +2 -2 [M] web/requirements.txt
- Exclude temporary files from code repository.
+__pycache__
+*.py[cod]
+*.log
+.DS_Store
A sample, fullstack, Python web application
-1. Python
-2. Flask
-3. MySQL
-4. Gunicorn
-5. JQuery
-6. Bootstrap
+1. Docker
+2. Python
+3. Flask
+4. MySQL
+5. Gunicorn
+6. JQuery
+7. Bootstrap
- Utility script to run
docker-compose up
and launch services. - You should update the
BASEDIR
value to reflect you local path.
+#!/bin/bash
+
+BASEDIR=/Library/WebServer/docker-hub/flaskapp
+docker-compose -f ${BASEDIR}/docker-compose.yml up --build -d
- Utility script to run
docker-compose down
and stop associated services. - You should update the
BASEDIR
value to reflect you local path.
+#!/bin/bash
+
+BASEDIR=/Library/WebServer/docker-hub/flaskapp
+docker-compose -f ${BASEDIR}/docker-compose.yml down
- Refine the startup process, and link to the container volume so code changes are seen immediately.
-
command
: Replace the direct call togunicorn
with theentrypoint.sh
script. -
volumes
: Link the local directory./web
with the containers directory/web
.
build: ./web
ports:
- "5000:8000"
- command: /usr/local/bin/gunicorn -b :8000 flaskapp:app
+ command: ./entrypoint.sh
+ volumes:
+ - ./web:/web
- Exclude temporary files when copying code into the container.
+__pycache__
+*.py[cod]
+*.log
+.DS_Store
- Separate the installation of
requirements.txt
. As the project grows, changes to this file become infrequent. Ifrequirements.txt
is unchanged between Docker builds, thepip install
commands can be skipped.
RUN mkdir -p /web
WORKDIR /web
-# copy code from current directory into working directory
-COPY . /web
+# copy requirements.txt for pip install
+COPY requirements.txt /web/requirements.txt
# setup python environment, import required modules
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
+# copy code from current directory into working directory
+COPY . /web
- Shell script collects
Gunicorn - WSGI
server launch options in one place. -
flaskapp:app
: Application moduleMODULE_NAME:VARIABLE_NAME
. -
bind
: Application available on this port inside container. -
workers
: The number of worker processes for handling requests. -
timeout
: Extend worker lifetime 30 to allow debugging session. -
access-logfile
: Request log filepath. -
error-logfile
: Error log filepath. -
log-level
: Error log granularity :debug
|info
|warning
|error
|critical
. -
reload
: Restart workers when code changes.
+#!/bin/sh
+
+# see http://docs.gunicorn.org/en/stable/settings.html
+
+/usr/local/bin/gunicorn \
+ flaskapp:app \
+ --bind :8000 \
+ --workers 2 \
+ --timeout 3600 \
+ --access-logfile logs/gunicorn-access.log \
+ --error-logfile logs/gunicorn-error.log \
+ --log-level info \
+ --reload
- Add a second route
/info/date
that returns a dynamic value.
+@app.route('/info/date')
+def info_date():
+ import datetime
+ ts = datetime.datetime.now().strftime("%Y/%m/%d @ %H:%M:%S")
+ return "Current Datetime : %s" % ts
- Add specific version numbers to required packages, to control changes and allow for testing after upgrades.
-Flask
-gunicorn
+Flask==0.12.2
+gunicorn==19.7.1
Commit-v0.1 | Commit-v0.2 | Commit-v0.3
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages