|
| 1 | +# Travis CI Nginx WordPress Test |
| 2 | + |
| 3 | +[](https://packagist.org/packages/typisttech/travis-nginx-wordpress) |
| 4 | +[](https://packagist.org/packages/typisttech/travis-nginx-wordpress) |
| 5 | +[](https://travis-ci.org/TypistTech/travis-nginx-wordpress) |
| 6 | +[](https://travis-ci.org/TypistTech/travis-nginx-wordpress) |
| 7 | +[](https://packagist.org/packages/typisttech/travis-nginx-wordpress) |
| 8 | +[](https://gemnasium.com/github.com/TypistTech/travis-nginx-wordpress) |
| 9 | +[](https://packagist.org/packages/typisttech/travis-nginx-wordpress) |
| 10 | + |
| 11 | + |
| 12 | +A basic template for Nginx and WordPress running on Travis CI's container based infrastructure. |
| 13 | + |
| 14 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 15 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 16 | + |
| 17 | + |
| 18 | +- [What is the purpose of this repo?](#what-is-the-purpose-of-this-repo) |
| 19 | +- [Installation and Usage](#installation-and-usage) |
| 20 | +- [Customization](#customization) |
| 21 | +- [How does the installation works?](#how-does-the-installation-works) |
| 22 | + - [WordPress](#wordpress) |
| 23 | + - [Nginx](#nginx) |
| 24 | +- [Known issues](#known-issues) |
| 25 | +- [See also](#see-also) |
| 26 | +- [Credit](#credit) |
| 27 | +- [License](#license) |
| 28 | + |
| 29 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 30 | + |
| 31 | +## What is the purpose of this repo? |
| 32 | + |
| 33 | +Do you need to run some automated tests that rely on Nginx on Travis CI? Do you want those tests to run on the Docker |
| 34 | +[container-based infrastructure](http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/)? |
| 35 | +Are you pulling your hair out trying to get this all to work? Then this repo is for you. |
| 36 | + |
| 37 | +Travis CI does not come with Nginx pre-installed so the install needs to be scripted. Since Travis CI's container-based |
| 38 | +infrastructure doesn't allow sudo privileges this installation is non-trivial. Hopefully, by providing this repo |
| 39 | +I can save someone some hassle trying to get Nginx set up for their project. |
| 40 | + |
| 41 | +## Installation and Usage |
| 42 | + |
| 43 | +The script is tailored on Travis CI PHP build images and might not work in every situation. Below is an basic example of `.travis.yml`: |
| 44 | + |
| 45 | +```yml |
| 46 | +# .travis.yml |
| 47 | + |
| 48 | +language: php |
| 49 | + |
| 50 | +sudo: false |
| 51 | + |
| 52 | +services: |
| 53 | + - mysql |
| 54 | + |
| 55 | +cache: |
| 56 | + apt: true |
| 57 | + directories: |
| 58 | + - $HOME/.composer/cache/files |
| 59 | + |
| 60 | +addons: |
| 61 | + apt: |
| 62 | + packages: |
| 63 | + - jq |
| 64 | + - nginx |
| 65 | + |
| 66 | +php: |
| 67 | + - 7.0 |
| 68 | + - 7.1 |
| 69 | + |
| 70 | +env: |
| 71 | + - WP_VERSION=latest |
| 72 | + - WP_VERSION=4.7.2 |
| 73 | + |
| 74 | +before_install: |
| 75 | + # Install helper scripts |
| 76 | + - composer global require -n --prefer-dist "typisttech/travis-nginx-wordpress:^0.1.2" |
| 77 | + - tnw-install-nginx |
| 78 | + - tnw-install-wordpress |
| 79 | + - tnw-prepare-codeception |
| 80 | + - tnw-install-wpcs |
| 81 | + |
| 82 | +install: |
| 83 | + # Build the test suites |
| 84 | + - cd $TRAVIS_BUILD_DIR |
| 85 | + - composer install -n --prefer-dist |
| 86 | + - vendor/bin/codecept build |
| 87 | + |
| 88 | +script: |
| 89 | + # Run the tests |
| 90 | + - cd $TRAVIS_BUILD_DIR |
| 91 | + - vendor/bin/codecept run |
| 92 | + - phpcs --standard=ruleset.xml |
| 93 | + |
| 94 | +after_script: |
| 95 | + - tnw-send-result-to-saucelabs |
| 96 | + - tnw-upload-coverage-to-scrutinizer |
| 97 | +``` |
| 98 | +
|
| 99 | +## Customization |
| 100 | +
|
| 101 | +The default scripts install WordPress core on `/tmp/wordpress` and serve it at `http://wp.dev:8080`. |
| 102 | + |
| 103 | +You can customize the build via environment variables. Check the variables of the functions in the `/bin` folder for available configuration. |
| 104 | + |
| 105 | +## How does the installation works? |
| 106 | + |
| 107 | +All of the setup scripts are located in the [bin](./travis) directory and template files are in the [tpl](./tpl) directory. They are short and basic so it should be relatively easy to follow. The other scripts are basic Nginx and php-fpm configuration templates. The repository defines 6 setup scripts: |
| 108 | + |
| 109 | +1. `tnw-install-wordpress` |
| 110 | + - Install WordPress |
| 111 | +1. `tnw-install-nginx` |
| 112 | + - Setup Nginx to serve a website from a folder on a local domain |
| 113 | +1. `tnw-prepare-codeception` |
| 114 | + - Install [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) and [WordPress coding standard](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) |
| 115 | +1. `tnw-install-wpcs` |
| 116 | + - Prepare [Codeception](http://codeception.com/) environment |
| 117 | +1. `tnw-send-result-to-saucelabs` |
| 118 | + - Send Travis test result to [SauceLabs](https://saucelabs.com/) |
| 119 | +1. `tnw-upload-coverage-to-scrutinizer` |
| 120 | + - Upload test coverage to [Scrutinizer](https://scrutinizer-ci.com) |
| 121 | + |
| 122 | +### WordPress |
| 123 | + |
| 124 | +The WordPress installation is done through the |
| 125 | +[tnw-install-wordpress](./bin/tnw-install-wordpress) bash script. The basic install process goes as follows: |
| 126 | + |
| 127 | +1. Create the WordPress database. |
| 128 | +1. Download WordPress core. |
| 129 | +1. Generate the `wp-config.php` file. |
| 130 | + - Note that we added `define( 'AUTOMATIC_UPDATER_DISABLED', true );`. |
| 131 | +1. Install the WordPress database. |
| 132 | + |
| 133 | +### Nginx |
| 134 | + |
| 135 | +The Nginx installation is done through the |
| 136 | +[install-nginx](./bin/install-nginx) bash script. The basic install process goes as follows: |
| 137 | + |
| 138 | +1. Install Nginx using the [apt addon](https://docs.travis-ci.com/user/installing-dependencies/#Installing-Packages-with-the-APT-Addon) via entries in the [.travis.yml](./.travis.yml) file. |
| 139 | +1. Copy the configuration templates to a new directory while replacing placeholders with environment variables. |
| 140 | +1. Start php-fpm and Nginx with our custom configuration file instead of the default. |
| 141 | + |
| 142 | +## Known issues |
| 143 | + |
| 144 | +* Nginx gives alert messages during start which is safe to ignore. |
| 145 | + ``` |
| 146 | + $ install-nginx |
| 147 | + [26-Dec-2046 00:00:00] NOTICE: [pool travis] 'user' directive is ignored when FPM is not running as root |
| 148 | + nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) |
| 149 | + ``` |
| 150 | +
|
| 151 | +## See also |
| 152 | +
|
| 153 | +* [Running Nginx as a Non-Root User](https://www.exratione.com/2014/03/running-nginx-as-a-non-root-user/) |
| 154 | +* [Travis CI Nginx Test (the original repo)](https://github.com/tburry/travis-nginx-test) |
| 155 | +* [Travis CI Apache Virtualhost configuration script](https://github.com/lucatume/travis-apache-setup) |
| 156 | +
|
| 157 | +## Credit |
| 158 | +
|
| 159 | +[Travis CI Nginx WordPress Test](https://github.com/TypistTech/travis-nginx-wordpress) is originally forked from the [Travis CI Nginx Test](https://github.com/tburry/travis-nginx-test) project. Special thanks to its author [Todd Burry](https://github.com/tburry). |
| 160 | +
|
| 161 | +## License |
| 162 | +
|
| 163 | +[Travis CI Nginx WordPress Test](https://github.com/TypistTech/travis-nginx-wordpress) is released under the MIT License. |
0 commit comments