Skip to content

Commit

Permalink
Add Lima Support
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoollllee committed Sep 26, 2023
1 parent 124e073 commit 34a0258
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ The available recipes:
## Bedrock DB
Provides tasks to export the database from the server and import it to your development machine and vice versa.

There is a recipe for Trellis / Vagrant as well as a recipe for Valet+ environments.

### Trellis / Vagrant environment

Requirements:

- Vagrant **running** on your local machine (or Trellis, of course)
- WP CLI running on your Vagrant as well as on your remote machine
- Virtual Machine (Vagrant, Lima,...) **running** on your local machine (or Trellis, of course)
- WP CLI running on your Virtual Machine as well as on your remote machine

Load into your deploy.php file with:

Expand All @@ -50,15 +48,16 @@ require 'vendor/mmoollllee/bedrock-deployer/recipe/bedrock_db.php';
Requires these Deployer environment variables to be set:

- local_root: Absolute path to website root directory on local host machine
- vagrant_dir: Absolute path to directory that contains .vagrantfile
- vagrant_root: Absolute path to website inside Vagrant machine (should mirror local_root)
- trellis_dir: Absolute path to directory that contains trellis
- vm_root: Absolute path to website inside Virtual machine (should mirror local_root)
- vm_shell: Virtual Machine SSH Prefix (e.g. `vagrant ssh -- -t`)

Example:

````php
set( 'local_root', dirname( __FILE__ ) );
set( 'vagrant_dir', dirname( __FILE__ ) . '/../trellis' );
set( 'vagrant_root', '/srv/www/domain.com/current' );
set( 'trellis_dir', dirname( __FILE__ ) . '/../trellis' );
set( 'vm_root', '/srv/www/domain.com/current' );
````

### Valet+ environment
Expand Down
5 changes: 3 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
set( 'domain', basename(get('local_root')) );

// Bedrock DB config
set( 'vagrant_dir', get('local_root') . '/../trellis' );
set( 'vagrant_root', '/srv/www/' . get('domain') . '/current' );
set( 'trellis_dir', get('local_root') . '/../trellis' );
set( 'vm_root', '/srv/www/' . get('domain') . '/current' );
set( 'vm_shell', 'trellis vm shell --' ); // or 'vagrant ssh -- -t'

// Bedrock DB and Sage config
set( 'theme_path', function () { return getenv('THEME_PATH'); });
Expand Down
26 changes: 13 additions & 13 deletions recipe/bedrock_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* Deployer recipes to push Bedrock database from local development
* machine to a server and vice versa.
*
* Assumes that Bedrock runs locally on a Vagrant machine ans uses
* "vagrant ssh" command to run WP CLI on local server.
* Assumes that Bedrock runs locally on a Virtual machine and uses
* "vagrant ssh -- -t" (or whatever is defined as {{vm_shell}} ) command to run WP CLI on local server.
*
* Will always create a DB backup on the target machine.
*
* Requires these Deployer variables to be set:
* local_root: Absolute path to website root on local host machine
* vagrant_dir: Absolute path to directory that contains .vagrantfile
* vagrant_root: Absolute path to website inside Vagrant machine (should mirror local_root)
* trellis_dir: Absolute path to directory that contains trellis folder
* vm_root: Absolute path to website inside Virtual machine (should mirror local_root)
*/

namespace Deployer;
Expand Down Expand Up @@ -48,15 +48,15 @@
$backupFilename = '_db_backup_' . date('Y-m-d_H-i-s') . '.sql';
$backupAbsFile = get('local_root') . '/' . $backupFilename;
writeln("<comment>Making backup of DB on local machine to {$backupAbsFile}</comment>");
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp db export {$backupFilename}\"");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp db export {$backupFilename}\"");

// Empty local DB
writeln("<comment>Reset local DB</comment>");
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp db reset\"");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp db reset\"");

// Import export file
writeln("<comment>Importing {$downloadedExport}</comment>");
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp db import {$exportFilename}\"");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp db import {$exportFilename}\"");

// Load local .env file and get local WP URL
if (!$localUrl = $getLocalEnv()) {
Expand All @@ -77,11 +77,11 @@
// In the DB however, this new remote domain doesn't exist yet before search-replace. So we have
// to specify the old (remote) domain as --url parameter.
writeln("<comment>Updating the URLs in the DB</comment>");
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp search-replace '{$remoteUrl}' '{$localUrl}' --skip-themes --url='{$remoteDomain}' --network\"");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp search-replace '{$remoteUrl}' '{$localUrl}' --skip-themes --url='{$remoteDomain}' --network\"");
// Also replace domain (multisite WP also uses domains without protocol in DB)
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp search-replace '{$remoteDomain}' '{$localDomain}' --skip-themes --url='{$remoteDomain}' --network\"");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp search-replace '{$remoteDomain}' '{$localDomain}' --skip-themes --url='{$remoteDomain}' --network\"");
// Flush Permalinks
runLocally( "cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp rewrite flush --hard\"" );
runLocally( "cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp rewrite flush --hard\"" );

// Cleanup exports on local machine
writeln("<comment>Cleaning up {$downloadedExport} on local machine</comment>");
Expand All @@ -91,11 +91,11 @@
desc('Pushes DB from local machine to server and installs it, after having made a backup of server DB');
task('push:db', function () use ($getLocalEnv, $getRemoteEnv, $urlToDomain) {

// Export db on Vagrant server
// Export db on Virtual Machine
$exportFilename = '_db_export_' . date('Y-m-d_H-i-s') . '.sql';
$exportAbsFile = get('local_root') . '/' . $exportFilename;
writeln("<comment>Exporting Vagrant DB to {$exportAbsFile}</comment>");
runLocally("cd {{vagrant_dir}} && vagrant ssh -- -t \"cd {{vagrant_root}}; wp db export {$exportFilename}\"");
writeln("<comment>Exporting Virtual Machine DB to {$exportAbsFile}</comment>");
runLocally("cd {{trellis_dir}} && {{vm_shell}} \"cd {{vm_root}}; wp db export {$exportFilename}\"");

// Upload export to server
$uploadedExport = get('current_path') . '/' . $exportFilename;
Expand Down

0 comments on commit 34a0258

Please sign in to comment.