New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create_db command of docker-entrypoint #2099

Merged
merged 1 commit into from Feb 11, 2018

Conversation

Projects
None yet
2 participants
@ariarijp
Contributor

ariarijp commented Nov 26, 2017

Sometimes I get an error like below.

$ docker-compose -f docker-compose.yml run --rm server create_db
Creating network "redash_default" with the default driver
Creating redash_postgres_1 ...
Creating redash_redis_1 ...
Creating redash_postgres_1
Creating redash_redis_1 ... done
[2017-11-26 04:01:52,577][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2017-11-26 04:01:52,595][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Traceback (most recent call last):
  File "/app/manage.py", line 9, in <module>
    manager()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 345, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 229, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/app/redash/cli/database.py", line 10, in create_tables
    db.create_all()
  File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
  File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 3848, in create_all
    tables=tables)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1919, in _run_visitor
    with self._optional_conn_ctx_manager(connection) as conn:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1912, in _optional_conn_ctx_manager
    with self.contextual_connect() as conn:
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2103, in contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2142, in _wrap_pool_connect
    e, dialect, self)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1456, in _handle_dbapi_exception_noconnection
    exc_info
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2138, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 387, in connect
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 516, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
    self._dec_overflow()
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
    return self._create_connection()
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 461, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 651, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 392, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
	Is the server running on host "postgres" (172.18.0.2) and accepting
	TCP/IP connections on port 5432?

I think create_db command should wait for PostgreSQL container to become available.

Thank you,

@ariarijp

This comment has been minimized.

Show comment
Hide comment
@ariarijp

ariarijp Dec 16, 2017

Contributor

Hi @arikfr,

How is this PR?
Some our workshop attendees stuck on its error.
If you have other ideas, I will close this PR.

Thanks,

Contributor

ariarijp commented Dec 16, 2017

Hi @arikfr,

How is this PR?
Some our workshop attendees stuck on its error.
If you have other ideas, I will close this PR.

Thanks,

@arikfr arikfr merged commit aa06e44 into getredash:master Feb 11, 2018

3 checks passed

VersionEye All software dependencies are fine. You are awesome!
Details
ci/circleci Your tests passed on CircleCI!
Details
codeclimate All good!
Details
@arikfr

This comment has been minimized.

Show comment
Hide comment
@arikfr

arikfr Feb 11, 2018

Member

Thank you for finding a solution to this issue! It's merged now. Sorry it took so long.

Member

arikfr commented Feb 11, 2018

Thank you for finding a solution to this issue! It's merged now. Sorry it took so long.

@ariarijp ariarijp deleted the ariarijp:fix/create_db branch Feb 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment