Allow container-native setup of LiberaForms
Currently, when setting up LiberaForms from develop
following the instructions in https://gitlab.com/liberaforms/liberaforms/-/blob/develop/docs/docker.md, we are mixing container-native and host-based setup steps.
We start with an empty database container, and only need that one now:
docker-compose up -d db
Note this uses the customised Compose from #140 (closed).
The command
flask database create --docker-container liberaforms-db
could ideally read
docker-compose run --rm liberaforms flask database create
Unfortunately this is not possible, since psql
is not available in the application container:
Traceback (most recent call last):
File "/usr/local/bin/flask", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 994, in main
cli.main(args=sys.argv[1:])
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 600, in main
return super().main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 444, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/app/liberaforms/commands/database.py", line 48, in create
run_subprocess(cmdline)
File "/app/liberaforms/commands/database.py", line 22, in run_subprocess
p = subprocess.Popen(cmdline)
File "/usr/local/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'psql'
- Is this rather an upstream issue with Flask, that they do not natively talk to the database through Python, but leverage a third-party CLI instead?
Thankfully the example command adapted to the respective container does give us a hint how Flask would create the user through Docker:
docker-compose run --rm liberaforms flask database create --docker-container liberaforms-db
We can adapt the response to that command
docker exec liberaforms-db psql -U postgres -c CREATE USER liberaforms WITH PASSWORD 'SECRET';
to a Compose command:
docker-compose exec liberaforms-db sh -c "psql -U postgres -c CREATE USER liberaforms WITH PASSWORD 'SECRET';"
With this, subsequent configuration can also happen through Compose:
docker-compose run --rm liberaforms flask db upgrade
docker-compose run --rm liberaforms flask site set -hostname=localhost.localdomain -scheme=http -port=5000
We can then run the whole application stack and access it at the BASE_URL
http://localhost.localdomain:5000/
docker-compose up -d
No images or static assets are yet delivered, but this is due to a missing web server that would offer them. https://gitlab.com/liberaforms/liberaforms/-/blob/develop/docs/nginx.example can be adapted for a separate nginx container alongside the app, in order to provide static assets to a client.
A pure Compose setup will also tell us how to create the cryptokey through the container, as done manually in https://gitlab.com/liberaforms/liberaforms/-/blob/develop/docs/INSTALL.md, or randomly set by me in .env
.
Unfortunately bootstrapping the first admin user from the ROOT_USER
email address is currently also not possible due to some 500 Internal Server Errror that complains about a missing CSRF session token. This might be due to the missing web server serving some JavaScript that would include it, but right now it doesn't.
Anyway, we've come quite some way until here, and may proceed with an example nginx
container configuration another time.