Last active
December 27, 2018 16:51
-
-
Save ApatheticCosmos/9f0f2848ac205134daf2578c40e2d372 to your computer and use it in GitHub Desktop.
Duplicating SuiteCRM Travis Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Ubuntu: | |
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" | |
$ sudo apt install docker-ce | |
$ sudo usermod -aG docker ${USER} | |
You will need to log out and back it so your shell is in group 'docker', or you can run "su - ${USER}". | |
Then get the docker image and run it: | |
$ docker run --rm --name travis -dit travisci/ci-garnet:packer-1512502276-986baf0 | |
This will download and start the instance. the "--rm" means that when the instance is stopped, it wipes all changes. | |
suitecrm-travis.sh is a shell script you'll want to run from INSIDE the docker instance. | |
You'll want to set the PHP_VERS, BRANCH, and REPO variables to your own. | |
Download it and copy it to the instance like this: | |
$ docker cp /path/to/suitecrm-travis.sh travis:/usr/local/bin/ | |
Log in to it: | |
$ docker exec -u travis -it travis bash -lc "cd ~; bash -l" | |
Set the script we copied into the container to executible (this is inside the container): | |
$ sudo chmod +x /usr/local/bin/suitecrm-travis.sh | |
Then run the script | |
$ suitecrm-travis.sh | |
When it's done you'll have a clean environment to run the tests in. | |
When you're done, exit the travis container shell and run: | |
$ docker stop travis | |
This will stop the container. The next time you run it, it'll be clean of all changes made to it. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export PHP_VERS='7.2' | |
export BRANCH='debug_tests_1' | |
export REPO='https://github.com/ApatheticCosmos/SuiteCRM.git' | |
export LOCAL_DIR='builds/SuiteCRM' | |
cd ~ | |
sudo service elasticsearch start | |
export CHROME_SOURCE_URL=https://dl.google.com/dl/linux/direct/google-chrome-stable_current_amd64.deb | |
wget --no-verbose -O /tmp/$(basename $CHROME_SOURCE_URL) $CHROME_SOURCE_URL | |
sudo dpkg -i /tmp/$(basename $CHROME_SOURCE_URL) | |
# Disable chromes sandbox | |
sed -i '${s/$/\ --no-sandbox/}' /opt/google/chrome/google-chrome | |
cd ~/bin | |
wget https://chromedriver.storage.googleapis.com/2.36/chromedriver_linux64.zip | |
unzip -o chromedriver_linux64.zip | |
./chromedriver --url-base=/wd/hub & | |
cd ~ | |
git clone --branch=$BRANCH $REPO $LOCAL_DIR | |
cd $LOCAL_DIR | |
export INSTANCE_URL=http://localhost | |
export DATABASE_DRIVER=MYSQL | |
export DATABASE_NAME=automated_tests | |
export DATABASE_HOST=localhost | |
export DATABASE_USER=automated_tests | |
export DATABASE_PASSWORD=automated_tests | |
export INSTANCE_ADMIN_USER=admin | |
export INSTANCE_ADMIN_PASSWORD=admin1 | |
export COMPOSER_MEMORY_LIMIT=-1 | |
export PHP_72_ARCHIVE="https://s3.amazonaws.com/travis-php-archives/binaries/ubuntu/14.04/x86_64/php-7.2.tar.bz2" | |
if ! phpenv global $PHP_VERS 2>/dev/null ; then | |
echo "Downloading PHP 7.2" | |
curl -s -o archive.tar.bz2 $PHP_72_ARCHIVE && sudo tar xjf archive.tar.bz2 --directory / | |
if ! phpenv global $PHP_VERS; then | |
echo "FATAL ERROR: FAILED TO SET PHP VERSION TO $PHP_VERS" | |
exit 1 | |
fi | |
fi | |
phpenv config-add travis.php.ini | |
composer self-update && composer --version | |
mysql -e "CREATE DATABASE automated_tests CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" | |
mysql -u root -e "CREATE USER 'automated_tests'@'localhost' IDENTIFIED BY 'automated_tests';" | |
mysql -u root -e "GRANT ALL PRIVILEGES ON automated_tests.* TO 'automated_tests'@'localhost';" | |
sudo apt-get update | |
sudo apt-get install apache2 libapache2-mod-fastcgi | |
# Enable php-fpm - images with PHP 7 or above | |
sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf 2>/dev/null || true | |
sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf | |
sudo a2enmod rewrite actions fastcgi alias | |
echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini | |
sudo sed -i -e "s,www-data,travis,g" /etc/apache2/envvars | |
sudo chown -R travis:travis /var/lib/apache2/fastcgi | |
~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm | |
# Configure apache virtual hosts - images with PHP 7 or above | |
sudo cp -f build/travis-ci-apache /etc/apache2/sites-available/000-default.conf | |
sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf | |
# Additional PHP config | |
phpenv config-add travis.php.ini | |
sudo service apache2 restart | |
# Install composer | |
rm composer.lock | |
composer install | |
./vendor/bin/codecept build | |
# Run the wizard installer | |
echo "using install wizard" | |
./vendor/bin/codecept run install --env travis-ci-hub -f -vvv -d | |
# Save Database so we can use it later. | |
mysqldump automated_tests > ~/database.sql | |
echo "Database backed up to ~/database.sql" | |
echo "You can restore it by running:" | |
echo "mysql automated_tests < ~/database.sql" | |
sudo chmod -R 777 . | |
echo "Test Environment Ready!" | |
cd ~ | |
echo "Your repo is in $PWD/$LOCAL_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment