How a new project starts
Day 3 into my IndieWeb journey.
One of the principles of IndieWeb is selfdogfood (a name that according to me and to others can be improved). The principle declares that you should be
using your own creations on your own personal site that you depend on, as an aspect of your primary online identity.
Having been a web developer since I can remember this looks nice to me. I've never feel comfortable at using Wordpress, Joomla or any other CMS. I've always felt constrained by their developer choices and at the end of the day, I didn't feel like I knew what was happening under the hood.
This has not been the case with Rails (which is not a CMS of course), that I feel comfortable enough to say that I have a wide and deep knowledge of it.
So when it comes to starting a new project
rails new has been my tool of choice for the last 5 years now.
Rails comes packed with lots of goodies like ActionCable or the newly added Webpack integration. What I really appreciate about it is the strong set of rules and conventions that guide you through your development journey.
Before even starting out I had to decide which features I want to implement first, which, in the IndieWeb vocabulary, are my itches. Thankfully the IndieMark page came to help.
So the first step is registering what will be your domain for life. It took me a few hours to choose, as I wanted to avoid the surname, but I settled on the plain and simple francescoboffa.com. I used NameCheap to buy the domain.
Time to setup the project. After checking that I have the latest versions of Ruby and Rails installed on my MacBook, I gave birth to it with:
rails new IndieRails -T
-T flag is to disable the default testing framework used by Rails, as I am using RSpec. After a few customisations to the Gemfile (Postgres driver, Slim, RSpec, DatabaseCleaner, Rubocop) and having converted the default .erb files to slim, I can finally deploy this thing. But where?
Deploying the application
Luckily I had a spare server running Minecraft and a Postgres server, and that is all that I needed. I removed some cruft (Minecraft first - abandoned for months), created new Unix users and wrote a simple deploy script on the server:
#!/bin/bash cd website git fetch --all git checkout --force origin/master bundle install RAILS_MASTER_KEY=xxx RAILS_ENV=production bundle exec rails assets:precompile RAILS_MASTER_KEY=xxx RAILS_ENV=production bundle exec rails db:migrate sudo service website restart
I still have to configure a hook from GitHub to have this launched automatically on every push. The script updates the code with the latest Git revision from master and executes standard Rails deploy commands: package the bundle, precompile assets and run migrations. Finally it restarts the puma service, for which I added a systemd script, so that it in the event of a reboot, it would start automatically.
Nginx and SSL certificates
I installed nginx and configured it with a pretty standard configuration for Rails applications and to serve static assets with gzip and far expiration dates. All is set up except for DNSs. I've always been happy using Cloudflare, so I added a new (free) website, the relevant A and AAAA DNS records and switched the nameservers on NameCheap.
Just one problem, the SSL certificate was taking way too long to generate, while it usually is ready in a few minutes. So I used Let's Encrypt just to have the green lock on my address bar. Today, after 2 days the certificate is finally ready, but I'm not sure that I wan't to switch back to Cloudflare, as my current setup works just fine.
Using my website for authentication
The first step in the world of IndieWeb is adding links to your other social profiles on your homepage with a
rel="me" attribute and adding links back from the profiles to the website.
As many things in this world, it's easier to be done than to understand. You can read more on the wiki.
I can now happily use my website to authenticate. Yay 🎉.