Render is a newer general purpose cloud that offers free static hosting and transparent prorated pricing for services, databases, and cron jobs. This hosting guide will show how you could use Render to edit content in a container, commit and push it with Git, and then host a static site.
Creating a Tome static site on Render
- Visit https://dashboard.render.com/services and create a new web service.
- Select a Tome site's repository
- For "Environment", select "Static Site"
- For "Build Command", enter something like:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && php composer.phar install && ./vendor/bin/drush tome:install -y && ./vendor/bin/drush tome:static -l https://your-site.onrender.com
Where "your-site" is the name of your new Render service
For "Publish directory", enter "html"
Save the form
That should be it - now your repository will be checked out and your static site will be built. If you're not interested in editing content in Render you can stop reading now!
Creating an editing service on Render
Now we're going to create a service on Render that exists to be spun up, have Drupal content edited on it, then spun down so that you only pay for what you need. This is still new and experimental so make sure to read the notes at the bottom of the guide!
- Copy this example Dockerfile into the root of your repository
- Change the placeholders in the Dockerfile's "Set up Git" section to match your Git settings
- Commit and push the Dockerfile
- Install Tome Git on your Tome site (i.e. with "composer require drupal/tome_git && drush en tome_git")
- Generate an SSH key on your computer for this service, do not use a password
- Add the new SSH public key to your repository and give it write access. The documentation on Github is good if you use Github
- Visit https://dashboard.render.com/services and create a new web service
- Select a Tome site's repository
- For "Environment", select "Docker"
- Save the form
- When your service is ready, go into its settings
- Disable "Auto Deploy"
- Go to the service's "Environment" settings
- Add a "Secret File" with the filename "tome_id_rsa" that has the contents of your SSH private key
- Add a "Secret File" with the filename "tome_pass" that has a password for the administrative user of this site. Alternatively, you could use something like SSO here to login, or allow SSH to your service so that you could use "drush uli"
- Trigger a manual deploy for your service
- Visit the URL for your service and login
- Make a change to content, config, or files
- Visit "/admin/config/tome/git" and click "Sync changes"
- Ensure that your edits were properly synced - the Tome Git module is still in development and could have bugs
- Go back to the settings for your service and suspend it
- See that your static service for this site is already rebuilding. Yay!
This kind of functionality - being able to spin up containers on demand to make changes to content then completely spin them down - is really exciting and also really new for Drupal. Tome allows a kind of statelessness with Drupal that would otherwise not be possible.
However, there are some things to consider when using Render:
- Your "editing" service's container is ephemeral, which means that any unpushed changes in the container will be lost when it's suspended. Tome Git is going to improve and make syncing easier, but if someone forgets to sync their changes and the container is suspended or restarted there's no getting that data back. Once Render gets a persistent filesystem offering you could checkout the repository there to prevent this, but then you wouldn't get all the advantages of prorating. I think this is less scary than it seems, but it's worth calling out.
- As an add-on to the previous note, when you resume a suspended container, it loses any writes that previously occurred. So if you edit/push changes, suspend, and resume, you'll also need to trigger a manual build so that the latest commit is used when building the container.
- Render's in-browser console does not allow writing to the container, so if Tome Git fails to push there's not a lot you can do to remedy that. A solution to this could be to allow SSH to your container so you can manually run Git commands if needed. Tome Git is also going to add options for handling merge conflicts in the future which should help too.
If you end up using Render please blog about it! Thanks for making it through this relatively complex guide.