Bring New Travis CI Testing Online - Test 1

This commit is contained in:
Mitchell Krog 2017-06-01 16:26:24 +02:00
parent 0387e9ac7e
commit 556e1bdafa
24 changed files with 259 additions and 47 deletions

View file

@ -28,8 +28,8 @@ install:
- sudo add-apt-repository -y ppa:nginx/stable - sudo add-apt-repository -y ppa:nginx/stable
- sudo apt-get update - sudo apt-get update
- sudo apt-get install -y --force-yes nginx-extras - sudo apt-get install -y --force-yes nginx-extras
- travisCI/install-nginx.sh
script: script:
- travis-ci/install-nginx.sh
- sudo nginx -t &> /dev/stdout - sudo nginx -t &> /dev/stdout
- curl -vsf 'http://localhost:8080/nginx.php' &> /dev/stdout - curl -vsf 'http://localhost:8080/nginx.php' &> /dev/stdout
- curl -A "googlebot" http://localhost:8080/nginx.php &> /dev/stdout - curl -A "googlebot" http://localhost:8080/nginx.php &> /dev/stdout

View file

@ -0,0 +1,56 @@
#!/bin/bash
# Travis CI Code to Configure Nginx
set -e
set -x
DIR=$(realpath $(dirname "$0"))
USER=$(whoami)
PHP_VERSION=$(phpenv version-name)
ROOT=$(realpath "$DIR/..")
PORT=9000
SERVER="/tmp/php.sock"
function tpl {
sed \
-e "s|{DIR}|$DIR|g" \
-e "s|{USER}|$USER|g" \
-e "s|{PHP_VERSION}|$PHP_VERSION|g" \
-e "s|{ROOT}|$ROOT|g" \
-e "s|{PORT}|$PORT|g" \
-e "s|{SERVER}|$SERVER|g" \
< $1 > $2
}
# Make some working directories.
mkdir "$DIR/nginx"
mkdir "$DIR/nginx/sites-enabled"
mkdir "$DIR/nginx/bots.d"
mkdir "$DIR/var"
# Configure the PHP handler.
PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm"
PHP_FPM_CONF="$DIR/nginx/php-fpm.conf"
# Build the php-fpm.conf.
tpl "$DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF"
# Start php-fpm
"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF"
# Build the default nginx config files.
tpl "$DIR/nginx.tpl.conf" "$DIR/nginx/nginx.conf"
tpl "$DIR/fastcgi.tpl.conf" "$DIR/nginx/fastcgi.conf"
tpl "$DIR/ddos.tpl.conf" "$DIR/nginx/ddos.conf"
tpl "$DIR/blockbots.tpl.conf" "$DIR/nginx/blockbots.conf"
tpl "$DIR/whitelist-ips.tpl.conf" "$DIR/nginx/bots.d/whitelist-ips.conf"
tpl "$DIR/whitelist-domains.tpl.conf" "$DIR/nginx/bots.d/whitelist-domains.conf"
tpl "$DIR/blacklist-user-agents.tpl.conf" "$DIR/nginx/bots.d/blacklist-user-agents.conf"
tpl "$DIR/bad-referrer-words.tpl.conf" "$DIR/nginx/bots.d/bad-referrer-words.conf"
tpl "$DIR/custom-bad-referrers.tpl.conf" "$DIR/nginx/bots.d/custom-bad-referrers.conf"
tpl "$DIR/blacklist-ips.tpl.conf" "$DIR/nginx/bots.d/blacklist-ips.conf"
tpl "$DIR/botblocker-nginx-settings.tpl.conf" "$DIR/nginx/botblocker-nginx-settings.conf"
tpl "$DIR/globalblacklist.tpl.conf" "$DIR/nginx/globalblacklist.conf"
tpl "$DIR/default-site.tpl.conf" "$DIR/nginx/sites-enabled/default-site.conf"
# Start nginx.
nginx -c "$DIR/nginx/nginx.conf"

