safe-global / safe-infrastructure

One `docker-compose.yml` file to rule them all
MIT License
56 stars 92 forks source link

First installation with the automated way is always unsuccessful. Why? #72

Closed comverser closed 1 year ago

comverser commented 1 year ago

Questions

First installation with the automated way is always unsuccessful. When I attempt to reinstall, the installation process completes without errors, which leaves me wondering why this is happening. If there is a problem, how can I solve it?

Console messages on my MacBook and EC2 instance in AWS.

MacBook Pro (M1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/app/src/manage.py", line 22, in main() File "/app/src/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/python-deps/lib/python3.10/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute() File "/python-deps/lib/python3.10/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv self.execute(*args, cmd_options) File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute return super().execute(*args, *options) File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 447, in execute self.check_migrations() File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 564, in check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) File "/python-deps/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in init self.loader = MigrationLoader(self.connection) File "/python-deps/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in init self.build_graph() File "/python-deps/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph self.applied_migrations = recorder.applied_migrations() File "/python-deps/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations if self.has_table(): File "/python-deps/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table with self.connection.cursor() as cursor: File "/python-deps/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner return func(args, kwargs) File "/python-deps/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor return self._cursor() File "/python-deps/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor self.ensure_connection() File "/python-deps/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, kwargs) File "/python-deps/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection with self.wrap_database_errors: File "/python-deps/lib/python3.10/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/python-deps/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection self.connect() File "/python-deps/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, *kwargs) File "/python-deps/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect self.connection = self.get_new_connection(conn_params) File "/python-deps/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner return func(args, kwargs) File "/python-deps/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection connection = Database.connect(conn_params) File "/python-deps/lib/python3.10/site-packages/psycopg2/init.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, kwasync) django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "cfg-db" (172.18.0.5) and accepting TCP/IP connections on port 5432?

(base)

