Skip to content

Commit 5091b96

Browse files
committed
.
1 parent 3e1ae96 commit 5091b96

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

docker.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ Commands
273273
+------------------------------------------------------------------+--------------------------------------------------------------------------+
274274
| ``docker run -p 5000:5000 --restart always comply`` | to auto restart container if it crashes |
275275
+------------------------------------------------------------------+--------------------------------------------------------------------------+
276-
276+
| ``docker run --name containerName imageName`` | give a name to the container |
277+
+------------------------------------------------------------------+--------------------------------------------------------------------------+
277278

278279
.. figure:: images/docker_cmd.PNG
279280
:width: 700px
@@ -347,7 +348,7 @@ Commands
347348
+---------------------------------------------------+------------------------------------+
348349
| ``docker exec container_nm/id COMMAND`` | execute a command within container |
349350
+---------------------------------------------------+------------------------------------+
350-
| ``docker exec -it <container name/id> /bin/bash`` | go into container's bash |
351+
| ``docker exec -it <container name/id> bash`` | go into container's bash |
351352
+---------------------------------------------------+------------------------------------+
352353

353354
Inside the docker container, if there is a need to view any files, we have to install an editor first

flask.rst

+72-5
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ We can add new key-values or change values as any dictionary in python.
111111
112112
However, for a large project,
113113
if there are multiple environments, each with different set of config values,
114-
we can create a configuration file. Refer to the link below for more.
115-
116-
https://pythonise.com/series/learning-flask/flask-configuration-files
114+
we can create a configuration file. Refer to the links below for more.
117115

116+
* https://pythonise.com/series/learning-flask/flask-configuration-files
117+
* https://flask.palletsprojects.com/en/0.12.x/config/#configuring-from-files
118118

119119

120120
Manipulating HTML
@@ -268,7 +268,11 @@ Below shows up to upload a file, e.g., an image to a directory in the server.
268268
file.save(img)
269269
270270
return render_template('index.html')
271-
271+
272+
To upload multiple files, end the html form tag with "multiple",
273+
``<form action="/upload" method="post" enctype="multipart/form-data" multiple>``
274+
275+
272276

273277
Logging
274278
-------
@@ -337,7 +341,7 @@ If we run ``docker ps``, under PORTS, we should be able to see
337341
that the Docker host IP 0.0.0.0 and port 5000, is accessible to the container at port 5000.
338342

339343

340-
Environment Variables
344+
Storing Keys
341345
----------------------
342346

343347
We can and should set environment variables; i.e., variables stored in the OS,
@@ -362,6 +366,16 @@ To do this, in Mac/Linux, we can store the environment variable in a ``.bash_pro
362366
echo $SECRET_KEY
363367
364368
369+
We can also add this to the ``.bashrc`` file so that the variable will not be lost each time
370+
you launch/restart the bash terminal.
371+
372+
.. code:: bash
373+
374+
if [ -f ~/.bash_profile ]; then
375+
. ~/.bash_profile
376+
fi
377+
378+
365379
In the flask script, we can then obtain the variable by using the os package.
366380

367381
.. code:: python
@@ -378,6 +392,59 @@ container.
378392
sudo docker run -e SECRET_KEY=$SECRET_KEY -p 5000:5000 comply
379393
380394
395+
Changing Environment
396+
--------------------
397+
398+
Sometimes certain configurations differ between the local development and
399+
server production environments. We can set a condition like the below.
400+
401+
Note by default flask environment is set to production
402+
403+
.. code:: python
404+
405+
if os.environ['FLASK_ENV'] == 'production':
406+
UPLOAD_URL = 'url/in/production/server'
407+
elif os.environ['FLASK_ENV'] == 'development'
408+
UPLOAD_URL = '/upload'
409+
410+
411+
We can then set the flask environment in docker as the below.
412+
Or if we are not using docker, we can ``export FLASK_ENV=development; python app.py``.
413+
414+
415+
.. code::
416+
417+
# when testing in production environment, comment out below
418+
CMD export FLASK_ENV=development
419+
420+
ENTRYPOINT [ "python", "-u", "app.py" ]
421+
422+
423+
A more proper way to handle environments is mentioned in flask's documentation below.
424+
425+
* https://flask.palletsprojects.com/en/0.12.x/config/#configuring-from-files
426+
427+
428+
Scaling Flask
429+
-----------------
430+
431+
Flask as a server is meant for development, as it tries to remind you everytime you launch it.
432+
One reason is because it is not built to handle multiple requests, which almost always occur in real-life.
433+
434+
The way to patch this deficiency is to first, set up a WSGI (web server gateway interface),
435+
and then a web server. The former is a connector to interface the python flask app to
436+
an established web server, which is built to handle concurrency and queues.
437+
438+
For WSGI, there are a number of different ones, including gunicorn, mod_wsgi, uWSGI, CherryPy, Bjoern.
439+
440+
For web servers, the two major ones are Apache and Nginx.
441+
442+
* https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
443+
* https://medium.com/ww-tech-blog/well-do-it-live-updating-machine-learning-models-on-flask-uwsgi-with-no-downtime-9de8b5ffdff8
444+
* https://www.appdynamics.com/blog/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/
445+
* https://www.fullstackpython.com/wsgi-servers.html
446+
447+
381448
OpenAPI
382449
---------
383450

general.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ After creating the file, and activating the VM, install the packages at one go u
8282
8383
pika==1.1.0
8484
scipy==1.4.1
85-
# package from github, not present in pip
86-
git+https://github.com/cftang0827/pedestrian_detection_ssdlite
8785
scikit_image==0.16.2
8886
numpy==1.18.1
87+
# package from github, not present in pip
88+
git+https://github.com/cftang0827/pedestrian_detection_ssdlite
89+
# wheel file stored in a website
90+
--find-links https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
91+
detectron2
92+
--find-links https://download.pytorch.org/whl/torch_stable.html
93+
torch==1.5.0+cu101
94+
torchvision==0.6.0+cu101
8995
9096
9197
Modeling

0 commit comments

Comments
 (0)