Enterwell icon
Vedran Blazenka

WWDW Part IV : The Enterwell’s way of WordPress

I set up everything, what now ?

Following this tutorial so far you have installed and configured a new server, added a new site and set up rocketeer so now you can deploy your website by simply calling deploy command. After using rocketeer in a few projects we noticed that there are a few things that could be automated using rocketeer.

We noticed that every WordPress project has few things in common. To start, we have to download WordPress, extract it to a folder in local development environment, create database for new project, add git repository, install and configure theme and so on. All those stuff are easy to do but they take time (and, as we know, time is money :D).

Even with rocketeer we have problems with syncing content (database, and files – uploads for example) between our developers who worked on the project, and even bigger problem of syncing the local content (in development environment) with the production content (for the sites we maintained). Over short period, our clients would update WordPress, plugins and themes on their own production sites but our development versions (and git versions) remained unchanged. So we needed a fast way to sync with the production.

Project setup automation

Creating a new WordPress project can be diveded in two parts. First part is downloading and installing WordPress itself and second part is setting up rocketeer for easy deployment. If you start working on an already created project you only need to configure rocketeer (second part). We created two scripts that do all the work for us. This scripts are bash scripts and to run in on Windows machines we use Cygwin (until this happens).

Setting up WordPress

First script is called start script. It prompts user for info it needs to create new project (project name, Git repository for project, custom theme name, custom plugin name etc.). After all the information was provided, scripts download the latest version of WordPress and extracts it to the working directory (new site folder). It sets up a new starter theme (we developed our own starter theme pack that we use for our custom themes, you can read more about this topic in one of our next blog posts), and a new starter plugin (we also developed our starter plugin, based on famous WordPress Plugin Boilerplate).

If you create a brand new project you’ll need to create a database for WordPress (easily done using phpmyadmin, or MySQL workbench) and install WordPress localy. Now you have a new WordPress set up and starter theme and plugin so you can start developing a new super-cool features. Everything is ready for the initial commit :D.

Setting up rocketeer

Second script is called ignite script (like rocketeer ignite command that configures rocketeer). It prompts for rocketeer related data (connection name, server address, SSH credentials, Git credentials, and other data required by rocketeer and its tasks – all described here). After collecting data (and if valid data was entered) script downloads and installs rocketeer (using composer), and uses data from user to configure it. After this script finishes you are able to deploy the first version of your site to test stage (or production if you really want to).

If you are working on an already created project, you don’t need to set up WordPress, you only pull source from git and call ignite script, because rocketeer (as well as its configuration) is not saved in  Git online repository.

Custom rocketeer tasks

We developed a few our own tasks to help us with WordPress development (in our team) and deployment. A few ways to create rocketeer tasks are explained here, and the most usefull for us was to create a new task by extending AbstractTask class. File where new task code is placed in a .rocketeer/tasks directory. After creating a task you’ll need to register your task in config to be able to use it. Task is registred by adding it to hooks.php file inside of .rocketeer config. After adding one new task this file should look like this

return
   [ 
     // Tasks to execute before the core Rocketeer Tasks
    'before' => [
        'setup'   => [],
        'deploy'  => [],
        'cleanup' => [],
     ],

    // Tasks to execute after the core Rocketeer Tasks
    'after'  => [
        'setup'   => [],
        'deploy'  => [],
        'cleanup' => [],
    ],

    // Custom Tasks to register with Rocketeer
    'custom' => [
        'customtask' => 'MyNamespace\CustomTask'
    ]
];

In this example we created a new task – a new PHP class with name CustomTask and namespace MyNamespace. File of this task is located in a .rocketeer/tasks folder and looks like this


namespace MyNamespace;

class CustomTask extends \Rocketeer\Abstracts\AbstractTask {

    protected $name = 'customtask';

    protected $description = "Custom task - does nothing.";

    protected $local = true;

    function execute() {

         $this->explainer->line("Custom task execution...");

    }
}

Important notes

Task name must be the same as the key in a custom array of hooks.php file (in both cases it is “customtask”).

This task will run locally (property $local is set to true).

Executing tasks

You can see all available rocketeer commands (and tasks) by running this command

rocketeer

Our custom task would be executed by running

rocketeer customtask

Enterwell’s tasks

For WordPress development purposes we created a few usefull tasks. Some of them are listed below:

  • local database backup task – this tasks exports local database (database in development environment) and saves it to the exports folder in the project root
  • remote database backup task – exports remote database (user selects connection of remote server), and downloads this export as .sql file into the exports folder in the project root directory
  • remote wp-content backup – this task compresses wp-content folder in the remote server and downloads it locally. It also prompts user to overwrite local wp-content and does so if user wants that. This task is usefull to quickly sync remote themes, plugins and uploads with the local (development) version. Using this task you can always have the same state in your development environment as in your production.

 

Info

This blog post is a part of Windows WordPress Development Workflow (WWDW) blog posts’ series. All blog posts in the series are:

  1. WWDW Part I : Server Configuration
  2. WWDW Part II : Create A New Site
  3. WWDW Part III : Rocketeer
  4. WWDW Part IV : Enterwell’s way

 

Share on FacebookTweet about this on TwitterShare on LinkedInShare on RedditEmail this to someone