Pyjoyment.Command.Author.generate.dockerfile - Dockerfile generator command
Usage: APPLICATION generate dockerfile [OPTIONS]
./myapp.py generate dockerfile
python -m MyApp generate dockerfile
python -m MyApp generate dockerfile --user app
python -m MyApp generate dockerfile --port 8080
python -m MyApp generate dockerfile --graceful-timeout 8
Options:
-G, --graceful-timeout <seconds> Graceful timeout of the workers of the
server, defaults to the one of the
server
-h, --help Show this summary of available options
-p, --port <port> Port that the server listens on and the
image exposes, defaults to 3000
-u, --user <name> Create a system user and run the
application as it, defaults to the user
of the image
Pyjoyment.Command.Author.generate.dockerfile generates Dockerfile
and .dockerignore for applications.
The image is built in two stages. The first one installs the dependencies
with uv into .venv: the ones of pyproject.toml, which
Pyjoyment.Command.Author.generate.pyproject generates, locked with
uv.lock if there is one, or the ones of the inline metadata of PEP 723 of
a Pyjoyment.Lite script that has it and no pyproject.toml, locked
with its .lock file if there is one. The second one has Python, .venv
and the application only, and its command runs the pre-forking server without
uv, so that the signals of docker stop go straight to the server, which
stops gracefully on TERM. The images of Python and of uv are those of the
versions that run the generator.
Docker and Cloud Run give a container 10 seconds to stop, less than the 25
seconds that Pyjo.Server.Prefork.Pyjo_Server_Prefork.graceful_timeout
gives a worker, so --graceful-timeout 8 sets PYJO_GRACEFUL_TIMEOUT in
the image, which the command prefork takes for its option, and which the
environment of the container can change again. With Docker,
docker stop -t 30, or stop_grace_period: 30s of Docker Compose, lets
the workers finish their requests too.
The server listens on the port of the PORT environment variable, which
the image sets to the port of --port, 3000 by default, and exposes,
and which docker build --build-arg PORT=8080 changes too. A platform as
Knative, Cloud Run, Render, Koyeb or Heroku sets PORT for the container,
and the server listens on its port, as Knative ignores EXPOSE and sets
PORT to the containerPort of the service, 8080 by default.
This is a core command, that means it is always enabled and its code a good
example for learning to build new commands, you’re welcome to fork it.
See Pyjoyment.Commands for a list of commands that are available by
default.
-
class Pyjoyment.Command.Author.generate.dockerfile.Pyjoyment_Command_Author_generate_dockerfile(**kwargs: Any)[source]
Pyjoyment.Command.Author.generate.dockerfile inherits all
attributes and methods from Pyjoyment.Command and implements the
following new ones.
-
description = 'Generate "Dockerfile"'
description = dockerfile.description
dockerfile.description = 'Foo'
Short description of this command, used for the command list.
-
run(*args: str) → None[source]
dockerfile.run(*sys.argv[1:])
Run this command.
-
usage = 'Usage: APPLICATION generate dockerfile [OPTIONS]\n\n ./myapp.py generate dockerfile\n python -m MyApp generate dockerfile\n python -m MyApp generate dockerfile --user app\n python -m MyApp generate dockerfile --port 8080\n python -m MyApp generate dockerfile --graceful-timeout 8\n\nOptions:\n -G, --graceful-timeout <seconds> Graceful timeout of the workers of the\n server, defaults to the one of the\n server\n -h, --help Show this summary of available options\n -p, --port <port> Port that the server listens on and the\n image exposes, defaults to 3000\n -u, --user <name> Create a system user and run the\n application as it, defaults to the user\n of the image\n'
usage = dockerfile.usage
dockerfile.usage = 'Foo'
Usage information for this command, used for the help screen.