fix(techdocs): use writable workdir for local TechDocs generation
During local generation, sanitizeMkdocsYml() in @backstage/plugin-techdocs-node always rewrites mkdocs.yaml in place before generation. The previous compose setup bind-mounted those files directly from the host, so the container user could not write them and TechDocs publish either had warnings or failed with EACCES. (more details in https://redhat.atlassian.net/browse/RHDHBUGS-3360?focusedCommentId=17297355)
To fix this, this PR:
- Mounts TechDocs source files (
mkdocs.yaml,docs/,catalog-info.yaml) read-only undertechdocs-source/ - Copies them into a writable in-container techdocs-workdir on startup
- Points the catalog file location at the workdir copy so
backstage.io/techdocs-ref: dir:.resolves to a writable tree
Which issue(s) does this PR fix or relate to
- Fixes: https://redhat.atlassian.net/browse/RHDHBUGS-3360
PR acceptance criteria
- [x] Tests updated and passing
- [ ] Documentation updated
- [ ] Built-in TechDocs updated if needed. Note that TechDocs changes may need to be reviewed by a Product Manager and/or Architect to ensure content accuracy, clarity, and alignment with user needs.
How to test changes / Special notes to the reviewer
run podman compose up and navigate to the RHDH Guide (http://localhost:7007/catalog/default/system/rhdh-local/docs), the docs should be visible as expected without errors/warnings.
/agentic_review
Code Review by Qodo
🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)
Context used
RHDHBUGS-3360 1. cp -a breaks startup 🐞 Bug ☼ Reliability
Description
wait-for-plugins-and-start.sh runs with set -euo pipefail under UID 1001, but uses cp -a to populate the TechDocs workdir; cp -a attempts to preserve ownership and can fail under a non-root user, which will terminate the entrypoint and prevent Backstage from starting.
Code
wait-for-plugins-and-start.sh[R25-33]+# Copy TechDocs source files into a writable workdir for in-place mkdocs.yaml updates +# during TechDocs generation +TECHDOCS_SOURCE="/opt/app-root/src/techdocs-source" +TECHDOCS_WORKDIR="/opt/app-root/src/techdocs-workdir" +if [[ -d "$TECHDOCS_SOURCE" ]]; then + echo "Syncing TechDocs source files to writable workdir" + mkdir -p "$TECHDOCS_WORKDIR" + cp -a "$TECHDOCS_SOURCE/"* "$TECHDOCS_WORKDIR/" +fi
Evidence
The compose config explicitly runs the rhdh service as UID 1001, while the entrypoint script uses set -euo pipefail and performs cp -a; any failure in that command will exit the script and stop startup.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ### Issue description The entrypoint sync uses `cp -a`, which preserves ownership; when running as non-root (UID 1001), this can fail and, due to `set -e`, abort container startup. ### Issue Context The container runs as a non-root user, and the TechDocs sources are bind-mounted from the host. The sync should copy content without requiring privileged metadata operations. ### Fix Replace `cp -a` with a copy approach that does **not** preserve ownership (and ideally ensures writability), e.g.: - `rm -rf "$TECHDOCS_WORKDIR" && mkdir -p "$TECHDOCS_WORKDIR"` - `cp -R "$TECHDOCS_SOURCE/." "$TECHDOCS_WORKDIR/"` - optionally `chmod -R u+rwX "$TECHDOCS_WORKDIR"` ### Fix Focus Areas - wait-for-plugins-and-start.sh[25-33]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Workdir sync can drift 🐞 Bug ☼ Reliability
Description
The TechDocs sync copies only "$TECHDOCS_SOURCE/"* into an existing workdir and never clears it, so dotfiles are skipped and removed/renamed source files can remain in techdocs-workdir when restarting a container without recreating it.
Code
wait-for-plugins-and-start.sh[R27-33]+TECHDOCS_SOURCE="/opt/app-root/src/techdocs-source" +TECHDOCS_WORKDIR="/opt/app-root/src/techdocs-workdir" +if [[ -d "$TECHDOCS_SOURCE" ]]; then + echo "Syncing TechDocs source files to writable workdir" + mkdir -p "$TECHDOCS_WORKDIR" + cp -a "$TECHDOCS_SOURCE/"* "$TECHDOCS_WORKDIR/" +fi
Evidence
The script copies only globbed entries into a pre-existing directory and does not remove old contents. Since the catalog location points at the workdir copy, any missing dotfiles or stale files in that directory affect the effective TechDocs source tree.
wait-for-plugins-and-start.sh[25-33]configs/app-config/app-config.yaml[168-180]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ### Issue description The sync logic uses a `*` glob and merges into an existing destination directory. This (1) skips dotfiles and (2) can leave stale files in the workdir if the source tree changes and the container is restarted without being recreated. ### Issue Context The catalog is configured to load `catalog-info.yaml` from `/opt/app-root/src/techdocs-workdir`, so whatever is in that directory is what Backstage/TechDocs will see. ### Fix Make the sync deterministic by clearing the destination and copying using `/.` to include dotfiles, e.g.: - `rm -rf "$TECHDOCS_WORKDIR" && mkdir -p "$TECHDOCS_WORKDIR"` - `cp -R "$TECHDOCS_SOURCE/." "$TECHDOCS_WORKDIR/"` Optionally ensure writability with `chmod -R u+rwX`. ### Fix Focus Areas - wait-for-plugins-and-start.sh[25-33]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
/agentic_review
/cherry-pick release-1.10
@rm3l: once the present PR merges, I will cherry-pick it on top of release-1.10 in a new PR and assign it to you.
In response to this:
/cherry-pick release-1.10
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Failures not related to the changes here. Tracked in https://redhat.atlassian.net/browse/RHDHBUGS-3374
@rm3l: new pull request created: #240
In response to this:
/cherry-pick release-1.10
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.