Skip to content

Commit

Permalink
doc: deployment: add docker deployment article
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Scherf <mail@florianscherf.de>
  • Loading branch information
fscherf committed Jul 30, 2023
1 parent 27bb596 commit 7c62167
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/content/deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dockerfile

FROM python:3.11

RUN pip install lona lona-picocss # lona-picocss is optional

COPY hello-world.py .

CMD ["python", "hello-world.py"]
45 changes: 45 additions & 0 deletions doc/content/deployment/deploying-on-docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
search_index_weight: 10


Deploying on Docker
===================

In this article we will deploy a simple Lona script using
`Docker <https://www.docker.com/>`_ and optionally
`Docker Compose <https://docs.docker.com/compose/>`_.

See the `lona-project-template <https://github.com/lona-web-org/lona-project-template>`_
for an example on how to run a Lona Project in Docker.

This article assumes that all files (``hello-world.py``, ``Dockerfile`` and
optionally ``docker-compose.yml``) are in the same directory, and all commands
are run in this directory.

.. code-block:: python
:include: hello-world.py
.. code-block:: docker
:include: Dockerfile
Run these two commands:

.. code-block:: bash
docker build -t lona-hello-world .
docker run -it -p 8080:8080 lona-hello-world
Docker Compose
--------------

To use `Docker Compose <https://docs.docker.com/compose/>`_, add this this
config to the same directory.

.. code-block:: yaml
:include: docker-compose.yml
Then run this command:

.. code-block:: bash
docker compose up # on your system it might be 'docker-compose'
19 changes: 19 additions & 0 deletions doc/content/deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# docker-compose.yml

version: "3"

services:
app:
build:
context: ./
dockerfile: Dockerfile

volumes:
- ./:/app

working_dir: "/app"

ports:
- 8080:8080

command: ["python", "hello-world.py"]
25 changes: 25 additions & 0 deletions doc/content/deployment/hello-world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# hello-world.py

from lona.html import HTML, H1
from lona import App, View

from lona_picocss import install_picocss

app = App(__file__)

install_picocss(app) # optional

app.settings.MAX_RUNTIME_THREADS = 50
app.settings.MAX_WORKER_THREADS = 100
app.settings.MAX_STATIC_THREADS = 20


@app.route('/')
class Index(View):
def handle_request(self, request):
return HTML(
H1('Hello World'),
)


app.run(host='0.0.0.0', port=8080)
1 change: 1 addition & 0 deletions doc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

['Deployment', [
['Resource Management', 'deployment/resource-management.rst'],
['Deploying on Docker', 'deployment/deploying-on-docker.rst'],
['Deploying on Linux', 'deployment/deploying-on-linux.rst'],
]],

Expand Down

0 comments on commit 7c62167

Please sign in to comment.