docker / awesome-compose

Awesome Docker Compose samples
https://docs.docker.com/compose/
Creative Commons Zero v1.0 Universal
34.57k stars 6.64k forks source link

Add sample rails + postgresql application #288

Open kochalex opened 2 years ago

kochalex commented 2 years ago

Signed-off-by: Alex Koch alex@esparklearning.com

kochalex commented 2 years ago

Closes https://github.com/docker/awesome-compose/issues/287 and https://github.com/docker/awesome-compose/pull/57

kochalex commented 2 years ago

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

Thank you, I didn't understand that and will update.

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.

I can do that if you'd like - but I was going for something as simple and as close to rails new as possible with this. There are no database models in the default generated app. As this PR is currently, the Rails application within does need the postgres database to boot and store some basic metadata. The only changes I made to the ./app directory after running rails new were adding a Dockerfile and making Gemfile.lock track the "aarch64-linux" and "x86_64-linux" platforms for binary ruby gems.

Also do we need the log and tmp directories? Same question for all the directories with only a .keep file inside?

Rails writes to log and tmp by default - it will exit if those do not exist, however they could be added via the Dockerfile instead if that would be cleaner. The other .keep files are default locations to put certain types of code, I'm not sure offhand if they are all required. This was all boilerplate from rails new - if you'd like to see them deleted, I can look into and do that.

nicksieger commented 2 years ago

I'd say it's fine to keep the log/tmp artifacts of Rails generation. Those directories still get used during development.

glours commented 2 years ago

Ok for the log/tmp and all the directories created by default by Rails initialiser 👍 @kochalex The purpose of the samples in this repository is it help people to bootstrap/see how they can use Compose to configure multi services applications. So having 2 services running side by side without any interactions together doesn't provide the value we expect for the community, most of the users will expected to learn how they can connect their Rails application to a database running inside an another container.

mculp commented 1 year ago

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.