Add SSH deployment support with release management - #1170
Conversation
|
This is on hold until the Upgrade wizard is delivered, while also discussing this work with the PaaS team. |
|
Nail down the interface first. The goal is to have shared commands that work across both PaaS and SSH, so we need to answer a few questions before implementation:
From Renaud Hager (@renaudhager): It depends on what you want to deploy:
|
Adds "shopware-cli project deploy" building on the existing environments abstraction: environments get a new "ssh" type with connection settings and a deployment section (path, keep_releases, shared files/dirs, hooks). Deployment methods are pluggable through a Deployer interface in internal/deployment so SFTP/PaaS backends can be added later with the same CLI surface. The SSH implementation uses a Deployer-style layout: releases are uploaded as tarball streams into releases/<timestamp>, shared files and directories are symlinked from shared/, the current symlink is switched atomically and old releases are pruned. When no pre_switch hooks are configured the Shopware Deployment Helper is run automatically when present. "project deploy rollback [release]" switches back to a previous release and marks the rolled-back-from release as bad so later rollbacks skip it, and "project deploy releases" lists the releases on the target. Multi-host support: environments can list additional servers under ssh.hosts, each inheriting unset connection settings from the ssh block. Deploys upload to all hosts in parallel, run hooks host after host so database work like migrations never executes concurrently, and switch the current symlink everywhere only after every host finished its pre-switch phase. A failure on any host before the switch aborts the deployment with the running release untouched everywhere. Rollback validates the target release exists on every host before switching any. Remote command execution: ssh environments implement the Executor interface, so "project console", "project clear-cache", "project worker" and "project dump" run on the deployment target with the same CLI surface as local and docker environments. Commands execute inside the currently deployed release on the primary host, with environment variables inlined and arguments shell-quoted. Because "project console" disables cobra flag parsing, shopware-cli's own flags (--env/-e, --project-config) are extracted before the console command name so Symfony's own --env flag stays usable; shell completion strips them too. Deployments and remote commands share one multiplexed connection through the new internal/sshcmd package, which sets ControlMaster=auto with a shared ControlPath and ControlPersist=60. The first command opens a master connection per host and later commands reuse it, skipping the TCP, key exchange and authentication handshake. Using the system ssh client also means deployments honor the user's ssh_config, SSH agent and ProxyJump settings. Squashed from 10 commits originally developed on the "next" line and replayed onto main; the intermediate states did not apply individually. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9329243 to
eb5bf53
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1170 +/- ##
==========================================
+ Coverage 53.94% 54.21% +0.27%
==========================================
Files 300 312 +12
Lines 23345 24027 +682
==========================================
+ Hits 12594 13027 +433
- Misses 10723 10972 +249
Partials 28 28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
TL;DR: Aligning to PaaS Native's deployment experience. Users should not need to know whether a plugin, binary, backend, or other execution mechanism is handling the deployment. Command structure and semanticsDeployment should be Note for broader context: PR #1237 already establishes Delegation modelThe architectural proposal is for Shopware CLI to act as a wrapper around the Native PaaS-specific actions could still exist under a command family with passed-through arguments. Benefit: limits coordination overhead, because DX Tools and PaaS/SaaS teams can work behind a shared CLI interface instead of blocking each other. For a PaaS target, Initially, this should provide the equivalent experience of For an SSH target, Shared deployment experienceThe shared flow should be:
The Shopware CLI and TUI should use consistent progress language where possible, while preserving the existing TUI experience. Back-end differences should be explained when they affect configuration, user decisions, or troubleshooting:
Before finalizing the PaaS integration, confirm ownership boundaries between Shopware CLI and paas-cli-as-plugin, version compatibility, and how required plugin or PaaS CLI updates and deprecations are communicated. Users need clear info about paas-cli version changes. Related operational questionsRelevant to the deployment experience but remain separate design decisions:
cc Sandor Akszenovics (@axasanya) Renaud Hager (@renaudhager) PTAL and share any concerns, comments, or feedback you have. |
Summary
This PR adds comprehensive SSH-based deployment capabilities to the CLI, enabling users to deploy Shopware projects to remote servers using a releases/shared directory layout with atomic symlink switching, similar to Deployer (deployer.org).
Key Changes
New Deployment Infrastructure
internal/deployment/- New package providing deployment abstraction:deployment.go- CoreDeployerinterface and types (Release,HostReleases,Options)ssh_deployer.go- SSH-based deployer implementing releases/shared/current symlink patternssh_connection.go- SSH connection wrapper using system ssh clientconnection.go- Connection interface for testabilityarchive.go- Project archiving with configurable exclusionsSSH Command Building
internal/sshcmd/- New package for SSH client command construction:sshcmd.go- Builds SSH arguments from environment config with ControlMaster multiplexing supportRemote Command Execution
internal/executor/ssh.go- New SSH executor for running commands on deployed releases:currentsymlinkConfiguration Schema
internal/shop/config.go- ExtendedEnvironmentConfigwith:EnvironmentSSH- SSH connection settings (host, port, user, authentication, known_hosts, ControlMaster control)EnvironmentDeployment- Deployment configuration (path, keep_releases, shared files/dirs, hooks)EnvironmentDeploymentHooks- Build, pre-switch, and post-switch hooksCLI Commands
cmd/project/project_deploy.go- Main deploy commandcmd/project/project_deploy_releases.go- List releases on targetcmd/project/project_deploy_rollback.go- Rollback to previous releasecmd/project/project_console.go- Enhanced to support SSH environments with flag strippingUtilities
internal/shell/quote.go- POSIX shell quoting for safe command constructioninternal/executor/factory.go- Extended to support SSH executor typeNotable Implementation Details
ln -sfn+mv -fTfor atomic current symlink updates, preventing partial deploymentsshopware-deployment-helperwhen present and no pre-switch hooks are configuredConfiguration Example