Container image improvements (#17)

pull/18/head
Josh Karpel 3 years ago committed by GitHub
parent 900a71dd03
commit cfbcb669e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,11 +13,31 @@
Spiel is a framework for building and presenting richly-styled presentations in your terminal using Python.
To see what Spiel can do, install it (`pip install spiel`), then run this command to view the demonstration deck:
To see what Spiel can do without installing it, you can view the demonstration deck in a container:
```bash
$ docker run -it --rm ghcr.io/joshkarpel/spiel
```
Alternatively, install Spiel (`pip install spiel`) and run this command to view the demonstration deck:
```bash
$ spiel demo present
```
## Sandboxed Execution via Containers
Spiel presentations are live Python code: they can do anything that Python can do.
You may want to run untrusted presentations (or even your own presentations) inside a container (but remember, even containers are not perfectly safe!).
We produce a [container image](https://github.com/users/JoshKarpel/packages/container/package/spiel)
that can be run by (for example) Docker.
Presentations without extra Python dependencies might just need to be bind-mounted into the container.
For example, if your demo file is at `$PWD/presentation/deck.py`, you could do
```bash
$ docker run -it --rm --mount type=bind,source=$PWD/presentation,target=/presentation ghcr.io/joshkarpel/spiel spiel present /presentation/deck.py
```
If the presentation has extra dependencies (like other Python packages),
we recommend building a new image that inherits our image (e.g., `FROM ghcr.io/joshkarpel/spiel:vX.Y.Z`).
Spiel's image itself inherits from the [Python base image](https://hub.docker.com/_/python).
## Supported Systems

@ -1,10 +1,21 @@
FROM python:3.9
ENV COLORTERM=truecolor
RUN : \
&& apt-get update \
&& apt-get install -y vim emacs nano \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& :
WORKDIR /app
COPY . /app/spiel
RUN pip install --no-cache-dir /app/spiel
RUN : \
&& pip install --no-cache-dir /app/spiel ipython \
&& spiel version \
&& :
ENV COLORTERM=truecolor \
EDITOR=/usr/bin/vim
CMD ["spiel", "demo", "present"]

@ -1,6 +1,8 @@
set -xeu
#!/usr/bin/env bash
set -eux
TAG="spiel:test"
docker build -f docker/Dockerfile -t "$TAG" .
docker run -it --rm "$TAG" spiel version
docker run -it --rm "$TAG" $@

@ -1,4 +1,5 @@
import inspect
import os
import shutil
import socket
from datetime import datetime
@ -371,7 +372,7 @@ def _(example, triggers):
## Editing Examples
Examples can be modified during the talk.
Press `e` to open your `$EDITOR` on the example code.
Press `e` to open your `$EDITOR` (`{os.getenv("EDITOR", "not set")}`) on the example code.
Save your changes and exit to come back to the presentation with your updated code.
You can then trigger the example again to run it with the new code.
"""

@ -1,5 +1,6 @@
from dataclasses import dataclass
from click._termui_impl import Editor # type: ignore
from rich.align import Align
from rich.console import Console, ConsoleRenderable, RenderGroup
from rich.padding import Padding
@ -8,7 +9,7 @@ from rich.table import Column, Table
from rich.text import Text
from spiel.constants import PACKAGE_NAME, __python_version__, __rich_version__, __version__
from spiel.input import INPUT_HANDLER_HELP, SpecialCharacters
from spiel.input import INPUT_HANDLER_HELP, SpecialCharacters, has_ipython
from spiel.modes import Mode
from spiel.state import State
@ -71,6 +72,7 @@ def version_details(console: Console) -> ConsoleRenderable:
table.add_row(f"{PACKAGE_NAME.capitalize()} Version", __version__)
table.add_row("Rich Version", __rich_version__)
table.add_row("Python Version", __python_version__, end_section=True)
table.add_row(
"Color System",
Text(
@ -84,4 +86,18 @@ def version_details(console: Console) -> ConsoleRenderable:
end_section=True,
)
editor = Editor().get_editor()
table.add_row(
"Editor",
Text(editor),
end_section=True,
)
repl = "IPython" if has_ipython() else "builtin"
table.add_row(
"REPL",
Text(repl, style=Style(color="green" if repl == "IPython" else None)),
end_section=True,
)
return table

Loading…
Cancel
Save