Skip to content

Commit b819aff

Browse files
committed
Added proper installation and test scripts
Added a script for package installation, as well as running the tests, and changed Travis to use that script
1 parent e9374db commit b819aff

File tree

9 files changed

+199
-14
lines changed

9 files changed

+199
-14
lines changed

.travis.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,11 @@ before_install:
77
- sudo apt-get update
88

99
before_script:
10-
- cd Symfony
11-
- cp app/config/parameters.yml.dist app/config/parameters.yml
12-
- composer install
13-
- sudo apt-get install -y unzip
14-
- sudo mkdir /opt/codebender
15-
- wget https://github.com/codebendercc/arduino-core-files/archive/master.zip
16-
- unzip master.zip
17-
- sudo cp -r arduino-core-files-master /opt/codebender/codebender-arduino-core-files
18-
- rm master.zip
19-
- wget https://github.com/codebendercc/external_cores/archive/master.zip
20-
- unzip master.zip
21-
- sudo cp -r external_cores-master /opt/codebender/external-core-files
22-
10+
- scripts/install.sh
11+
- cd /opt/codebender/compiler/Symfony
2312
script:
2413
- mkdir -p build/logs
25-
- phpunit -c app/ --coverage-clover build/logs/clover.xml
14+
- ../scripts/run_tests.sh
2615

2716
after_script:
2817
- php composer.phar update satooshi/php-coveralls --dev

apache-config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<VirtualHost *:80>
2+
ServerAdmin root@localhost
3+
DocumentRoot /opt/codebender/compiler/Symfony/web/
4+
DirectoryIndex app.php
5+
6+
<Directory /opt/codebender/compiler/Symfony/web>
7+
Options -Indexes FollowSymLinks MultiViews
8+
AllowOverride All
9+
Order allow,deny
10+
Allow from all
11+
</Directory>
12+
</VirtualHost>

scripts/clear_cache.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
echo "Clearing the cache"
4+
php app/console cache:clear --env=dev
5+
php app/console cache:clear --env=prod
6+
php app/console cache:clear --env=test

scripts/install.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/bash
2+
set -x
3+
set -e
4+
5+
PACKAGENAME=compiler
6+
7+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
8+
echo "Configuring environment for Linux"
9+
sudo apt-get update
10+
if [[ ! $TRAVIS ]]; then
11+
# Ubuntu Server (on AWS?) lacks UTF-8 for some reason. Give it that
12+
sudo locale-gen en_US.UTF-8
13+
# Make sure we have up-to-date stuff
14+
sudo apt-get install -y php5-intl
15+
fi
16+
# Install dependencies
17+
sudo apt-get install -y apache2 libapache2-mod-php5 php-pear php5-curl php5-sqlite acl curl git
18+
# Enable Apache configs
19+
sudo a2enmod rewrite
20+
sudo a2enmod alias
21+
# Restart Apache
22+
sudo service apache2 restart
23+
elif [[ "$OSTYPE" == "darwin"* ]]; then
24+
# is there something comparable to this on os x? perhaps Homebrew
25+
echo "Configuring environment for OS X"
26+
fi
27+
28+
if [[ ! $TRAVIS ]]; then
29+
#### Set Max nesting lvl to something Symfony is happy with
30+
export ADDITIONAL_PATH=`php -i | grep -F --color=never 'Scan this dir for additional .ini files'`
31+
echo 'xdebug.max_nesting_level=256' | sudo tee ${ADDITIONAL_PATH:42}/symfony2.ini
32+
fi
33+
34+
if [[ $TRAVIS ]]; then
35+
HTTPDUSER="root"
36+
else
37+
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
38+
fi
39+
40+
if [[ ${#HTTPDUSER} -eq 0 ]]; then
41+
echo "Failed to set HTTPDUSER"
42+
echo `ps aux`
43+
exit 1
44+
fi
45+
46+
sudo mkdir -p /opt/codebender
47+
sudo cp -r . /opt/codebender/$PACKAGENAME
48+
sudo chown -R `whoami`:$HTTPDUSER /opt/codebender/$PACKAGENAME
49+
cd /opt/codebender/$PACKAGENAME
50+
51+
#Set permissions for app/cache and app/logs
52+
53+
rm -rf Symfony/app/cache/*
54+
rm -rf Symfony/app/logs/*
55+
56+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
57+
58+
if [[ ! $TRAVIS ]]; then
59+
60+
sudo dd if=/dev/zero of=cache-fs bs=1024 count=0 seek=200000
61+
sudo dd if=/dev/zero of=logs-fs bs=1024 count=0 seek=200000
62+
63+
yes | sudo mkfs.ext4 cache-fs
64+
yes | sudo mkfs.ext4 logs-fs
65+
66+
mkdir -p `pwd`/Symfony/app/cache/
67+
mkdir -p `pwd`/Symfony/app/logs/
68+
69+
echo "`pwd`/cache-fs `pwd`/Symfony/app/cache/ ext4 loop,acl 0 0" | sudo tee -a /etc/fstab > /dev/null 2>&1
70+
echo "`pwd`/logs-fs `pwd`/Symfony/app/logs/ ext4 loop,acl 0 0" | sudo tee -a /etc/fstab > /dev/null 2>&1
71+
cat /etc/fstab
72+
73+
sudo mount `pwd`/Symfony/app/cache/
74+
sudo mount `pwd`/Symfony/app/logs/
75+
76+
sudo rm -rf `pwd`/Symfony/app/cache/*
77+
sudo rm -rf `pwd`/Symfony/app/logs/*
78+
79+
sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs
80+
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs
81+
fi
82+
83+
elif [[ "$OSTYPE" == "darwin"* ]]; then
84+
85+
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
86+
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs
87+
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs
88+
fi
89+
90+
cd Symfony
91+
92+
# TODO: generate parameters.yml file somehow
93+
cp app/config/parameters.yml.dist app/config/parameters.yml
94+
95+
../scripts/install_dependencies.sh
96+
97+
../scripts/install_composer.sh
98+
99+
../scripts/warmup_cache.sh
100+
101+
# TODO: Fix this crap later on (Apache config), it's all hardcoded now
102+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
103+
sudo cp /opt/codebender/$PACKAGENAME/apache-config /etc/apache2/sites-available/codebender-compiler
104+
cd /etc/apache2/sites-enabled
105+
sudo ln -s ../sites-available/codebender-compiler 00-codebender-compiler
106+
sudo service apache2 restart
107+
fi

scripts/install_composer.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
echo "Installing Dependencies"
4+
curl -s http://getcomposer.org/installer | php
5+
php composer.phar install

scripts/install_dependencies.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
sudo apt-get install -y unzip
3+
cd ~
4+
wget https://github.com/codebendercc/arduino-core-files/archive/master.zip
5+
unzip master.zip
6+
sudo cp -r arduino-core-files-master /opt/codebender/codebender-arduino-core-files
7+
rm master.zip
8+
wget https://github.com/codebendercc/external_cores/archive/master.zip
9+
unzip master.zip
10+
sudo cp -r external_cores-master /opt/codebender/external-core-files
11+
cd -

scripts/run_local_tests.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
#Left here to be commited on git, in case dirname doesn't work as expected
4+
#echo "The script you are running has basename `basename $0`, dirname `dirname $0`"
5+
#echo "The present working directory is `pwd`"
6+
7+
8+
#Ask user to make sure we want to run this
9+
echo "NEVER run this script in production. It will purge your database to a clean state"
10+
read -r -p "Are you sure you want to run this? [y/N] " response
11+
case $response in
12+
[yY][eE][sS]|[yY])
13+
# User accepted
14+
;;
15+
*)
16+
# Abort
17+
exit
18+
;;
19+
esac
20+
21+
#Changing directory to Symfony, regardless where we are
22+
cd `dirname $0`/../Symfony
23+
24+
set -x
25+
pwd
26+
27+
../scripts/install_composer.sh
28+
29+
../scripts/clear_cache.sh
30+
31+
../scripts/warmup_cache.sh
32+
33+
../scripts/run_tests.sh

scripts/run_tests.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
echo "Running Tests"
6+
if [[ $TRAVIS ]]; then
7+
bin/phpunit -c app/ --coverage-clover build/logs/clover.xml --stderr
8+
#bin/phpcpd --log-pmd build/pmd-cpd.xml --exclude app --exclude vendor --names-exclude *Test.php -n .
9+
#bin/phpmd src/Codebender/ xml cleancode,codesize,design,naming,unusedcode --exclude *Test.php --reportfile build/pmd.xml
10+
else
11+
bin/phpunit -c app/ --stderr --coverage-html=coverage/
12+
13+
echo "Running Copy-Paste-Detector"
14+
bin/phpcpd --exclude app --exclude vendor --names-exclude *Test.php -n .
15+
bin/phpmd src/Codebender/ xml cleancode,codesize,design,naming,unusedcode --exclude *Test.php
16+
fi

scripts/warmup_cache.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
echo "Warming up the cache"
4+
php app/console cache:warmup --env=dev
5+
php app/console cache:warmup --env=prod
6+
php app/console cache:warmup --env=test

0 commit comments

Comments
 (0)