2017 © Pedro Peláez
 

wp-cli-package wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

image

opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  • Tuesday, January 16, 2018
  • by batosai
  • Repository
  • 4 Watchers
  • 3 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 22 Forks
  • 1 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Project maintainers welcomed

January, 2017, (*1)

WP-Cli Deploy

Current Version: 1.2.0, (*2)

Deploys the local WordPress database or uploads directory., (*3)

The tool requires defining a set of values in your wp-cli.yml file. The constants should be prefixed with the environment handle which you will use as the first parameter for your desired subcommand. An example configuration for a "dev" environment:, (*4)

@dev:
  path: /path/to/the/wp/dir/on/the/server
  url: the-remote-website-url.com
  host: ssh_host
  ssh_user: ssh_user
  port: ssh_port
  writable_path: /path/to/a/writable/dir/on/the/server
  uploads_path: /path/to/the/remote/uploads/directory
  themes_path: /path/to/the/remote/themes/directory
  plugins_path: /path/to/the/remote/plugins/directory
  db_host: the_remote_db_host
  db_name: the_remote_db_name
  db_user: the_remote_db_user
  db_password: the_remote_db_password
  excludes:
    - ".env"
    - "file_to_exclude.php"
    - ...

=> wp deploy push dev ..., (*5)

Not all commands / subcommands require all constants to be defined. To test what a subcommand requires, execute it with a non-existing environment handle. e.g. wp deploy dump dev., (*6)

You can define as many constant groups as deployment enviroments you wish to have., (*7)

Examples, (*8)

# Deploy the local db to the staging environment
wp deploy push staging --what=db

# Pull both the production database and uploads
wp deploy pull production --what=db && wp deploy pull production --what=uploads

# Pull both the production themes and plugins
wp deploy pull production --what=themes && wp deploy pull production --what=plugins

# Dump the local db with the siteurl replaced
wp deploy dump production

Configuration Dependecies

Subcommands depend on different constants in order to work. Here's the dependency list:, (*9)

  • wp deploy push: In order to push to your server, you need to define the ssh credentials, and a path to a writable directory on the server. These constants are needed whatever the arguments passed to the push subcommand:, (*10)

    • %%ENV%%_SSH_USER
    • %%ENV%%_HOST
    • %%ENV%%_WRITABLE_PATH
  • wp deploy push %%env%% --what=db: In order to deploy the database to your server, you need to define the url of your WordPress website, the path to the WordPress code on your server, and the credentials to the database on the server:, (*11)

    • %%ENV%%_URL
    • %%ENV%%_PATH
    • %%ENV%%_DB_HOST
    • %%ENV%%_DB_NAME
    • %%ENV%%_DB_USER
    • %%ENV%%_DB_PASSWORD
  • wp deploy push %%env%% --what=uploads: In order to push the uploads directory, you need to define the path to the uploads directory on your server:, (*12)

    • %%ENV%%_UPLOADS_PATH

    wp deploy pull: In order to pull to your server, you need to define the sh credentials constants. These constants are needed whatever the arguments assed to the pull subcommand:, (*13)

    • %%ENV%%_USER
    • %%ENV%%_HOST
  • wp deploy pull %%env%% --what=db: In order to pull the database to from your server, you need to define the url of your remote WordPress website, the path to the WordPress code on your server, and the credentials to the database on the server:, (*14)

    • %%ENV%%_WRITABLE_PATH
    • %%ENV%%_URL
    • %%ENV%%_PATH
    • %%ENV%%_DB_HOST
    • %%ENV%%_DB_NAME
    • %%ENV%%_DB_USER
    • %%ENV%%_DB_PASSWORD
  • wp deploy push %%env%% --what=uploads: As in the push command's case, in order to pull the remote server uploads, we need their path on the server., (*15)

    • %%ENV%%_UPLOADS_PATH
  • wp deploy push %%env%% --what=themes: As in the push command's case, in order to pull the remote server themes, we need their path on the server., (*16)

    • %%ENV%%_THEMES_PATH
  • wp deploy push %%env%% --what=themes --themename=mytheme: As in the push command's case, in order to pull the remote server specific theme, we need their path on the server., (*17)

    • %%ENV%%_THEMES_PATH
  • wp deploy push %%env%% --what=plugins: As in the push command's case, in order to pull the remote server plugins, we need their path on the server., (*18)

    • %%ENV%%_PLUGINS_PATH
  • wp deploy push %%env%% --what=core: As in the push command's case, in order to pull the remote server core, we need their path on the server., (*19)

    • %%ENV%%_PATH
  • wp dump %%env%%: This subcommand only requires the path to the target WordPress path and its URL., (*20)

%%ENV%%_POST_HOOK

You can optionally define a constant with bash code which is called at the end of the subcommand execution., (*21)

You can refer to environment variables using placeholders. Some of the available environment variables are: * env: The environment handle * command: The subcommand (Currently push, pull, or dump). * what: The what argument value for the push or pull subcommand. * wd: The path to the working directory for the deploy command. This is the directory where the database is pulled, and other temporary files are created. * timestamp: The date formatted with "Y_m_d-H_i" * tmp_path: The path to the temporary files directory used by the deploy tool. * bk_path: The path to the backups directory used by the deploy tool. * local_uploads: The path to the local WordPress instance uploads directory. * ssh: The ssh server handle in the user@host format., (*22)

Example, (*23)

Here's an example of a DEV_POST_HOOK that posts a message to a hipchat room after a pull or a push is performed using the HipChat REST API (https://github.com/hipchat/hipchat-cli). For pushes, it also clears the cache., (*24)

<?php
$hipchat_message = "http://%%url%%"
    . "\njeandoe has successfully %%command%%ed %%what%%";
$command = "if [[ '%%command%%' != 'dump' ]]; then "
        . "echo '$hipchat_message' | %%abspath%%/hipchat-cli/hipchat_room_message -t 1245678 -r 123456 -f 'WP-Cli Deploy';"
    . "fi;"
    . "if [[ '%%command%%' == 'push' ]]; then "
        . "curl -Ss http://example.com/clear_cache.php?token=12385328523;"
    . "fi;";
define( 'DEV_POST_HOOK', $command );

Credits, (*25)

  • Contributors: opsone
  • Fork of: terminalpixel
  • https://github.com/demental/wp-deploy-flow for inspiration.

The Versions

16/01 2018

dev-master

9999999-dev https://github.com/opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads

16/01 2018

v1.3.3

1.3.3.0 https://github.com/opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads

16/10 2017

v1.3.2

1.3.2.0 https://github.com/opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads

03/08 2017

v1.3.1

1.3.1.0 https://github.com/opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads

02/08 2017

v1.3.0

1.3.0.0 https://github.com/opsone/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads

28/02 2014

v1.0.0

1.0.0.0 https://github.com/c10b10/wp-cli-deploy

Deploys the local WordPress database or the uploads directory to a remote server using ssh.

  Sources   Download

MIT

The Requires

 

wordpress git wp-cli mysql dump deploy uploads