-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: deployment: add docker deployment article
Signed-off-by: Florian Scherf <mail@florianscherf.de>
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters