welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 165 forks source link

Rewrite for 6.0 #624

Open alessandro-fazzi opened 2 years ago

alessandro-fazzi commented 2 years ago

Preliminary note: the commit history hasn't been kept: it had no sense at all. Unfortunately I'm not able to fully squash the history because of a "backport" I've made in the middle causing too much conflicts during history rewrite attempts. Shit happens: I'll keep it easy :)

Alpha version for testing

If you have other versions installed, wipe it with gem uninstall wordmove, then

gem install wordmove --version '6.0.0.alpha.8'

The alpha version is shipped for internal testing; everyone feels free to be courious, but I'd advice to test it against staging/testing environments and anyway be wise about your backups.

Why such a big refactor?

What was wrong

thus

Which goals?

Since Wordmove is almost doing what it was created to do for almost 10 years, I can't see huge room nor huge urgency to expand its functionalities. But it still has it's place in the "market", thus I'd like to keep it alive.

In order to keep it alive I had some goals:

How does this PR accomplish those goals?

New command line implementation

the command line implementation has been re-implemented using https://dry-rb.org/gems/dry-cli/. dry-rb is minimal, class based and heavily object oriented

Service objects all the way

All the core logic is now organised into service objects; we have two organisers for SSH Wordmove::Organizers::Ssh::Push and Wordmove::Organizers::Ssh::Pull and two for FTP Wordmove::Organizers::Ftp::Push and Wordmove::Organizers::Ftp::Pull in charge of orchestrating all the single actions needed to accomplish the procedure. Reading the organisers should immediately give you the idea of what the code is accomplishing to do.

Let's look for example into lib/wordmove/organizers/ssh/push.rb

# [...]

        with(
            cli_options:,
            global_options: movefile.options[:global],
            local_options: movefile.options[:local],
            remote_options:,
            movefile:,
            guardian: Wordmove::Guardian.new(cli_options:, action: :push),
            logger:,
            photocopier: Photocopier::SSH
                          .new(ssh_opts)
                          .tap { |c| c.logger = logger }
          ).reduce(actions)
        end

        def self.actions
          [
            Wordmove::Actions::RunBeforePushHook,
            Wordmove::Actions::FilterAndSetupTasksToRun,
            reduce_if(
              ->(ctx) { ctx.wordpress_task },
              [Wordmove::Actions::Ssh::PushWordpress]
            ),
            iterate(:folder_tasks, [Wordmove::Actions::Ssh::PutDirectory]),
            reduce_if(->(ctx) { ctx.database_task },
                      [
                        Wordmove::Actions::SetupContextForDb,
                        Wordmove::Actions::Ssh::DownloadRemoteDb,
                        Wordmove::Actions::Ssh::BackupRemoteDb,
                        Wordmove::Actions::AdaptLocalDb,
                        Wordmove::Actions::Ssh::PutAndImportDumpRemotely,
                        Wordmove::Actions::Ssh::CleanupAfterAdapt
                      ]),
            Wordmove::Actions::RunAfterPushHook
          ]
        end

where it's evident what's the procedure being executed; the list of actions will be executed in order, and every action will have access to same context, where all the needed state (almost configurations) resides.

This way, and thanks to the new design, development and bug fixes should be naturally more focused.

Testing

Testing single actions is now more straight. The coverage has been preserved and slightly improved.

The CI, moved on GitHub actions, is also a bit more polished and for sure faster.

Documentation

Now the code has an extremely wider in-code documentation coverage. When 6.0.0 will be out of pre-release, you'll find updated developer's documentation at https://www.rubydoc.info/gems/wordmove.

Not a complete rewrite still

Some part of the legacy code have been loosely adapted to work into the new design patter; I'm not happy with this surviving code, but I'll keep it as it is. Time investment has already grown too much.

Features

This release is not about features, but

Maybe for the beta release also the ruby version will be bumped. I've still to check if the update to Ruby 3 would be easily affordable.

Bugfixes

Dropped features

global:
  sql_adapter: wpcli

Breaking changes

Thus remember to update you movefile.yml accordingly. The wiki documentation will be updated lately so you'll be on your own until then.

Configuring the local section: news and drops

From now on this will be your local section in movefile.yml:

local:
  wordpress_path: /users/fuzzy/dev/cosy_site

This sounds - and actually is - really cool, but you have to be aware of a few things.

local.database.mysql_options and local.database.mysqldump_options are dropped. Now we rely on wp-cli in order to dump and import the database. You can still configure wp-cli in order to achieve some of the previous configuration. In order to configure wp-cli you can follow the official docs https://make.wordpress.org/cli/handbook/references/config/#config-files, but here come some examples of a wp-cli.yml file

db export:
  exclude_tables: wp_posts,wp_options
  hex-blob: true
  no-create-info: true
  verbose: true
  # and even more at https://developer.wordpress.org/cli/commands/db/export/

db search-replace:
  skip_tables: wp_stats_*
  # and more at https://developer.wordpress.org/cli/commands/search-replace/

db import:
  # and on and on

Keep in mind that we already always use some flags when wrapping wp-cli commands:

Keep in mind you are able to overwrite them creating hard to track misbehaviours.

Also local.database.port and local.database.charset are dropped since they are managed differently in wp-config.php and anyway automatically managed by wp-cli.

alessandro-fazzi commented 2 years ago

Thanks @nlemoine for this https://github.com/welaika/wordmove/pull/624/commits/ab39a4a699ecdd78f5923b13d8860af9d012c045

Fixed in alpha.8

electricarts commented 2 years ago

Sorry for the maybe stupid questions from a pixel pusher:

Since from version 6 mysql and mysqldump options are no longer available, then the connection to the (local) database via socket also no longer works, right?

Currently I use the following entries in the movefile.yml in connection with local (flywheel):

name: local
user: root
password: "root"
host: localhost
mysqldump_options: '--column-statistics=0 --socket "/Users/mario/Library/Application\ Support/Local/run/w_2HLYrYO/mysql/mysqld.sock"'
mysql_options: '--socket "/Users/mario/Library/Application\ Support/Local/run/w_2HLYrYO/mysql/mysqld.sock"'
alessandro-fazzi commented 2 years ago

Hello @electricarts :)

Thnaks for the inquiry. That's not correct or at least that's not intended :P

Flags to the underlying mysql and mysqldump commands are still possible to be proxied by configuring wp-cli. I wrote something about it in a paragraph of this PR, but for sure a more structured documentation will follow the future release.

Moreover I think that using wp-cli to do BD operations, as far as your wordpress is able to connect to the DB, then you should be able to go configuration-lessly: wp-cli reads configurations directly from your wordpress installation.

That said I'd be more than happy to help you troubleshooting the specific flywheel scenario if you'd be able to perform some alpha or - soon - beta testing: I'm very interested in retaining support for such a widespread stack.

Let me know and feel free to open a discussion if you need to chat about the matter :)

P.S.: I've not yet tested the alpha against nothing but a plain standard WP install into a directory

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.