Find a file
2024-11-01 17:00:55 -05:00
migrate Added sequel with example setup 2023-12-28 18:36:49 -06:00
models Added sequel with example setup 2023-12-28 18:36:49 -06:00
views Update views/index.erb 2024-11-01 17:00:55 -05:00
.gitignore Added new views that use the database 2023-12-28 22:39:02 -06:00
app.rb Added new views that use the database 2023-12-28 22:39:02 -06:00
config.ru Added sequel with example setup 2023-12-28 18:36:49 -06:00
db.rb Added sequel with example setup 2023-12-28 18:36:49 -06:00
Gemfile Added sequel with example setup 2023-12-28 18:36:49 -06:00
LICENSE Initial commit 2023-12-26 15:45:04 -06:00
models.rb Added sequel with example setup 2023-12-28 18:36:49 -06:00
myapp.service Added systemd 2023-12-26 23:57:02 -06:00
Rakefile Added sequel with example setup 2023-12-28 18:36:49 -06:00
README.md Update README.md 2024-11-01 15:50:21 -05:00

roda-templates

For the single file app template, really the only file you need is the config.ru and run it with puma.

Database

Views

In this template, I've taken the single-file template and split up the config.ru to put routes and app logic in app.rb and call on templates to render proper html pages. tilt and erubi gems are added to do the rendering, and rack-unreloader gem is added to have puma automatically load file changes while running in development mode.

My example html layout uses Bulma to make it easier to make modern looking webpages.

Next Roda app template iterations will add database, then authentication.

Setup

Get git

sudo apt install git
git config --global user.email "myemail@gmail.com"
git config --global user.name "Full Name"
git config --global credential.helper "cache"

git clone https://path/to/project.git

Prereq installs

Will need ruby; install it via package manager or a ruby manager like rbenv/ruby-build. Will need the roda gem, and then an application server such as puma (recommended), gunicorn, or passenger. My examples will use system ruby and puma.

Option 1: System wide packages

With this example, will basically just ignore the project's Gemfile. Debian 12 has a pretty current ruby version so just using it.

sudo apt install ruby ruby-rack puma ruby-erubi ruby-tilt ruby-sequel ruby-sqlite3 rake
sudo gem install roda rack-unreloader

cd my-project

Option 2a: Bundler system package

Run the bundle install command from the project's root directory

sudo apt install ruby ruby-bundler ruby-dev gcc pkgconf make g++
echo 'gem:  --no-document' >> ~/.gemrc
sudo cp ~/.gemrc /root/
bundle config set --global path 'vendor/bundle'
sudo cp -r .bundle /root/

cd my-project
bundle install

Similar to above but might as well use the gem install to get the latest bundler. The Debian apt packaged bundler is currently a bit outdated and missing some features compared to the latest.

sudo apt install ruby ruby-dev gcc pkgconf make g++
echo 'gem:  --no-document' >> ~/.gemrc
sudo cp ~/.gemrc /root/
sudo gem install bundler
bundle config set --global path 'vendor/bundle'
sudo cp -r .bundle /root/

cd my-project
bundle install

Option 3: Rbenv Ruby

Todo

Run it

In the project root directory:

bundle exec puma

# or if you did not use bundler to install puma...
puma

This default to development mode. Run it in production mode with:

RACK_ENV=production bundle exec puma

# or if you did not install puma
RACK_ENV=production puma

For development, just run it like that. For production, probably want to set up a systemd service.

Run it with systemd in production

Copy the example myapp.service file to /etc/systemd/system/ and edit accordingly. The example assumes a user named "myapp" with a group name "myapp", the application files are in /opt/myapp/, and puma is the system puma. If you installed puma with bundler, the exe will be at /opt/myapp/vendor/bundle/ruby/3.1.0/bin/puma.

Notes

Unreloader

This has puma reload with any file changes while you are working on the app, when in development mode. When puma is in production mode, it loads the app on startup like normal with no performance penalty. It's very useful during development and no reason to not leave it in.

https://github.com/jeremyevans/rack-unreloader.

Basically, you require the app from the config.ru, and then within you app files, any "require_relative" will be "Unreloader.require" instead, plus you do need to include the file extension.

In config.ru, the dev = line stores true or false depending on the RACK_ENV environment variable (see above for changing from default development). Then the :reload=>dev uses the dev variable to tell Unreload to reload files or not. Lastly the run command uses the dev variable to choose between running Unreloader, or bypass Unreloader and run App like normal in production.

Additional credit

I took a lot of inspirations from Jeremy Evans roda-sequel-stack. Jeremy Evans is the author of Roda and also Unreloader, Sequel, and a ruby core contributor, among other things.