Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

Commit 67c5cb6

Browse files
committed
Version one release
1 parent 2d60014 commit 67c5cb6

17 files changed

+2135
-2
lines changed

.github_changelog_generator

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unreleased=true
2+
future-release=1.0.0

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Composer ###
2+
/vendor/
3+
4+
### PhpStorm ###
5+
/.idea/

.travis.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
language: php
2+
3+
sudo: false
4+
5+
branches:
6+
only:
7+
- master
8+
- /^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/
9+
10+
services:
11+
- mysql
12+
13+
cache:
14+
apt: true
15+
directories:
16+
- $HOME/.composer/cache/files
17+
18+
addons:
19+
apt:
20+
packages:
21+
- nginx
22+
23+
notifications:
24+
email:
25+
on_success: never
26+
on_failure: change
27+
28+
php:
29+
- 7.0
30+
- 7.1
31+
- nightly
32+
33+
env:
34+
- WP_VERSION=nightly
35+
- WP_VERSION=latest
36+
- WP_VERSION=4.7.2
37+
38+
matrix:
39+
fast_finish: true
40+
41+
before_install:
42+
- export PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
43+
- export PATH="$TRAVIS_BUILD_DIR/bin:$PATH"
44+
- export TNW_TPL_DIR="$TRAVIS_BUILD_DIR/tpl"
45+
- composer install -n --prefer-dist --no-suggest
46+
47+
install:
48+
- tnw-install-nginx
49+
- tnw-install-wordpress
50+
- tnw-prepare-codeception
51+
- tnw-install-wpcs
52+
53+
script:
54+
### Assert that WordPress is served at `http://wp.dev:8080`
55+
# Echo the WordPress Homepage source code
56+
- curl -vsf 'http://wp.dev:8080' &> /dev/stdout
57+
58+
# Show the wp-config.php source code
59+
- cat /tmp/wordpress/wp-config.php
60+
61+
# There should be nothing in the Nginx error log
62+
- cat /tmp/error.log
63+
64+
# Display the WordPress version.
65+
- wp core version --path=/tmp/wordpress
66+
67+
# Show a list of installed coding standards
68+
- phpcs -i

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2017 Tang Rufus
3+
Copyright (c) 2017 Tang Rufus https://www.typist.tech/
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Travis CI Nginx WordPress Test
2+
3+
[![Latest Stable Version](https://poser.pugx.org/typisttech/travis-nginx-wordpress/v/stable)](https://packagist.org/packages/typisttech/travis-nginx-wordpress)
4+
[![Total Downloads](https://poser.pugx.org/typisttech/travis-nginx-wordpress/downloads)](https://packagist.org/packages/typisttech/travis-nginx-wordpress)
5+
[![Build Status](https://travis-ci.org/TypistTech/travis-nginx-wordpress.svg?branch=master)](https://travis-ci.org/TypistTech/travis-nginx-wordpress)
6+
[![PHP Versions Tested](http://php-eye.com/badge/typisttech/travis-nginx-wordpress/tested.svg)](https://travis-ci.org/TypistTech/travis-nginx-wordpress)
7+
[![Latest Unstable Version](https://poser.pugx.org/typisttech/travis-nginx-wordpress/v/unstable)](https://packagist.org/packages/typisttech/travis-nginx-wordpress)
8+
[![Dependency Status](https://gemnasium.com/badges/github.com/TypistTech/travis-nginx-wordpress.svg)](https://gemnasium.com/github.com/TypistTech/travis-nginx-wordpress)
9+
[![License](https://poser.pugx.org/typisttech/travis-nginx-wordpress/license)](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.

bin/tnw-install-nginx

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
function tnw-tpl {
4+
sed \
5+
-e "s|{WP_CORE_DIR}|$WP_CORE_DIR|g" \
6+
-e "s|{WP_PORT}|$WP_PORT|g" \
7+
-e "s|{TNW_NGINX_DIR}|$TNW_NGINX_DIR|g" \
8+
-e "s|{USER}|$USER|g" \
9+
-e "s|{PHP_VERSION}|$PHP_VERSION|g" \
10+
-e "s|{PORT}|$PORT|g" \
11+
-e "s|{SERVER}|$SERVER|g" \
12+
< $1 > $2
13+
}
14+
15+
function tnw-install-nginx {
16+
TNW_TPL_DIR=${TNW_TPL_DIR-$HOME/.composer/vendor/typisttech/travis-nginx-wordpress/tpl}
17+
TNW_NGINX_DIR=${TNW_NGINX_DIR-$HOME/nginx}
18+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
19+
WP_PORT=${WP_PORT-8080}
20+
USER=$(whoami)
21+
PHP_VERSION=$(phpenv version-name)
22+
PORT=9000
23+
SERVER="/tmp/php.sock"
24+
25+
# Make some working directories.
26+
mkdir -p "$TNW_NGINX_DIR"
27+
mkdir -p "$TNW_NGINX_DIR/sites-enabled"
28+
mkdir -p "$TNW_NGINX_DIR/var"
29+
30+
PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm"
31+
PHP_FPM_CONF="$TNW_NGINX_DIR/php-fpm.conf"
32+
33+
# Build the php-fpm.conf.
34+
tnw-tpl "$TNW_TPL_DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF"
35+
36+
# Start php-fpm
37+
"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF"
38+
39+
# Build the default nginx config files.
40+
tnw-tpl "$TNW_TPL_DIR/nginx.tpl.conf" "$TNW_NGINX_DIR/nginx.conf"
41+
tnw-tpl "$TNW_TPL_DIR/fastcgi.tpl.conf" "$TNW_NGINX_DIR/fastcgi.conf"
42+
tnw-tpl "$TNW_TPL_DIR/default-site.tpl.conf" "$TNW_NGINX_DIR/sites-enabled/default-site.conf"
43+
44+
# Start nginx.
45+
nginx -c "$TNW_NGINX_DIR/nginx.conf"
46+
}
47+
48+
tnw-install-nginx

bin/tnw-install-wordpress

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
function tnw-install-wordpress {
4+
WP_DOMAIN=${WP_DOMAIN-wp.dev}
5+
WP_PORT=${WP_PORT-8080}
6+
ADMIN_USER=${ADMIN_USER-admin}
7+
ADMIN_PASSWORD=${ADMIN_PASSWORD-password}
8+
ADMIN_EMAIL=${ADMIN_EMAIL-admin@wp.dev}
9+
WP_TITLE=${WP_TITLE-'Brought to you by Typist Tech'}
10+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
11+
DB_HOST=${DB_HOST-localhost}
12+
DB_NAME=${DB_NAME-wordpress}
13+
DB_USER=${DB_USER-root}
14+
WP_VERSION=${WP_VERSION-latest}
15+
WP_LOCALE=${WP_LOCALE-en_US}
16+
17+
# Prepare WordPress database
18+
mysql -u root -e "create database IF NOT EXISTS $DB_NAME"
19+
20+
# Install WordPress
21+
wp core download --version=$WP_VERSION --locale=$WP_LOCALE --force --path=$WP_CORE_DIR
22+
23+
wp core config --dbname=$DB_NAME --dbuser=$DB_USER --dbhost=$DB_HOST --locale=$WP_LOCALE --force --path=$WP_CORE_DIR --extra-php <<PHP
24+
define( 'AUTOMATIC_UPDATER_DISABLED', true );
25+
PHP
26+
27+
wp core install --url="$WP_DOMAIN:$WP_PORT" --admin_user=$ADMIN_USER --admin_password=$ADMIN_PASSWORD --admin_email=$ADMIN_EMAIL --title="$WP_TITLE" --skip-email --path=$WP_CORE_DIR
28+
}
29+
30+
tnw-install-wordpress

bin/tnw-install-wpcs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
function tnw-install-wpcs {
4+
WPCS_DIR=${WPCS_DIR-$HOME/wpcs}
5+
6+
git clone --depth=1 -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR
7+
phpcs --config-set installed_paths $WPCS_DIR
8+
}
9+
10+
tnw-install-wpcs

bin/tnw-prepare-codeception

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
function tnw-prepare-codeception {
4+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
5+
DB_DUMP=${DB_DUMP-$TRAVIS_BUILD_DIR/tests/_data/dump.sql}
6+
DB_NAME_INT=${DB_NAME_INT-wordpress_int}
7+
8+
mysql -u root -e "create database IF NOT EXISTS $DB_NAME_INT"
9+
10+
if [ -f $DB_DUMP ]; then
11+
# Import DB dump
12+
wp db import $DB_DUMP --path=$WP_CORE_DIR;
13+
else
14+
# Create directory if not exists
15+
mkdir -p "$(dirname "$DB_DUMP")";
16+
fi
17+
18+
# Upgrade DB
19+
wp core update-db --path=$WP_CORE_DIR
20+
# Export a dump of the just installed database to the _data folder
21+
wp db export $DB_DUMP --path=$WP_CORE_DIR
22+
}
23+
24+
tnw-prepare-codeception

bin/tnw-send-result-to-saucelabs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
function tnw-sauce-test-result {
4+
if [[ "$TRAVIS_TEST_RESULT" == "0" ]]
5+
then
6+
echo true
7+
else
8+
echo false
9+
fi
10+
}
11+
12+
function tnw-sauce-job-id {
13+
TNW_SAUCE_BUILD=${TNW_SAUCE_BUILD-$TRAVIS_JOB_NUMBER}
14+
15+
echo $(curl -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY https://saucelabs.com/rest/v1/$SAUCE_USERNAME/jobs\?full=true\&format=json | jq ".[] | select(.build == \"$TNW_SAUCE_BUILD\") | .id" | sed -e 's/^"//' -e 's/"$//')
16+
}
17+
18+
function tnw-send-result-to-saucelabs {
19+
TNW_SAUCE_JOB_ID=${TNW_SAUCE_JOB_ID-$(tnw-sauce-job-id)}
20+
TNW_SAUCE_TEST_RESULT=${TNW_SAUCE_TEST_RESULT-$(tnw-sauce-test-result)}
21+
22+
curl -X PUT \
23+
-H 'Content-Type: application/json' \
24+
-s -d "{ \"passed\": $TNW_SAUCE_TEST_RESULT }" \
25+
-u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \
26+
https://saucelabs.com/rest/v1/$SAUCE_USERNAME/jobs/$TNW_SAUCE_JOB_ID
27+
}
28+
29+
tnw-send-result-to-saucelabs

0 commit comments

Comments
 (0)