sunrisemovement / devops

This repo is obsolete. A maintained version of this code lives at https://github.com/maximum-ethics/linode-caddy
GNU Affero General Public License v3.0
2 stars 1 forks source link

handler runs Hugo twice if both theme and config have changed #11

Open skyfaller opened 4 years ago

skyfaller commented 4 years ago

This task fails. Once we get this working, we should be able to update any Hugo sites that have changed. Then we should be able to automate hosting Hugo sites :)

Typical error:

TASK [sunrise : decide which sites to reload] ****************************************************************************************************************
fatal: [attenborough]: FAILED! => {"msg": "The conditional check 'item.changed == true' failed. The error was: error while evaluating conditional (item.changed == true): 'item' is undefined

The error appears to be in '/Users/nelson/Documents/GitHub/devops/roles/sunrise/tasks/hugo.yml': line 72, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: decide which sites to reload
  ^ here
"}
skyfaller commented 4 years ago

We completely rewrote this task several different ways without getting it to work.

Here is the problem: we have a list of Hugo websites. When we change the theme, the config file, or both for a given website, we want to have Hugo re-generate the site, so that the website served to users reflects the updates.

We do not want to regenerate all Hugo sites always. We do not want to regenerate a Hugo site twice if both its theme AND its config file have changed. We only want to regenerate a Hugo site once, if its theme and/or config file have changed, and if neither have changed, we want to do nothing. That would be idempotent, which is what we want.

What we think we need to do is:

  1. run the list of Hugo sites through a task that updates the theme for each, and a task that updates the config file for each.
  2. Store the results of those two tasks in variables, which are lists of results that include a loop item variable "item" which contains the original list of hugo sites, and also include an element "changed" that tells you whether each Hugo site's theme changed or config file changed (depending on whether we're looking at theme_changes or config_changes).
  3. Concatenate and filter (maybe not in that order?) those lists so we end up with a list of Hugo sites that were changed.
  4. Run the "hugo" command on that list of changed sites. (And if the list is empty, cheerfully do nothing. Idempotency!)

This seems actually really complicated and hard. There must be a simpler approach!

skyfaller commented 4 years ago

I rewrote this to run as a handler. The problem is that Hugo will run twice if both the theme and the config have changed. I cannot figure out how to make it only run once in that case.

We take this array of sites, run hugo.yml to create them, and call this handler to make Hugo regenerate them if (1) the theme has changed, and if (2) the config has changed.