Run the following algorithm to deploy this project on your local machine
Installation algorithm (steps):
git clone https://github.com/MarkOdinSon/IMDb-clone.git AppIMBbClone
cd AppIMBbClone
cp .env.example .env
docker-compose up --build
- go to http://localhost:8000/
Enjoy!
(following commands not necessary anymore, command #4 do it automatically)
`./run rails db:setup` (input in database some users and categories by default) file: db/seeds.rb
`./run rails db:migrate` `./run rails db:seed`
`./run bundle:install`
To be sure that the database and Rails components are working correctly, run the following commands:
./run rails db:seed RAILS_ENV=test --trace
it must return: Created 3 Users; Created 26 Categories
docker-compose run -e "RAILS_ENV=test" web bundle exec rspec
it must return: 36 examples, 0 failures, 3 pending
This app is using Rails 7.0.4, Ruby 3.2.0, Redis 7.0.7, PostgreSQL 15.1.
If you don't like some of these choices that's no problem, you can swap them out for something else on your own.
- PostgreSQL
- Redis
- Sidekiq (not necessary in this case)
- Action Cable (not necessary in this case)
- ERB
- Rspec-Rails
I recommend checking out most files and searching the code base for TODO:
,
but please review the .env
and run
files before diving into the rest of the
code and customizing it. Also, you should hold off on changing anything until
we cover how to customize this example app's name with an automated script
(coming up next in the docs).
This file is ignored from version control so it will never be commit. There's a number of environment variables defined here that control certain options and behavior of the application. Everything is documented there.
Feel free to add new variables as needed. This is where you should put all of your secrets as well as configuration that might change depending on your environment (specific dev boxes, CI, production, etc.).
You can run ./run
to get a list of commands and each command has
documentation in the run
file itself.
If the commands you run with the ./run ... file don't work then try changing all the entries in the run file from "docker-compose" to "docker compose". Everything works for me when docker-compose is written.
It's a shell script that has a number of functions defined to help you interact
with this project. It's basically a Makefile
except with less
limitations.
For example as a shell script it allows us to pass any arguments to another
program.
This comes in handy to run various Docker commands because sometimes these commands can be a bit long to type. Feel free to add as many convenience functions as you want. This file's purpose is to make your experience better!
If you get tired of typing ./run
you can always create a shell alias with
alias run=./run
in your ~/.bash_aliases
or equivalent file. Then you'll be
able to run run
instead of ./run
.
Let's say you've customized your app and it's time to make a change to your
Gemfile
or package.json
file.
Without Docker you'd normally run bundle install
or yarn install
. With
Docker it's basically the same thing and since these commands are in our
Dockerfile
we can get away with doing a docker compose build
but don't run
that just yet.
You can run ./run bundle:outdated
or ./run yarn:outdated
to get a list of
outdated dependencies based on what you currently have installed. Once you've
figured out what you want to update, go make those updates in your Gemfile
and / or package.json
file.
Then to update your dependencies you can run ./run bundle:install
or ./run yarn:install
. That'll make sure any lock files get copied from Docker's image
(thanks to volumes) into your code repo and now you can commit those files to
version control like usual.
Alternatively for updating your gems based on specific version ranges defined
in your Gemfile
you can run ./run bundle:update
which will install the
latest versions of your gems and then write out a new lock file.
You can check out the run
file to see what these commands do in more detail.
run rails:db seed for test environmental: ./run rails db:seed RAILS_ENV=test --trace
run rails console in test environmental: ./run rails console -e test
run RSpec with Docker in test environmental => docker-compose run -e "RAILS_ENV=test" web bundle exec rspec
Also, you can run all these commands in development environmental:
./run rails db:seed RAILS_ENV=development --trace
./run rails console
docker-compose run -e "RAILS_ENV=test" web bundle exec rspec
Here's a run down on what's different. You can also use this as a guide to Dockerize an existing Rails app.
- Core:
- Use PostgreSQL (
-d postgresql)
as the primary SQL database - Use Redis as the cache back-end
- Use Sidekiq as a background worker through Active Job
- Use a standalone Action Cable process
- Use PostgreSQL (
- App Features:
- Add
pages
controller with a home page - Add
up
controller with 2 health check related actions
- Add
- Config:
- Log to STDOUT so that Docker can consume and deal with log output
- Credentials are removed (secrets are loaded in with an
.env
file) - Extract a bunch of configuration settings into environment variables
- Rewrite
config/database.yml
to use environment variables .yarnc
sets a customnode_modules/
directoryconfig/initializers/rack_mini_profiler.rb
to enable profiling Hotwire Turbo Driveconfig/initializers/assets.rb
references a customnode_modules/
directoryconfig/routes.rb
has Sidekiq's dashboard ready to be used but commented out for safetyProcifile.dev
has been removed since Docker Compose handles this for us
- Assets:
- Use esbuild (
-j esbuild
) and TailwindCSS (-c tailwind
) - Add
postcss-import
support fortailwindcss
by using the--postcss
flag - Add ActiveStorage JavaScript package
- Use esbuild (
- Public:
- Custom
502.html
andmaintenance.html
pages - Generate favicons using modern best practices
- Custom
Besides the Rails app itself, a number of new Docker related files were added
to the project which would be any file having *docker*
in its name. Also
GitHub Actions have been set up.
- Docker + Rails template origin: Nick Janetakis | https://nickjanetakis.com | @nickjanetakis [https://github.com/nickjj/docker-rails-example]
- Developer of this site: Mark Hladkov (web developer) | Telegram
Developed this project as my Rails pet-project with Docker.
In order to demonstrate my knowledge of web application development.
Such as: server-side (databases + SQL (ORM) DDL & DML, business logic, API, authorization, unit testing and other debugging tools, Docker, Git)
and front-end JavaScript, AJAX or fetch, Tailwind CSS, dynamic pages without reloading (turbo frames),
WYSIWYG Trix editor to create and edit posts with attachments, responsive page layout (HTML Responsive Web Design), page paganation, seach by title or selected categories and etc.)