31
travisCI/change-file.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
cd $TRAVIS_BUILD_DIR
#Remove Remotes Added by TravisCI
git remote rm origin
#Add Remote with Secure Key
git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
#List Remotes ONLY DURING testing - do not do this on live repo / possible key leak
#git remote -v
# Set Git Variables
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
# Make sure we have master branch checked out in Git
git checkout master
# Modify our file and make sure Travis is owner
sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
sudo chown -R travis:travis $TRAVIS_BUILD_DIR/*
# Add the modified file to the and commit it
git add $TRAVIS_BUILD_DIR/globalblacklist.conf
git commit -am "V3.$YEAR.$MONTH.$TRAVIS_BUILD_NUMBER [ci skip]"
# Travis now moves to the before_deploy: section of .travis.yml

11
travisCI/default.vhost Normal file
View file

@ -0,0 +1,11 @@
server {
listen *:9000;
root /var/www/html;
server_name localhost;
charset UTF-8;
location / {
root /var/www/html/;
}
}

20
travisCI/deploy-package.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/bash
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
# Make Sure we are in the Build Directory
cd $TRAVIS_BUILD_DIR
# Create our Version Number
export GIT_TAG=V3.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
# Tag our release
git tag $GIT_TAG -a -m "V3.$YEAR.$MONTH.$TRAVIS_BUILD_NUMBER"
# Push our commit and tags back to the repo
sudo git push origin master && git push origin master --tags
# Uncomment to list all git folders and modified files etc
#ls -aR
# Now TravisCI moves into the deploy: section of TravisCI - see .travis.yml

5
travisCI/index.php Normal file
View file

@ -0,0 +1,5 @@
<?php
echo "Welcome to Nginx\n";
echo "This is the Travis Testing Environment for the Nginx Ultimate Bad Bot Blocker\n";
echo "Visit https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker\n";

View file

@ -1,56 +1,64 @@
#!/bin/bash #!/bin/bash
# Travis CI Code to Configure Nginx # Travis CI Testing for Nginx Ultimate Bad Bot Blocker
set -e # https://github.com/mitchellkrogza
set -x set -x
DIR=$(realpath $(dirname "$0")) # Check Date - I only used this for testing to make sure I had set timezone correctly
USER=$(whoami) # See .travis.yml file in the before_install section on how to set your timezone on TravisCI
PHP_VERSION=$(phpenv version-name) #date
ROOT=$(realpath "$DIR/..")
PORT=9000
SERVER="/tmp/php.sock"
function tpl { # Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
sed \
-e "s|{DIR}|$DIR|g" \
-e "s|{USER}|$USER|g" \
-e "s|{PHP_VERSION}|$PHP_VERSION|g" \
-e "s|{ROOT}|$ROOT|g" \
-e "s|{PORT}|$PORT|g" \
-e "s|{SERVER}|$SERVER|g" \
< $1 > $2
}
# Make some working directories. # Delete default site created by Nginx Installation
mkdir "$DIR/nginx" sudo rm /etc/nginx/sites-available/default
mkdir "$DIR/nginx/sites-enabled"
mkdir "$DIR/nginx/bots.d"
mkdir "$DIR/var"
# Configure the PHP handler. # Download the Nginx Bad Bot Blocker files from the Live Repository
PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm" sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
PHP_FPM_CONF="$DIR/nginx/php-fpm.conf" sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker -O /usr/sbin/setup-ngxblocker
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O /usr/sbin/update-ngxblocker
# Build the php-fpm.conf. # Set our install and setup scripts to be executable
tpl "$DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF" sudo chmod +x /usr/sbin/install-ngxblocker
sudo chmod +x /usr/sbin/setup-ngxblocker
sudo chmod +x /usr/sbin/update-ngxblocker
# Start php-fpm # Run Install-NgxBlocker
"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF" cd /usr/sbin
sudo ./install-ngxblocker -x
# Build the default nginx config files. # Copy our default.vhost file into Nginx /sites-available/
tpl "$DIR/nginx.tpl.conf" "$DIR/nginx/nginx.conf" sudo cp $TRAVIS_BUILD_DIR/travis-ci/default.vhost /etc/nginx/sites-available/default.vhost
tpl "$DIR/fastcgi.tpl.conf" "$DIR/nginx/fastcgi.conf"
tpl "$DIR/ddos.tpl.conf" "$DIR/nginx/ddos.conf"
tpl "$DIR/blockbots.tpl.conf" "$DIR/nginx/blockbots.conf"
tpl "$DIR/whitelist-ips.tpl.conf" "$DIR/nginx/bots.d/whitelist-ips.conf"
tpl "$DIR/whitelist-domains.tpl.conf" "$DIR/nginx/bots.d/whitelist-domains.conf"
tpl "$DIR/blacklist-user-agents.tpl.conf" "$DIR/nginx/bots.d/blacklist-user-agents.conf"
tpl "$DIR/bad-referrer-words.tpl.conf" "$DIR/nginx/bots.d/bad-referrer-words.conf"
tpl "$DIR/custom-bad-referrers.tpl.conf" "$DIR/nginx/bots.d/custom-bad-referrers.conf"
tpl "$DIR/blacklist-ips.tpl.conf" "$DIR/nginx/bots.d/blacklist-ips.conf"
tpl "$DIR/botblocker-nginx-settings.tpl.conf" "$DIR/nginx/botblocker-nginx-settings.conf"
tpl "$DIR/globalblacklist.tpl.conf" "$DIR/nginx/globalblacklist.conf"
tpl "$DIR/default-site.tpl.conf" "$DIR/nginx/sites-enabled/default-site.conf"
# Start nginx. # Link the vhost file into Nginx /sites-enabled/ and reload nginx
nginx -c "$DIR/nginx/nginx.conf" sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
#sudo service nginx reload
# Run setup-ngxblocker
cd /usr/sbin
sudo ./setup-ngxblocker -x
# NOTE: for Verbose Testing of any shell scripts use below format adding sh -x before running the script
# this helps a lot inside the TravisCI environment to see where a shell script may be failing
#sudo sh -x ./setup-ngxblocker -x
# Load our Nginx.conf file and reload Nginx
sudo nginx -c /etc/nginx/nginx.conf
#sudo service nginx reload
# Copy our index.php file into the default site's root folder
sudo cp $TRAVIS_BUILD_DIR/travis-ci/index.php /var/www/html/index.php
# Run update-ngxblocker test
cd /usr/sbin
sudo ./update-ngxblocker
# Reload nginx - no need to do this as update-ngxblocker does this for us
#sudo service nginx reload
# Set all our other setup and deploy scripts to be executable
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/deploy-package.sh
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/change-file.sh
# Travis now goes into the rest of the tests in the script: section of .travis.yml

View file

@ -0,0 +1,81 @@
#!/bin/bash
# Write Build Number into globalblacklist.conf
# Created by: https://github.com/mitchellkrogza (mitchellkrog@gmail.com)
# Copyright: Mitchell Krog - https://github.com/mitchellkrogza
# Start time of script generation
start=$(date +%s.%N)
versionyear=$(date +%Y)
versionmonth=$(date +%m)
MY_GIT_TAG=V3.$versionyear.$versionmonth.$TRAVIS_BUILD_NUMBER
# Temporary database files we create
_inputdbA=/tmp/lastupdated.db
# Declare Nginx template and temp variables
#_nginx=/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/conf.d/globalblacklist.conf
#_nginx2=/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/Engintron_for_cPanel_WHM_Configuration_Example/etc/nginx/conf.d/globalblacklist.conf
_tmpnginxA=tmpnginxA
_tmpnginxB=tmpnginxB
# Start and End Strings to Search for to do inserts into template
_startmarker="### Version Information #"
_endmarker="### Version Information ##"
# PRINT VERSION INFORMATION INTO GLOBALBLACKLIST FILE 1
# *****************************************************
LASTUPDATEIFS=$IFS
IFS=$'\n'
now="$(date)"
end=$(date +%s.%N)
echo $_startmarker >> $_tmpnginxA
runtime=$(python -c "print(${end} - ${start})")
printf "############################################\n### Version: "$MY_GIT_TAG"\n### Updated: "$now"\n### Generated In: "$runtime" seconds\n############################################\n" >> $_tmpnginxA
echo $_endmarker >> $_tmpnginxA
IFS=$LASTUPDATEIFS
mv $_tmpnginxA $_inputdbA
ed -s $_inputdbA<<\IN
1,/### Version Information #/d
/### Version Information ##/,$d
,d
.r /home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/conf.d/globalblacklist.conf
/### Version Information #/x
.t.
.,/### Version Information ##/-d
#,p
#,p used to print output replaced with w below to write
w /home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/conf.d/globalblacklist.conf
q
IN
rm $_inputdbA
# PRINT VERSION INFORMATION INTO GLOBALBLACKLIST FILE 2
# *****************************************************
LASTUPDATE2IFS=$IFS
IFS=$'\n'
now="$(date)"
end=$(date +%s.%N)
echo $_startmarker >> $_tmpnginxB
runtime=$(python -c "print(${end} - ${start})")
printf "############################################\n### Version: "$MY_GIT_TAG"\n### Updated: "$now"\n### Generated In: "$runtime" seconds\n############################################\n" >> $_tmpnginxB
echo $_endmarker >> $_tmpnginxB
IFS=$LASTUPDATE2IFS
mv $_tmpnginxB $_inputdbA
ed -s $_inputdbA<<\IN
1,/### Version Information #/d
/### Version Information ##/,$d
,d
.r /home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/Engintron_for_cPanel_WHM_Configuration_Example/etc/nginx/conf.d/globalblacklist.conf
/### Version Information #/x
.t.
.,/### Version Information ##/-d
#,p
#,p used to print output replaced with w below to write
w /home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/Engintron_for_cPanel_WHM_Configuration_Example/etc/nginx/conf.d/globalblacklist.conf
q
IN
rm $_inputdbA
exit 0