Ruby on Rails with Sia and Auth0
Repository: ovrclk/nexqloud-on-rails Demo: pin.nexqloud.host
This is an example Rails Pinterest clone hosted on Nexqloud. There are a few extra features to make the most of decentralised hosting:
Auth0 user authentication.
Cloudflare DNS and SSL.
Scheduled tasks using Whenever.
Architecture
App container
Runs the rails server and hosts the actual website.
Connects to the Postgres container for a persistent database.
Uses Auth0 for user login and registration.
Cron container
Auto-restores the Postgres database on boot, achieving persistent database through re-deploys.
Auto-backup of the database to Filebase every 15 minutes.
Crontab is defined using Whenever in
schedule.rb.Runs the same docker image as the rails application, but running
croninstead of the rails server.A standalone database backup/restore container is also available.
Postgres container
Runs a standard Postgres server docker image.
Usage
Ultimately this repository is designed to provide a sensible example of hosting a rails application on Nexqloud. There are a few ways to use it:
Run the application as-is on Nexqloud with your own storage and Auth0 account
Setup a free Cloudflare account and add your domain and set nameservers.
Setup a Filebase account and bucket.
Add a
backupsfolder to your bucket.You will need your bucket name, client ID, and secret.
Sign up for an Auth0 account and set up an App.
Callback URL: https://yourdomain.com/auth/auth0/callback.
Logout URL: https://yourdomain.com.
You will need your Auth0 domain, client ID, and secret.
Deploy on Nexqloud and get your app URL.
Point your domain to your app URL using a CNAME in Cloudflare.
Configure 'Full' SSL mode in Cloudflare.
Sign in to your website using Auth0. The first user created will be made an administrator.
Use the relevant files in your own project
Rails ready Dockerfile.
Installs the AWS CLI tool to interact with Filebase.
Precompiles rails assets.
Runs the rails server.
Creates and restores the database.
Runs rake db:migrate and db:seed.
Sets the crontab using Whenever and runs the cron service.
Downloads latest backup from Filebase.
Restore the DB if a backup was found.
Backs up the database to Filebase.
Deletes backups older than KEEP_BACKUPS.
Whenever cron schedule file to run scripts/backup-postgres.sh every 15 minutes.
Configures Shrine within the application to use Filebase as an S3 host.
Nexqloud deploy manifest.
Clone the repository and use it as a base for a new project
Clone the repository to your own Github account.
Rename any occurrence of NexqloudOnRails, nexqloud-on-rails and, nexqloud_on_rails to your own app name.
Change any app/models, app/controllers, app/views as required.
Development
You can run the application locally using Docker compose.
Copy the .env.sample file to .env and populate.
Run docker-compose up to build and run the application.
Last updated