#### Second
```bash
==> 16:59:56 ==> Starting up environment containers...
[+] Running 14/16
 ⠿ Container safe-infrastructure-txs-db-1                                                                                                                 Started                                                7.2s
 ⠿ Container safe-infrastructure-txs-rabbitmq-1                                                                                                           Star...                                                6.9s
 ⠿ Container safe-infrastructure-cgw-redis-1                                                                                                              Started                                                7.0s
 ⠿ Container safe-infrastructure-cfg-db-1                                                                                                                 Started                                                7.2s
 ⠿ Container safe-infrastructure-txs-redis-1                                                                                                              Started                                                7.1s
 ⠿ Container safe-infrastructure-txs-scheduler-1                                                                                                          Sta...                                                 7.8s
 ⠿ Container safe-infrastructure-txs-worker-notifications-webhooks-1                                                                                      Started                                                7.8s
 ⠿ Container safe-infrastructure-txs-web-1                                                                                                                Started                                                7.5s
 ⠿ Container safe-infrastructure-txs-worker-indexer-1                                                                                                     Started                                                7.2s
 ⠿ Container safe-infrastructure-txs-worker-contracts-tokens-1                                                                                            Started                                                7.5s
 ⠿ Container safe-infrastructure-cfg-web-1                                                                                                                Started                                                7.0s
 ⠿ Container safe-infrastructure-cgw-web-1                                                                                                                Started                                                6.8s
 ⠙ cgw-web The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested                                                        0.0s
 ⠿ Container safe-infrastructure-nginx-1                                                                                                                  Started                                                6.4s
 ⠿ Container safe-infrastructure-ui-1                                                                                                                     Started                                                6.6s
 ⠙ ui The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested                                                             0.0s
==> 17:00:05 ==> Creating super-user for Safe Config Service... (may take a while)
2023-02-23 08:00:06,524 [DEBUG] [MainProcess] Consider installing rusty-rlp to improve pyrlp performance with a rust based backend

You have 64 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, chains, contenttypes, safe_apps, sessions.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/src/manage.py", line 22, in <module>
    main()
  File "/app/src/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/python-deps/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/python-deps/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute
    return super().execute(*args, **options)
  File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 109, in handle
    default_username = get_default_username(database=database)
  File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/__init__.py", line 163, in get_default_username
    auth_app.User._default_manager.db_manager(database).get(
  File "/python-deps/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 646, in get
    num = len(clone)
  File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 376, in __len__
    self._fetch_all()
  File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 1867, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 87, in __iter__
    results = compiler.execute_sql(
  File "/python-deps/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1398, in execute_sql
    cursor.execute(sql, params)
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/python-deps/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                             ^

(base)

Third

==> 17:02:04 ==> Starting up environment containers...
[+] Running 14/14
 ⠿ Container safe-infrastructure-txs-rabbitmq-1                       Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-cfg-db-1                             Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-db-1                             Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-redis-1                          Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-cgw-redis-1                          Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-cfg-web-1                            Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-scheduler-1                      Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-worker-contracts-tokens-1        Started                                                                                                                                    0.4s
 ⠿ Container safe-infrastructure-cgw-web-1                            Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-web-1                            Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-worker-indexer-1                 Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-nginx-1                              Running                                                                                                                                    0.0s
 ⠿ Container safe-infrastructure-txs-worker-notifications-webhooks-1  Started                                                                                                                                    0.4s
 ⠿ Container safe-infrastructure-ui-1                                 Running                                                                                                                                    0.0s
==> 17:02:05 ==> Creating super-user for Safe Config Service... (may take a while)
2023-02-23 08:02:06,141 [DEBUG] [MainProcess] Consider installing rusty-rlp to improve pyrlp performance with a rust based backend
Username (leave blank to use 'root'): s
Email address: comverser@abc.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
==> 17:02:21 ==> Creating super-user for Safe Transaction Service... (may take a while)
Username (leave blank to use 'root'): s
Email address: comverser@abc.ocm
Password:
Password (again):
Superuser created successfully.
==> 17:02:42 ==> All set! You may want to add a ChainInfo into the Config service. Please use the link below to fill its data: http://localhost:8000/cfg/admin/chains/chain/add/
(base)

Ubuntu 20.04 (AWS EC2, t2.xlarge)

You have 64 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, chains, contenttypes, safe_apps, sessions. Run 'python manage.py migrate' to apply them. Traceback (most recent call last): File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedTable: relation "auth_user" does not exist LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user... ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/app/src/manage.py", line 22, in main() File "/app/src/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/python-deps/lib/python3.10/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute() File "/python-deps/lib/python3.10/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv self.execute(*args, cmd_options) File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute return super().execute(*args, *options) File "/python-deps/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute output = self.handle(args, options) File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 109, in handle default_username = get_default_username(database=database) File "/python-deps/lib/python3.10/site-packages/django/contrib/auth/management/init.py", line 163, in get_default_username auth_app.User._default_manager.db_manager(database).get( File "/python-deps/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 646, in get num = len(clone) File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 376, in len self._fetch_all() File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 1867, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/python-deps/lib/python3.10/site-packages/django/db/models/query.py", line 87, in iter results = compiler.execute_sql( File "/python-deps/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1398, in execute_sql cursor.execute(sql, params) File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute return super().execute(sql, params) File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute with self.db.wrap_database_errors: File "/python-deps/lib/python3.10/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/python-deps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "auth_user" does not exist LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user... ^

#### Second run
```bash
==> 07:15:48 ==> Starting up environment containers...
[+] Running 14/14
 ⠿ Container safe-infrastructure-txs-rabbitmq-1                       Running                                           0.0s
 ⠿ Container safe-infrastructure-cgw-redis-1                          Ru...                                             0.0s
 ⠿ Container safe-infrastructure-cgw-web-1                            Runn...                                           0.0s
 ⠿ Container safe-infrastructure-txs-db-1                             Runni...                                          0.0s
 ⠿ Container safe-infrastructure-txs-redis-1                          Ru...                                             0.0s
 ⠿ Container safe-infrastructure-txs-web-1                            Runn...                                           0.0s
 ⠿ Container safe-infrastructure-cfg-db-1                             Runni...                                          0.0s
 ⠿ Container safe-infrastructure-cfg-web-1                            Runn...                                           0.0s
 ⠿ Container safe-infrastructure-nginx-1                              Runnin...                                         0.0s
 ⠿ Container safe-infrastructure-ui-1                                 Running                                           0.0s
 ⠿ Container safe-infrastructure-txs-worker-contracts-tokens-1        Started                                           0.5s
 ⠿ Container safe-infrastructure-txs-scheduler-1                      Running                                           0.0s
 ⠿ Container safe-infrastructure-txs-worker-notifications-webhooks-1  Started                                           0.5s
 ⠿ Container safe-infrastructure-txs-worker-indexer-1                 Running                                           0.0s
==> 07:15:49 ==> Creating super-user for Safe Config Service... (may take a while)
2023-02-23 07:15:50,332 [DEBUG] [MainProcess] Consider installing rusty-rlp to improve pyrlp performance with a rust based backend
Username (leave blank to use 'root'):s
Email address: comverser@abc.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
==> 07:16:20 ==> Creating super-user for Safe Transaction Service... (may take a while)
Username (leave blank to use 'root'): s
Email address: comverser@abc.com
Password:
Password (again):
Superuser created successfully.
==> 07:16:39 ==> All set! You may want to add a ChainInfo into the Config service. Please use the link below to fill its data: http://localhost:8000/cfg/admin/chains/chain/add/

Reproduce

git clone https://github.com/safe-global/safe-infrastructure.git
cd safe-infrastructure
cp .env.sample .env

Edit the .env and set RPC_NODE_URL to the chain you want the services running against. (cf. Please note that this URL has not been added to safe-contracts through request pull and merge process.)

First run

cd scripts
sudo sh run_locally.sh

Second and third run

sh run_locally.sh
moisses89 commented 1 year ago

I'm trying to reproduce.

sudo sh run_locally.sh

I jump this because it's not necessary run as root.

My steps

First run, returns me the migrations issue. Second run, was success.

What happened with your first run

Your first run shows that something happened with the database docker image, because the issue is that the transaction-service can't access to database at default port.

My first run your second run

I get exactly the same issue than you here, I guess that is only once because the script is running createsuperuser without wait for migrations ready.

My second run, your third run

No error because the migrations are ready and createsuperuser can be executed without issues.

I'm going to work on this, to fix the first run issue.