Making My CI Server
Tinkering with building some WP plugins and themes.
Goal: A Continuous Integration Server for PHP Projects
If using AWS, then of all the images to choose from, we would want to select an Amazon Linux AMI, if using VirtualBox would use a CentOS box with guest additions already added. Both the Amazon Linux AMI and CentOS are compatible with RHEL and therefore each other for the most part.
Clear out those iptables
$ sudo /sbin/iptables -F
Down the road, I will make this a bit more refined by opening only the ports we need
$ yum install java-1.6.0-openjdk
Caveat Developer! You need to be careful with your yum. On many a Linux distribution, you might just sudo yum install java but not here. And why? Because everything with CentOS has to be hairy, doesn’t it? We need to install Sun’s Java. This page has the details.
Let’s start by installing PHP and MySQL:
$ sudo yum install mysql-server $ sudo service mysqld start $ sudo yum install php php-mysql $ sudo yum install php php-cli $ sudo service httpd restart
Above LAMP steps recapped here
Note that the above does not leave you with a running mysql!! Gotta start that thing up with sudo service mysql start
Now install Jenkins:
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo $ sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key $ sudo yum install jenkins $ sudo service jenkins start
Now PHP Unit:
$ wget https://phar.phpunit.de/phpunit.phar $ chmod +x phpunit.phar $ sudo mv phpunit.phar /usr/local/bin/phpunit $ phpunit --version
SECURE JENKINS:
Enable Matrix based security
Give self account
Actually sign up for that account
For now, this has to be done manually, but I will soon research if it can be done via Jenkins CLI.
Now, to get our machine ready for WordPress unit testing
WORDPRESS CLI FOR DEVELOPMENT!
MAIN PAGE ABOUT THIS: http://wp-cli.org/#install
Let’s install WordPress CLI
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $ php wp-cli.phar --info $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp
UNIT TESTS FOR WORDPRESS PLUGINS:
Recapped here
First we need to install the WordPress developer suite:
# Make the directory for the tools (assumes that ~/svn exists; # you can create it by running "$ mkdir ~/svn") $ mkdir ~/svn/wordpress-dev # Change to the new directory we just made. $ cd ~/svn/wordpress-dev # Check out the developer tools with SVN. $ svn co http://develop.svn.wordpress.org/trunk/
Next you will need to follow the instructions in the /trunk/tests/phpunit/README.txt
file to set up the tests configuration. Once that is done, if you want to run the tests for WordPress itself, just run the phpunit
command from the /trunk
directory.
First, let’s do this one step at a time:
$ mysql -u root -p #Then within the mysql cli mysql> create database wp_test_database; mysql> grant all on wp_test_database.* to 'wptestuser'@'localhost' identified by 'vagrant'; mysql> exit;
But let’s keep in mind we want to automate all this in a Vagrant with Puppet. So let’s accomplish all of the above with a single line:
$ mysql -u root --password= -e "create database wp_test_database;grant all on wp_test_database.* to 'wptestuser'@'localhost' identified by 'vagrant';"
Let’s take the above single line one step further. We don’t want to lose track of where we are at in this process. But since we’re at this point, let’s take a quick look at the syntax we would give this in a puppet script:
exec {"wait-for-mysqld": require => Service["mysqld"], command => "mysql -u root --password= -e \"create database wp_test_database;grant all on wp_test_database.* to 'wptestuser'@'localhost' identified by 'vagrant';\"", }
(Won’t move on to specific plugin right now because the scope of this article is configuring the server)
Last notes to be addressed in the future
Enable Rewrite Module for WordPress rewrites
$ sudo vi /etc/httpd/conf.d
Then uncomment this line:
LoadModule rewrite_module
And change the line which indicates AllowOverride None to AllowOverride All
(Note – this sort of manual way of enabling the module may not really be necessary because I have now modified the manifest to handle this earlier and that seemed to fix things.)