Page MenuHomeSoftware Heritage

postgres db: Create guest user at db initialization time
ClosedPublic

Authored by ardumont on Tue, Jun 7, 2:28 PM.

Details

Summary

Related to T4228
Related to D7913

Test Plan
$ swh-doco up -d swh-scheduler
...
swh-doco exec swh-scheduler-db psql -U postgres
+ cd /home/tony/work/inria/repo/swh/swh-environment/docker
+ docker-compose -f docker-compose.yml -f docker-compose.override.yml exec swh-scheduler-db psql -U postgres
psql (12.11 (Debian 12.11-1.pgdg110+1))
Type "help" for help.

postgres=# select now(), * from pg_roles where rolname='guest';
             now              | rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig |  oid
------------------------------+---------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
 2022-06-07 13:02:37.84723+00 | guest   | f        | t          | f             | f           | t           | f              |           -1 | ********    |               | f            |           | 16385
(1 row)

$ swh-doco up -d swh-storage
...
$ swh-doco logs -f swh-storage-db
swh-storage-db_1                    | 2022-06-07 12:32:23.180 UTC [49] LOG:  database system is ready to accept connections
swh-storage-db_1                    |  done
swh-storage-db_1                    | server started
swh-storage-db_1                    | CREATE DATABASE
swh-storage-db_1                    |
swh-storage-db_1                    |
swh-storage-db_1                    | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/01-init-guest-user-db.sql
swh-storage-db_1                    | CREATE ROLE
...

$ swh-doco exec swh-storage-db psql -U postgres
+ cd /home/tony/work/inria/repo/swh/swh-environment/docker
+ docker-compose -f docker-compose.yml -f docker-compose.override.yml exec swh-storage-db psql -U postgres
psql (12.11 (Debian 12.11-1.pgdg110+1))
Type "help" for help.

postgres=# select now(), * from pg_roles where rolname='guest';
              now              | rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig |  oid
-------------------------------+---------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
 2022-06-07 13:03:26.519636+00 | guest   | f        | t          | f             | f           | t           | f              |           -1 | ********    |               | f            |           | 16385
(1 row)

Diff Detail

Repository
rDENV Development environment
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

ardumont edited the summary of this revision. (Show Details)

is it not possible to use a sql script directly, in the idea of [1] ?
I suppose it will make the script simpler as the postgresql image logic will take care of running the script only during the database initialization.

[1] https://forge.softwareheritage.org/source/swh-provenance/browse/master/docker-compose.yml$16

is it not possible to use a sql script directly, in the idea of [1] ?
I suppose it will make the script simpler as the postgresql image logic will take care of running the script only during the database initialization.

[1] https://forge.softwareheritage.org/source/swh-provenance/browse/master/docker-compose.yml$16

I guess it is, the [2] docker postgres image doc mentions the possibllity to init the db through both script and sql.
I went the script sh ways for some reason.

Lemme check.

[2] https://hub.docker.com/_/postgres/ -> Initialization scripts

ardumont edited the test plan for this revision. (Show Details)

It works like @vsellier suggested as well.

This revision is now accepted and ready to land.Wed, Jun 8, 9:25 AM