feat: add site:shared push pull commands for shared files - #92
Conversation
WalkthroughAdds two new Symfony Console commands to upload and download files to a site's shared directory, a trait for normalizing and building shared paths, server lookup helper for sites, and site-path/validation helpers in SitesTrait. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI
participant PullCmd as SiteSharedPullCommand
participant Sites as SitesTrait
participant Servers as ServersTrait
participant SSH
User->>CLI: site:shared:pull --domain=example.com --remote=config.php --local=./config.php
CLI->>PullCmd: execute()
PullCmd->>Sites: get site by domain
Sites-->>PullCmd: SiteDTO
PullCmd->>Servers: getServerForSite(site)
Servers-->>PullCmd: ServerDTO
PullCmd->>PullCmd: resolveRemotePath() -> normalizeRelativePath()
PullCmd->>SSH: test -f /shared/config.php
SSH-->>PullCmd: exists / not found
PullCmd->>PullCmd: resolveLocalPath() (prompt/expand)
PullCmd->>SSH: downloadFile(/shared/config.php → ./config.php)
SSH-->>PullCmd: success / error
PullCmd-->>User: success message + replay
sequenceDiagram
actor User
participant CLI
participant PushCmd as SiteSharedPushCommand
participant Sites as SitesTrait
participant Servers as ServersTrait
participant SSH
User->>CLI: site:shared:push --domain=example.com --local=./config.php --remote=config.php
CLI->>PushCmd: execute()
PushCmd->>Sites: get site by domain
Sites-->>PushCmd: SiteDTO
PushCmd->>Servers: getServerForSite(site)
Servers-->>PushCmd: ServerDTO
PushCmd->>PushCmd: resolveLocalPath() (expand & validate file)
PushCmd->>PushCmd: resolveRemotePath() -> normalizeRelativePath()
PushCmd->>PushCmd: buildSharedPath(site, remote)
PushCmd->>SSH: mkdir -p /shared/... && uploadFile()
SSH-->>PushCmd: upload result
PushCmd->>SSH: chmod 640 && chown deployer:deployer (if needed)
SSH-->>PushCmd: success / error
PushCmd-->>User: success message + replay
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
app/Traits/SitesTrait.php (1)
207-221: InlinegetSiteRootPathintogetSiteSharedPathto eliminate the single-use helper method.The method is called only once (line 220), which directly aligns with the coding guideline to eliminate single-use methods. Replace line 220:
return $this->getSiteRootPath($site).'/shared';with:
return '/home/deployer/sites/'.$site->domain.'/shared';Then remove the
getSiteRootPathmethod entirely (lines 207–213).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
app/Console/Site/SiteSharedPullCommand.php(1 hunks)app/Console/Site/SiteSharedPushCommand.php(1 hunks)app/Traits/ServersTrait.php(14 hunks)app/Traits/SiteSharedPathsTrait.php(1 hunks)app/Traits/SitesTrait.php(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.php
📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)
**/*.php: Eliminate single-use methods: inline if a method is called only once
Cache computed values: initialize expensive calculations in the constructor
Avoid method call overhead: prefer direct property access when appropriate
Files:
app/Traits/ServersTrait.phpapp/Traits/SiteSharedPathsTrait.phpapp/Console/Site/SiteSharedPushCommand.phpapp/Console/Site/SiteSharedPullCommand.phpapp/Traits/SitesTrait.php
🧠 Learnings (1)
📚 Learning: 2025-09-22T11:10:21.459Z
Learnt from: CR
Repo: deployer-plus/deployer-php PR: 0
File: .cursor/rules/01-architecture.mdc:0-0
Timestamp: 2025-09-22T11:10:21.459Z
Learning: Applies to app/**/Command/**/*.php : Commands must not duplicate orchestration logic—extract to shared Services
Applied to files:
app/Console/Site/SiteSharedPullCommand.php
🧬 Code graph analysis (3)
app/Traits/SiteSharedPathsTrait.php (3)
app/DTOs/SiteDTO.php (1)
SiteDTO(7-24)app/Contracts/BaseCommand.php (1)
nay(186-190)app/Traits/SitesTrait.php (1)
getSiteSharedPath(218-221)
app/Console/Site/SiteSharedPushCommand.php (6)
app/DTOs/ServerDTO.php (1)
ServerDTO(7-19)app/Traits/SitesTrait.php (1)
selectSite(70-106)app/Traits/ServersTrait.php (1)
getServerForSite(532-543)app/Traits/SiteSharedPathsTrait.php (2)
buildSharedPath(37-46)normalizeRelativePath(15-35)app/Services/SSHService.php (2)
uploadFile(109-132)executeCommand(69-102)app/Services/FilesystemService.php (2)
expandPath(113-143)exists(42-45)
app/Traits/SitesTrait.php (1)
app/DTOs/SiteDTO.php (1)
SiteDTO(7-24)
🪛 GitHub Actions: Pint
app/Traits/SiteSharedPathsTrait.php
[error] Pint PSR-12 lint failure: single_blank_line_at_eof.
🔇 Additional comments (8)
app/Traits/SitesTrait.php (1)
136-205: LGTM on validation enhancements.The added uniqueness check for domains and non-empty validations for branch and repository fields strengthen data integrity and prevent configuration errors.
app/Traits/ServersTrait.php (1)
529-543: LGTM on the new server lookup helper.The
getServerForSitemethod provides a clean abstraction for resolving a site's associated server with appropriate error handling, reducing duplication across commands.app/Traits/SiteSharedPathsTrait.php (1)
28-32: LGTM on path traversal protection.The validation correctly prevents directory traversal attacks by rejecting paths containing
.., which is essential for the security of file operations in the shared directory.app/Console/Site/SiteSharedPullCommand.php (2)
48-168: LGTM on command execution flow.The command structure is clean with proper error handling at each step, overwrite protection, and clear user feedback. The workflow logically progresses through site selection, server validation, path resolution, and file download.
218-237: LGTM on remote file existence check.The implementation correctly uses the Unix
test -fcommand with proper exit code handling and shell escaping. The exception for unexpected errors provides good debugging information.app/Console/Site/SiteSharedPushCommand.php (3)
48-143: LGTM on upload logic and permissions.The upload sequence (mkdir, upload, chmod 640, conditional chown) is correct and secure. The
chmod 640permission is appropriate for shared files, allowing the owner to read/write and the group to read. The conditional chown based on username prevents unnecessary operations.
149-176: LGTM on local file validation.The method properly validates that the local file exists and is a regular file (not a directory), with clear error messages. Path expansion for
~notation is a nice UX touch.
202-211: LGTM on remote command helper.The helper provides clean error handling for remote commands, with informative error messages that include command output when available, aiding in debugging failures.
…ivePath The null check catches rare preg_replace() errors, not empty input. Empty input is already handled separately on line 28. Updated message to accurately reflect processing failure rather than missing input.
Summary by CodeRabbit