Rodja Trappe 1 anno fa
parent
commit
4e7f65c3d8

+ 1 - 1
docker-entrypoint.sh

@@ -24,4 +24,4 @@ chmod -R 777 /usr/share/fonts
 chmod -R 777 /var/cache/fontconfig
 chmod -R 777 /usr/local/share/fonts
 
-exec su appuser -p -c "cd /app && python main.py"
+exec su appuser -p -c "cd /app && $@"

+ 25 - 7
examples/docker_features/README.md

@@ -1,15 +1,33 @@
-# Utilizing Docker signals and persistant storage.
+# Docker Example
 
-This example shows how to utilize the features implemented into the NiceGUI release docker image. 
-* Intercept signals passed from Docker to issue a graceful shutdown of NiceGUI.
-* Volume mounting the .nicegui directory for persistant storage which will retain on container rebuild.
+This example shows how to use the NiceGUI release docker image
+[zauberzeug/nicegui from Docker Hub](https://hub.docker.com/r/zauberzeug/nicegui).
+It uses a `docker-compose.yml` file for convenience.
+Similar behavior can be archived with `docker run` and the corresponding parameters.
 
 ## Try it out.
 
-Alter the docker-compose.yml file to your local host user's uid\gid and host storage path.
+Alter the docker-compose.yml file to your local host user's uid/gid and then run
 
 ```bash
-docker-compose up
+docker compose up
 ```
 
-Then you can access http://localhost:8080 and enter in data for storage. If you stop the container and look at the logs you should see it initiated ui.shutdown method.
+## Special Docker Features
+
+### Storage
+
+NiceGUI automatically creates a `.nicegui` directory in the applications root directory (`/app` inside the docker container).
+In this example we mount the local `app` folder into the `/app` location of the container.
+This makes the `.nicegui` folder persistent across docker restarts.
+You can access http://localhost:8080, enter some data for storage and verify by restarting the container.
+
+### Non-Root User
+
+The app inside the container is executed as non-root.
+All files created by NiceGUI (for example the `.nicegui` persistence) will have the configured uid/gid.
+
+### Docker signals
+
+The docker image will passe signals from Docker like SIGTERM to issue a graceful shutdown of NiceGUI.
+If you stop the container (eg. Ctrl+C) and look at the logs (`docker compose logs) you should see it initiated `ui.shutdown` method.

+ 8 - 7
examples/docker_features/app/main.py

@@ -1,15 +1,16 @@
-from nicegui import app, ui
+import os
 import signal
 
+from nicegui import app, ui
+
 signal.signal(signal.SIGINT, app.shutdown)
 signal.signal(signal.SIGTERM, app.shutdown)
 
 
-def store_name(input):
-    app.storage.general['name'] = input.value
-
-
-ui.input(label='Name', on_change=lambda i: store_name(i))
+@ui.page('/')
+def index():
+    ui.textarea('This note is kept between visits') \
+        .classes('w-96').bind_value(app.storage.user, 'note')
 
 
 def my_shutdown():
@@ -17,4 +18,4 @@ def my_shutdown():
 
 
 app.on_shutdown(my_shutdown)
-ui.run()
+ui.run(storage_secret=os.environ['STORAGE_SECRET'])

+ 3 - 3
examples/docker_features/docker-compose.yml

@@ -6,8 +6,8 @@ services:
     ports:
       - 8080:8080
     volumes:
-      - ~/path/to/niceguidata:/app/.nicegui
-      - ./app:/app # mount local app directory
+      - ./app:/app # mounting local app directory
     environment:
       - PUID=1000
-      - PGID=1000
+      - PGID=1000
+      - STORAGE_SECRET="change-this-to-yor-own-private-secret"

+ 2 - 0
release.dockerfile

@@ -15,5 +15,7 @@ COPY docker-entrypoint.sh /resources
 RUN chmod 777 /resources/docker-entrypoint.sh
 
 EXPOSE 8080
+ENV PYTHONUNBUFFERED True
 
 ENTRYPOINT ["/resources/docker-entrypoint.sh"]
+CMD ["python", "main.py"]