Settle on custom directory creation approach #16

Open
opened 2026-11-11 21:07:22 +00:00 by jsheunis · 2 comments

The /home/hub/custom directory is somehow expected to exist during some step in the forgejo.py deployment. This was evidenced when I removed the customizations_fetch_url and customizations_annex_get config options from an inventory and ran the deployment, which gave an error:

Error: statfs /home/hub/custom: no such file or directory

I worked around that using ensure_dirs:

'ensure_dirs': ['git/repositories', 'gitea/log', 'conf', 'custom'],

That worked fine, but only for the case when I did not want customizations. When I then added back the customizations_fetch_url and customizations_annex_get config options and kept the workaround, and then ran the deployment again, I got:

 fatal: --local can only be used inside a git repository
 Error: could not load fact: git.GitConfig repo=/home/hub/custom, system=False

--> Disconnecting from hosts...
--> pyinfra error in .venv/lib/python3.14/site-packages/liab_deployments/operations/annex.py line 35

That line in the annex.py operation is basically where the annex repo is initialized. But I'm guessing that the ensure_dirs created the custom directory already, as a normal directory and not a git repo, which I think is what leads to the error. When i removed the ensure_dirs workaround and reran the deployment, the annex error disappeared.

So I think I'm saying we should just have some fail proof way of handling the custom directory. E.g.:

if customizations_fetch_url and 'custom' in ensure_dirs:
    # do not include 'custom' in files.directory() call

and/or better code comments / docs to describe this scenario.

The `/home/hub/custom` directory is somehow expected to exist during some step in the `forgejo.py` deployment. This was evidenced when I removed the `customizations_fetch_url` and `customizations_annex_get` config options from an inventory and ran the deployment, which gave an error: ``` Error: statfs /home/hub/custom: no such file or directory ``` I worked around that using `ensure_dirs`: ``` 'ensure_dirs': ['git/repositories', 'gitea/log', 'conf', 'custom'], ``` That worked fine, but only for the case when I did not want customizations. When I then added back the `customizations_fetch_url` and `customizations_annex_get` config options and kept the workaround, and then ran the deployment again, I got: ``` fatal: --local can only be used inside a git repository Error: could not load fact: git.GitConfig repo=/home/hub/custom, system=False --> Disconnecting from hosts... --> pyinfra error in .venv/lib/python3.14/site-packages/liab_deployments/operations/annex.py line 35 ``` That line in the `annex.py` operation is basically where the annex repo is initialized. But I'm guessing that the `ensure_dirs` created the `custom` directory already, as a normal directory and not a git repo, which I think is what leads to the error. When i removed the `ensure_dirs` workaround and reran the deployment, the annex error disappeared. So I think I'm saying we should just have some fail proof way of handling the `custom` directory. E.g.: ```python if customizations_fetch_url and 'custom' in ensure_dirs: # do not include 'custom' in files.directory() call ``` and/or better code comments / docs to describe this scenario.
Member

Not creating the dir seems like a hacky workaround to me. It's not deploying anything that fails (cloning into an existing dir should work), but assessing what's to do in the first place. If the fact, that there is no repo yet lead to a failure at the point of annex-init, then establishing what's there to do was wrong earlier (establishing whether to clone).

I'll look into it.

Not creating the dir seems like a hacky workaround to me. It's not deploying anything that fails (cloning into an existing dir should work), but assessing what's to do in the first place. If the fact, that there is no repo yet lead to a failure at the point of annex-init, then establishing what's there to do was wrong earlier (establishing whether to clone). I'll look into it.
Member

So, there are multiple issues to deal with here:

  • The service unit expects a custom dir to exist, so it can be mounted into the service container. Hence, it's currently included in the ensure_dirs default.
  • As @jsheunis pointed out, when changing to actually use a customization repo, deployment fails during the planning phase, because annex.init calls host.get_fact(git.GitConfig, repo=<path>) and that errors out when the local gitconfig doesn't exist, even though it would exist in the execution phase b/c the cloning preceeds annex init.
  • However, once a custom dir exists, forgejo puts an empty conf dir underneath. That then leads to failure during the execution phase when the previous issue is fixed by a conditional, because now that destination dir for cloning isn't empty.

Two options, I think:

  • Instead of just creating that dir, make it an (empty) git repo right away. That way we maintain the canonical place for it, that later can be changed by setting a URL. Deployment can then commit what might be there and proceed to add/change origin and pull.
  • Simply change the service unit template to not mount a custom dir, when no customization is specified in the inventory and consequently don't create the dir in the first place.

I think the former is better for users playing around with this, the latter is smaller and easier on the deployment side.
Leaning toward the latter. Thoughts?

So, there are multiple issues to deal with here: - The service unit expects a `custom` dir to exist, so it can be mounted into the service container. Hence, it's currently included in the `ensure_dirs` default. - As @jsheunis pointed out, when changing to actually use a customization repo, deployment fails during the *planning phase*, because `annex.init` calls `host.get_fact(git.GitConfig, repo=<path>)` and that errors out when the local gitconfig doesn't exist, even though it would exist in the execution phase b/c the cloning preceeds annex init. - However, once a `custom` dir exists, forgejo puts an empty `conf` dir underneath. That then leads to failure during the *execution phase* when the previous issue is fixed by a conditional, because now that destination dir for cloning isn't empty. Two options, I think: - Instead of just creating that dir, make it an (empty) git repo right away. That way we maintain the canonical place for it, that later can be changed by setting a URL. Deployment can then commit what might be there and proceed to add/change origin and pull. - Simply change the service unit template to not mount a custom dir, when no customization is specified in the inventory and consequently don't create the dir in the first place. I think the former is better for users playing around with this, the latter is smaller and easier on the deployment side. Leaning toward the latter. Thoughts?
Sign in to join this conversation.
No labels
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab-in-a-box/liab-deployments#16
No description provided.