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

Add database support #2

Open
calebmeyer opened this issue Jun 8, 2018 · 2 comments
Open

Add database support #2

calebmeyer opened this issue Jun 8, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@calebmeyer
Copy link

The current application has nothing in schema.rb, no migrations, and no host defined in the database.yml

I assume there's some work to be done to ensure that docker can talk to a database run

  • locally at 0.0.0.0
  • in another container
  • somewhere that DNS can resolve (like database.mywebsite.com)

The "in another container" solution seems the best from the perspective of running everything needed locally using docker. However, this presents challenges:

  • How do we get the schema loaded? Do we do this every time?
  • How do we seed the initial data? Do we do this every time?
  • Can we keep a local copy of our data, or is the database refreshed every time?

Can we get that included?

@mikeantonelli
Copy link
Owner

Hi @calebmeyer. I think this would also be a useful example to include. I've done this a few different ways in the past.

  • Create a new service in our docker-compose.yml, call it db and just run the community mysql image
  • Add depends_on to services you want to spin up the database for first.
  • Create a utility service that overrides app with database commands.

I imagine it would look something like:

services:
  db-migrate:
    command: sh -c "bundle exec rake db:migrate"
    depends_on:
      - db
    environment:
      - DB_HOST: db
    image: 'mikeantonelli/docker-rails-compose:${VERSION-latest}'

  db:
    image: 'mysql:5.6'

Rather than build a new image varient, I would think that our production image should have all schema, migrations, and db connection configuration. It might also be a good time to introduce env_files instead of environment in service definitions so that we can take advantage of the same database configuration for db, db-migrate and app.

The result would be the capability to:

docker-compose run db-migrate

You could also override this to run custom commands:

docker-compose run db-migrate sh -c 'bundle exec rake db:setup`

So, maybe a different name than db-migrate makes more sense?

I also think we could update the app front end to show the current migration version so there was an example of database utilization in the project.

@mikeantonelli mikeantonelli added the enhancement New feature or request label Jul 10, 2018
@mikeantonelli
Copy link
Owner

@calebmeyer I opened #4 if you want to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants