Add sample rails + postgresql application#288
Conversation
Signed-off-by: Alex Koch <alex@esparklearning.com>
nicksieger
left a comment
There was a problem hiding this comment.
Looks great! Thanks again for submitting. Will get one more set of 👀 and probably get this merged early next week.
glours
left a comment
There was a problem hiding this comment.
As you propose your sample as a Dev Environment, you need to convert your Dockerfile to use multistage and add Docker tooling during a dedicated target that will be used in your .docker/docker-compose.yaml
It should be interesting to use the seeds.rb file to populate the database and display them in the main page to demonstrate that the ruby application is linked to the database.
Also do we need the log and tmp directories? Same question for all the directories with only a .keep file inside?
Otherwise do we need the
| FROM ruby:3.1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN useradd -m app && chown app:app /app | ||
|
|
||
| RUN apt-get update -qq && apt-get install -y --no-install-recommends postgresql-client | ||
|
|
||
| USER app | ||
|
|
||
| COPY --chown=app:app Gemfile* . | ||
| RUN bundle install | ||
|
|
||
| COPY --chown=app:app . . | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] |
There was a problem hiding this comment.
As you described that your sample should work as a Dev Environments, you need to configure multistage build to include all the docker bits and check that git is present in the ruby base image
Check other existing samples of this repo if you need examples
| context: app | ||
| command: bash -c "bundle exec rails db:migrate && bundle exec rails server -b 0.0.0.0" |
There was a problem hiding this comment.
You should reference the build stage of the dev envs configuration to be sure to embed docker cli, compose ... inside your container
| context: app | |
| command: bash -c "bundle exec rails db:migrate && bundle exec rails server -b 0.0.0.0" | |
| context: app | |
| target: dev-envs | |
| command: bash -c "bundle exec rails db:migrate && bundle exec rails server -b 0.0.0.0" |
| # This file should contain all the record creation needed to seed the database with its default values. | ||
| # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
| # | ||
| # Examples: | ||
| # | ||
| # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) | ||
| # Character.create(name: "Luke", movie: movies.first) |
There was a problem hiding this comment.
We should populate the database to make the sample more realistic.
Thank you, I didn't understand that and will update.
I can do that if you'd like - but I was going for something as simple and as close to
Rails writes to |
|
I'd say it's fine to keep the log/tmp artifacts of Rails generation. Those directories still get used during development. |
|
Ok for the log/tmp and all the directories created by default by Rails initialiser 👍 |
|
Another note: Redis is configured in the Rails app, but not in the docker-compose file. This should probably be Rails+Postgres+Redis since I think it's the most common stack. |
Signed-off-by: Alex Koch alex@esparklearning.com