This project is a self-hosted collection of recipes.
- Installed Docker: This project uses 3 container to run the following services:
railsapplicationmysqldatabasenginxas a reverse proxy
- Clone the repository
git clone git@github.com:aurexli/cooking_app.git- Create the environment and credential files Create env file that is used by docker.
cd cooking_app
cp .env.example .env
# Generate a user/password and populate the file
vim .envCreate local env that is used by the rails application.
touch config/local_env.ymlThis file should contain this content:
DATABASE_NAME_DEV: db/developmentdb
DATABASE_NAME_TEST: db/testdb
DATABASE_NAME_PROD: db/productiondb
SOCKET: /var/run/mysqld/mysqld.sock
HOST: localhost
ADMIN_PASSWORD: some-admin-passwordADMIN_PASSWORD is the default admin user that exits after the database has been seeded. The admin user is called asdf. To change the name of the admin user, edit the last line in db/seeds.rb.
-
The website runs on port 80 per default. You can adjust the nginx config in
docker/nginx.conf. -
Build and start the cooking application
docker compose build
docker compose up -d- Create and initialize the database
docker exec rails_app bundle exec rake db:create
docker exec rails_app bundle exec rake db:migrate- Seed the database with the ingredients and the default admin user
docker exec rails_app bundle exec rake db:seeddocker compose down-
View logs
docker compose logs
-
Get interactive shell
docker container ls docker exec -it <docker-container-id> bash
- ruby, version: 3.2.5
- rails, version: 8.0.2
- stimulus libraries:
bin/importmap pin @stimulus-components/rails-nested-form bin/importmap pin slim-select bin/importmap pin stimulus-textarea-autogrow bin/importmap pin stimulus-use
-
You need to install rails and ruby.
-
Create credentials file
# Create config/credentials/production.yml.enc
EDITOR="code --wait" rails credentials:edit
# The content should be:
# database:
# username:
# password:- Replace the values in config/database.yml
-username: <%= ENV['DB_USER'] %>
+username: <%= Rails.application.credentials.database.username %>
-password: <%= ENV['DB_PASSWORD'] %>
+password: <%= Rails.application.credentials.database.password %>
-host: <%= ENV['DB_HOST'] %> # created by docker compose
+host: <%= ENV["HOST"] %>- Run tests
# Run one test
rails test test/models/recipe_test.rb
# Run all tests
rails test test