Skip to content

easy-install: make deploy compose generation resilient when SITES_RULE is unset#1711

Draft
Copilot wants to merge 3 commits into
developfrom
copilot/fix-skip-sites-rule-validation
Draft

easy-install: make deploy compose generation resilient when SITES_RULE is unset#1711
Copilot wants to merge 3 commits into
developfrom
copilot/fix-skip-sites-rule-validation

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 23, 2026

easy-install.py build --deploy can fail during compose config generation because Traefik labels in frappe_docker require SITES_RULE, but bench-generated .env files may omit it. This change makes env generation always provide a valid SITES_RULE while preserving user overrides.

  • Root cause addressed in env generation

    • write_to_env(...) now always writes SITES_RULE.
    • Default is derived from configured sites; when no sites are provided, it falls back to site1.localhost.
  • Override behavior preserved

    • On existing deployments, start_prod(...) now reads SITES_RULE from the current .env and passes it back through env regeneration, so custom routing rules remain intact.
  • Regression coverage added

    • Added focused unit tests for:
      • default SITES_RULE generation when unset
      • preservation of explicit/custom SITES_RULE
sites = sites or ["site1.localhost"]
sites_rule = sites_rule or " || ".join([f"Host(`{site}`)" for site in sites])

env_file_lines = [
    ...,
    f"SITES={quoted_sites}\n",
    f"SITES_RULE={sites_rule}\n",
    ...,
]
Original prompt

The GitHub Actions job "Easy Install Test" is failing in pull request #1707 in repository frappe/bench.

Observed failure from the job logs:

  • Docker Compose generation fails with: required variable SITES_RULE is missing a value: SITES_RULE not set
  • The failure happens during the workflow step in .github/workflows/easy-install.yml that runs python3 ${GITHUB_WORKSPACE}/easy-install.py build --deploy ...
  • The logs show the fatal error: error while interpolating services.frontend.labels.[]: required variable SITES_RULE is missing a value: SITES_RULE not set

Please implement a fix in this PR so the easy-install flow no longer fails when SITES_RULE is unset.

Requirements:

  1. Investigate the compose template(s) and/or env generation code used by easy-install.py build --deploy.
  2. Add a robust fix so compose generation succeeds even when SITES_RULE is not explicitly provided.
  3. Prefer fixing the product behavior rather than only patching CI, unless CI-only is clearly the correct scope.
  4. Keep the existing override behavior intact if SITES_RULE is provided by users.
  5. If the correct fix is in a compose template, use a sensible default matching the workflow’s expected hostname behavior (site1.localhost) or the repository’s existing conventions.
  6. Update tests if there are relevant tests for compose/env generation; otherwise add a focused regression test if appropriate.

Please create a pull request with the code changes against the branch for PR #1707 in frappe/bench.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The failure is caused by Docker Compose template interpolation, not by the image build.

Root cause

The job fails here in the logs:

  • error while interpolating services.frontend.labels.[]: required variable SITES_RULE is missing a value: SITES_RULE not set
  • then:
    • Generating Compose File failed

This happens during the workflow’s easy-install step in .github/workflows/easy-install.yml, which runs:

python3 ${GITHUB_WORKSPACE}/easy-install.py build --deploy --tag=custom-apps:latest --project=actions_test --email=test@frappe.io --image=custom-apps --version=latest --app=erpnext

So the install path is generating a compose file that now expects SITES_RULE, but the generated .env does not provide it.

Why this fails

The compose template for the frontend service is using ${SITES_RULE} in labels, and Compose treats that as a required variable. Since the generated environment file only has “basic configs” and does not include SITES_RULE, compose generation aborts before the stack comes up.

The repeated --- ERROR --- lines during Yarn install are not the fatal issue. The actual terminating error is the missing SITES_RULE.


Solution

Make compose generation resilient by providing a default for SITES_RULE, or ensure the easy-install generated .env explicitly sets it.

Best fix

In the compose template, replace the required interpolation with a safe default.

Use:

${SITES_RULE:-Host(`site1.localhost`)}

or, if the label is part of a larger expression, default only the variable:

...${SITES_RULE:-Host(`site1.localhost`)}...

This prevents Compose from failing when SITES_RULE is absent and preserves override behavior when it is set.

If the template currently uses required syntax

If it looks like this:

- "traefik.http.routers.frontend.rule=${SITES_RULE}"

change it to:

- "traefik.http.routers.frontend.rule=${SITES_RULE:-Host(`site1.localhost`)}"

Alternative fix

If bench intentionally requires SITES_RULE, then the generator that creates .env for --deploy must write a default value.

Suggested generated env entry:

SITES_RULE=Host(`site1.localhost`)

That is especially appropriate because the workflow validates:

curl -H "Host: site1.localhost" -sk https://127.0.0.1/api/method/ping

So site1.localhost is already the expected hostname in this test.


Recommended patch direction

Prefer fixing the compose template instead of only the workflow, because this is a product-level robustness issue: any user running easy install without SITES_RULE will hit the same failure.

Suggested code change

Wherever the frontend Traefik label is defined, update it along these lines:

services:
  frontend:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.frontend.rule=${SITES_RULE:-Host(`site1.localhost`)}"

If there are separate HTTP/HTTPS routers, apply the same fallback there too.


Summary

...

This pull request was created from Copilot chat.

Copilot AI and others added 2 commits April 23, 2026 15:15
Agent-Logs-Url: https://github.com/frappe/bench/sessions/80e3dbaa-a210-469b-a99d-4a443f1cf71a

Co-authored-by: netchampfaris <9355208+netchampfaris@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

Copilot AI changed the title [WIP] Fix Docker Compose generation to handle missing SITES_RULE easy-install: make deploy compose generation resilient when SITES_RULE is unset Apr 23, 2026
Copilot AI requested a review from netchampfaris April 23, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants