Обнаружена ошибка подключения после команды развертывания с Travis CI и Django Postgres «Не удалось подключиться к серверу» - PullRequest
0 голосов
/ 14 февраля 2020

В моем Travis.yaml я указываю, что хочу развернуть в Google App Engine, и что все работает без проблем. После развертывания я указываю:

after_deploy:
  - bash ./fastestfollowup/gae_deploy.sh

Это выполняется:

python3 ./fastestfollowup/manage.py migrate

И я получаю трассировку:

django.db.utils.OperationalError: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/cloudsql/fastest-follow-up-backend:us-central1:fastest-follow-up-backend-instance/.s.PGSQL.5432"?

Другие сведения о ситуации, которые имеют отношение :

  1. Я могу запустить миграцию при подключении к производственному серверу через локальную базу данных

  2. Мои учетные записи Travis Service установлены следующим образом:

    • Администратор App Engine
    • Deployer App Engine
    • Редактор облачной сборки
    • Облако SQL Администратор
    • Администратор хранилища
  3. Я вручную поддерживал сервер SQL в активном состоянии, чтобы убедиться, что он не просто не работает по тайм-ауту

(Если вы см. избыточный или избыточный доступ к этим учетным записям, дайте мне знать).

Если я могу подключиться, когда я работаю локально, почему я не могу подключиться через Travis?

Полный Travis.yaml:

language: python
services:
  - postgresql
python: 3.7
env:
  global:
    - secure: XLK0DRhRBBbECQUldG9LWB4Jpc6LwmRmaQBJFf9j7UCKB......
before_install:
  - echo $super_secret_password | gpg --batch --yes --passphrase-fd 0 fastest-follow-up-backend-ad30efeabbd5.json.gpg
install:
  - pip install -r fastestfollowup/requirements.txt
script:
  - python fastestfollowup/manage.py test
deploy:
  provider: gae
  keyfile: "./fastest-follow-up-backend-ad30efeabbd5.json"
  project: fastest-follow-up-backend
  config: "./fastestfollowup/app.yaml"
  edge: true
  on:
    branch: master
after_deploy:
  - bash ./fastestfollowup/gae_deploy.sh # just runs python3 manage.py migrate

Полная трассировка:

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/cloudsql/fastest-follow-up-backend:us-central1:fastest-follow-up-backend-instance/.s.PGSQL.5432"?


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

Traceback (most recent call last):
  File "./fastestfollowup/manage.py", line 21, in <module>
    main()
  File "./fastestfollowup/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations
    if self.has_table():
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 260, in cursor
    return self._cursor()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 236, in _cursor
    self.ensure_connection()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/cloudsql/fastest-follow-up-backend:us-central1:fastest-follow-up-backend-instance/.s.PGSQL.5432"?
...