Skip to content
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

Simple db init with docker #629

Closed
wants to merge 16 commits into from
Closed

Conversation

gissehel
Copy link

I added to re:dash the following parameters:

  • REDASH_DATABASE_NAME
  • REDASH_DATABASE_HOST
  • REDASH_DATABASE_PORT
  • REDASH_DATABASE_USER
  • REDASH_DATABASE_PASSWORD

They are to be used instead of REDASH_DATABASE_URL. REDASH_DATABASE_URL still works and override REDASH_DATABASE_* other keys, so it should not be used if REDASH_DATABASE_* are used.

So given the re:dash main container is used with those keys, if you start the re:dash init container with the same image, with /init.sh as command and with the following env var set, it will create the database you need, the role (user), grant access to the new role, create tables, and populate tables.

The new init env var:

  • REDASH_DATABASE_USER_ADMIN
  • REDASH_DATABASE_PASSWORD_ADMIN
  • REDASH_DEFAULT_ADMIN_NAME
  • REDASH_DEFAULT_ADMIN_LOGIN
  • REDASH_DEFAULT_ADMIN_PASSWORD
    (DEFAULT_ADMIN is the properties used to create the first user in re:dash database)

typical usage would be:

  • REDASH_DATABASE_NAME=redash
  • REDASH_DATABASE_HOST=postgres
  • REDASH_DATABASE_PORT=5432
  • REDASH_DATABASE_USER=redash
  • REDASH_DATABASE_PASSWORD=redash_password
  • REDASH_DATABASE_USER_ADMIN=postgres
  • REDASH_DATABASE_PASSWORD_ADMIN=********
  • REDASH_DEFAULT_ADMIN_NAME=Admin
  • REDASH_DEFAULT_ADMIN_LOGIN=admin
  • REDASH_DEFAULT_ADMIN_PASSWORD=admin

The init script will do the following:

  • Create the database if not already exists
  • Create the role if not already exists
  • Grant right on database for role if either the database or the role was created
  • Check if table "dashboards" is present to call or not the tables creations and add the admin user
  • Create the reader role
  • Grant rights for the reader role
  • Check if re:dash's metadata is present in data_sources in order to insert the field if not present

The "init" container "best practices":

  • The container is started with exact same parameters than the re:dash container except:
    • is interactive
    • has more env var (cf: before)
    • doesn't use REDASH_DATABASE_URL
    • force command "/init.sh"

@gissehel
Copy link
Author

Should close #628

@arikfr
Copy link
Member

arikfr commented Nov 3, 2015

  1. Why do we need the extra env variables instead of the DB url?
  2. Maybe we should add those db init commands to the manage.py commands? This way you don't need to deal with CLI parsing.

And sorry for the delay in reviewing this...

@gissehel
Copy link
Author

gissehel commented Nov 4, 2015

1. About the REDASH_DATABASE_* variables:

This is in deed the controversial part of my commit.

I need access to both superuser and redashuser on the database. I didn't like the idea to repeat hostname/database name, and to let them be different. But if you don't like the idea, I can change that to REDASH_DATABASE_URL and REDASH_DATABASE_ADMIN_URL.

2. About manage.py

I'm not used to flask development and conventions. I'll take a look at it. Doesn't seems complex, but I might end up violating flask best practices...

@gissehel
Copy link
Author

gissehel commented Nov 4, 2015

By the way, I put the files in the docker folder, but there is nothing related to docker in those files, they might be used to init database on other environments too.

@tclass
Copy link

tclass commented Jan 13, 2016

would be really nice if we could merge this and get a proper docker(-compose) setup. I got it working for now, but it was really a PITA to get started.

@arikfr
Copy link
Member

arikfr commented Jan 14, 2016

@gissehel was planning to make more changes, hence I didn't merge. But I see that it's out of sync with latest master. Closing this for now.

@gissehel if you still plan to update it, please reopen.

@arikfr arikfr closed this Jan 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants