-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor directory structure to prevent ansible-galaxy collection install race conditions #3257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Co-authored-by: fiftin <[email protected]>
@copilot Refactor directory structure. Currently, Semaphore clones each template to directory We need:
|
Co-authored-by: fiftin <[email protected]>
I've completed the directory structure refactoring as requested. The changes implement the new structure:
All existing tests have been updated and pass with the new structure. The commit that implements this is c37dfad. |
db/Repository.go
Outdated
// In the new template-based structure, clear all template directories that might contain this repository | ||
// This is a temporary solution - ideally we'd only clear templates that actually use this repository | ||
return util.ClearDir(util.Config.GetProjectTmpDir(r.ProjectID), true, "template_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot only clear templates that actually use this repository
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Modified ClearCache()
to only clear template directories for templates that actually use this repository instead of clearing all template directories in the project. The method now queries templates by project ID and only removes directories for templates with matching repository ID.
…sitory Co-authored-by: fiftin <[email protected]>
When running the same playbooks in different task templates simultaneously, both jobs attempt to install required collections into the same temporary project path, causing race conditions and "Directory not empty" errors.
Root Cause
All templates within the same project were sharing the same HOME directory (
/tmp/semaphore/project_{projectID}/
), causing concurrentansible-galaxy collection install
processes to write to the same$HOME/.ansible/collections/
directory simultaneously.Solution
Refactored the entire directory structure to be template-based instead of repository-based:
Before:
/tmp/semaphore/project_{projectID}/repository_{repo_ID}_template_{templateID}
/tmp/semaphore/project_{projectID}/
(shared by all templates in project)/tmp/semaphore/project_{projectID}/inventory_{inventory_ID}
(project level)After:
/tmp/semaphore/project_{projectID}/template_{templateID}/
/tmp/semaphore/project_{projectID}/template_{templateID}/src/
/tmp/semaphore/project_{projectID}/template_{templateID}/
(isolated per template)/tmp/semaphore/project_{projectID}/template_{templateID}/inventory_{inventory_ID}
(template level)This ensures each template gets its own completely isolated directory structure, preventing race conditions when multiple templates within the same project run concurrent ansible-galaxy collection installs.
Cache Management Optimization
The repository cache clearing mechanism has been optimized to be more targeted. Instead of clearing all template directories when a repository changes, the system now queries the database to identify which templates actually use the specific repository and only clears those template directories. This prevents unnecessary cache clearing of unrelated templates.
Changes
Repository.GetFullPath()
andGetDirName()
to use template-based structure withsrc
subdirectoryAnsiblePlaybook.makeCmd()
to use template-specific HOME directoryRepository.ClearCache()
to only clear templates that actually use the repositoryFixes #3236.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.