Installation phpUnderControl from scratch

Projekt PHP Entwicklungsserver mit Continuous Integration

phpundercontrol

Wie behalte ich die Übersicht über meine Projekte?
Wer kümmert sich um die Dokumentation?
Laufen die Tests noch?

Soll das Entwicklungstempo hoch gehalten werden und/oder agile Methoden zum Einsatz kommen, dann wird eine technische Lösung für diese Fragen gesucht.

PHP Projekte müssen nicht hilflos auf Ruby Tools schielen oder JAVA Lösungen beneiden. Es gibt interessante Anwendungen, die einen Tester, Builder und Dokumentator ersetzen. Dafür sind nur 237 Webquellen durchzuarbeiten, 793 weiterführende Links zu überschauen und Beta Versionen anzutesten.

Hört sich nicht sehr einladend an?
Ich habe in den letzen Tagen 3 mal ein phpUnderControl aufgesetzt und da die Sucherei nicht weniger wurde, mich gezwungen es zu dokumentieren. Für die von mir benutzten aktuellen Versionen ist es jetzt komplett nachvollziehbar.

Systemumgebung für diese Anleitung:

Ubuntu Server 8.10 (in VirtualBox installiert)

In den VirtualBox Einstellungen die Netzwerkkarte des Gastes als Hostinterface gesetzt für lokales Netzwerk zwischen Wirt und Gast.

Beim Ubuntu Setup ausgewählt:

  • LAMP Server
  • SSH Server

VirtualBox Netz erreichbar vom Host z.B. http://lamp
user account “developer”
root account aktiviert (sudo passwd root)

Die nächsten Systembefehle benötigen root Rechte und da es ein virtueller Rechner für lokale Entwicklung wird spricht nichts gegen die Arbeit als root. Alternativ kann gerne sudo vor jeden Befehl gesetzt werden. Für die Installation auf einem Arbeitsplatz empfehle ich eine Konsole mit “sudo -s” zur Root Shell zu machen.

optional wichtige Entwicklungstools:

  • Subversion (apt-get install subversion)
  • Git (apt-get install git-core)
  • CVS (agt-get install cvs)

PHP vorbereiten:

apt-get install php5-cli php-pear php5-xdebug

Java JDK installieren

apt-get install sun-java6-jdk

Hier ist Interaktion angesagt, da die Nutzungsbedingungen akzeptiert werden müssen.

CruiseControl installieren

cd /opt
wget http://downloads.sourceforge.net/cruisecontrol/cruisecontrol-bin-2.8.2.zip
apt-get install unzip
unzip cruisecontrol-bin-2.8.2.zip
mv cruisecontrol-bin-2.8.2 cc
chown -R developer /opt/cc

Startsript anlegen:

cd /etc/init.d
touch cruisecontrol

Folgenden Inhalt einfügen:

Download
#!/bin/sh
### BEGIN INIT INFO
# Provides:          cruisecontrol
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: CruiseControl build loop.
### END INIT INFO

# CruiseControl Unix Startup Script Version
#
# based on http://confluence.public.thoughtworks.org/display/CC/UnixStartupScriptVersion1.x
# adapted for multiple projects
# also modified by Jerome Lacoste
#
# modifications for ubuntu-server installation by Jens Klose

########################################################################
# USER CONFIGURATION
#
# Fill in these values for your Cruise Control setup

# What user will Cruise Control run as?  The user will need permission to write and modify files
# in the next entries.
CC_USER=developer

# Where is the CC startup script located?
CC_INSTALL_DIR=/opt/cc

# In what directory is the config.xml file located for CC?
# default: CC_WORK_DIR=$CC_INSTALL_DIR
CC_WORK_DIR=$CC_INSTALL_DIR

# Where will the cruisecontrol.log file be located?
# default: CC_LOGFILE_DIR=$CC_INSTALL_DIR
CC_LOGFILE_DIR=$CC_INSTALL_DIR/logs

#######################
# ENVIRONMENT ADDITIONS

# Add environement variables here that are needed by your build.
# example:
export JAVA_HOME=/usr/lib/jvm/java-6-sun

# Add path to additional executables needed for project build.  See PATH entry below for base config.
# No additional action taken when blank.
PATH_ADDITIONS=

##############################
# CRUISE CONTROL PORT SETTINGS
# Port for Jetty reporting application.  You can access it by going to http://localhost:8080
# default CC_WEBPORT=8080
CC_WEBPORT=8080

# JMX port for webapp and Java Management eXtensions (JMX). http://localhost:8082
# Change only if this port is in use as the webapp will also need modification.
# default CC_JMXPORT=8082
CC_JMXPORT=8082

# RMI port for control via Java's Remote Management Interface (RMI)
# Leave blank to disable.
CC_RMIPORT=

########################################################################
# DO NOT MODIFY ENTRIES BELOW THIS LINE

NAME=cruisecontrol
DESC="CruiseControl - continuous integration build loop"

PATH=/sbin:/usr/sbin:/usr/bin:/bin

# add additions if variable has text defined
if [ -n "$PATH_ADDITIONS" ]; then
    PATH=$PATH_ADDITIONS:$PATH
fi
export PATH

CC_DAEMON=$CC_INSTALL_DIR/cruisecontrol.sh
CC_CONFIG_FILE=$CC_WORK_DIR/config.xml
CC_LOG_FILE=$CC_LOGFILE_DIR/cruisecontrol.log

CC_COMMAND="$CC_DAEMON -configfile $CC_CONFIG_FILE -webport $CC_WEBPORT -jmxport $CC_JMXPORT -rmiport $CC_RMIPORT"

# overwrite settings from default file
if [ -f /etc/default/cruisecontrol ]; then
    . /etc/default/cruisecontrol
fi

# does the executable exist?
test -f $CC_DAEMON || (echo "The executable $CC_DAEMON does not exist!" && exit 0)

if [ `id -u` -ne 0 ]; then
    echo "Not starting/stopping $DESC, you are not root."
    exit 4
fi

case "$1" in

    'start')
        cd $CC_INSTALL_DIR
        #echo "CC environtment at startup" > cc.startup.env
        #env >> cc.startup.env
        su $CC_USER -c "/bin/sh -c \"$CC_COMMAND >> $CC_LOG_FILE 2>&1\"" & RETVAL=$?
        echo "$NAME started with jmx on port ${CC_JMXPORT}"
        ;;

    'stop')
        # Get the PID output from the startup script
        if [ -f $CC_INSTALL_DIR/cc.pid ]; then
            CC_PID=`cat $CC_INSTALL_DIR/cc.pid`
        else
            echo "No cc.pid file found.  CC process may not be controllable from this script!"
        fi

        if [ -n "$CC_PID" ] && ps -p ${CC_PID} > /dev/null ; then
            kill -9 ${CC_PID}
            $0 status
            RETVAL=$?
        else
            echo "$NAME is not running"
            RETVAL=1
        fi
        ;;

    'status')
        # Get the PID output from the startup script
        if [ -f $CC_INSTALL_DIR/cc.pid ]; then
            CC_PID=`cat $CC_INSTALL_DIR/cc.pid`
        else
            echo "No cc.pid file found.  CC process may not be controllable from this script!"
        fi

        if [ -n "$CC_PID" ] && ps -p ${CC_PID} > /dev/null ; then
            echo $NAME \(pids $CC_PID\) is running
            RETVAL=0
        else
            echo "$NAME is stopped"
            RETVAL=1
        fi
        ;;

    'restart')
        $0 stop && $0 start
        RETVAL=$?
        ;;

    *)
        echo "Usage: $0 { start | stop | status | restart }"
        exit 1
        ;;

esac

exit 0;

Script testen:

root@lamp:/etc/init.d#chmod +x ./cruisecontrol
/etc/init.d/cruisecontrol start
cruisecontrol started with jmx on port 8082
root@lamp:/etc/init.d#

Im Browser testen:

http://lamp:8080/cruisecontrol/

cruisecontrolfirststart

Ok - dann: CruiseControl beenden:

/etc/init.d/cruisecontrol stop

Runlevel Einträge setzen:

update-rc.d cruisecontrol defaults

Output:

root@lamp:/etc/init.d# update-rc.d cruisecontrol defaults
 Adding system startup for /etc/init.d/cruisecontrol ...
   /etc/rc0.d/K20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc1.d/K20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc6.d/K20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc2.d/S20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc3.d/S20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc4.d/S20cruisecontrol -> ../init.d/cruisecontrol
   /etc/rc5.d/S20cruisecontrol -> ../init.d/cruisecontrol

Beim nächsten Neustart sollte die Startmeldung mit erscheinen.

ccstartscriptintegriert

An dieser Stelle hat man den fleißigen neuen Mitarbeiter bereits. Auch ohne phpUnderControl können jetzt Projekte verwaltet und mit ANT bearbeitet und deployed werden. Die weiteren Installationen bringen den PHP Entwicklern angepaßte Auswertungen, die auf den Logs der pear Tools beruhen.

Installation phpUnderControl, PHPUnit und weitere Tools:

2009/06 UpdateInfos: PHPUnit verlangt für die Installation einen aktuelleren PEAR Installer.
Fehlermeldung:
phpunit/PHPUnit requires PEAR Installer (version >= 1.8.1)
Lösung:
pear upgrade PEAR

Installation über pear erspart späteren Ärger mit PATH Anpassungen, installiert Codesniffer, PHPDocumentor und andere benötigte Tools gleich mit.

pear channel-discover pear.phpunit.de
pear update-channels
pear install phpunit/PHPUnit
pear install --alldeps Log
pear config-set preferred_state beta
pear install --alldeps pear/Image_GraphViz
pear channel-discover components.ez.no
pear install --alldeps phpunit/phpUnderControl
pear config-set preferred_state stable

Jetzt mal mit Ausgabe, um die Toolliste für manuelle Nachinstallationen festzuhalten.

root@lamp:~# root@lamp:~# pear install --alldeps phpunit/phpUnderControl
downloading phpUnderControl-0.4.7.tgz ...
Starting to download phpUnderControl-0.4.7.tgz (558,873 bytes)
.........................................................................done: 558,873 bytes
downloading Graph-1.4.2.tgz ...
Starting to download Graph-1.4.2.tgz (3,388,920 bytes)
...done: 3,388,920 bytes
downloading PHP_CodeSniffer-1.2.0RC1.tgz ...
Starting to download PHP_CodeSniffer-1.2.0RC1.tgz (282,807 bytes)
...done: 282,807 bytes
downloading PhpDocumentor-1.4.2.tgz ...
Starting to download PhpDocumentor-1.4.2.tgz (2,421,028 bytes)
...done: 2,421,028 bytes
downloading Base-1.6.1.tgz ...
Starting to download Base-1.6.1.tgz (178,245 bytes)
...done: 178,245 bytes
downloading XML_Beautifier-1.2.0.tgz ...
Starting to download XML_Beautifier-1.2.0.tgz (12,948 bytes)
...done: 12,948 bytes
downloading XML_Parser-1.3.2.tgz ...
Starting to download XML_Parser-1.3.2.tgz (16,260 bytes)
...done: 16,260 bytes
downloading XML_Util-1.2.1.tgz ...
Starting to download XML_Util-1.2.1.tgz (17,729 bytes)
...done: 17,729 bytes
install ok: channel://pear.php.net/PHP_CodeSniffer-1.2.0RC1
install ok: channel://pear.php.net/PhpDocumentor-1.4.2
install ok: channel://components.ez.no/Base-1.6.1
install ok: channel://pear.php.net/XML_Parser-1.3.2
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://components.ez.no/Graph-1.4.2
install ok: channel://pear.php.net/XML_Beautifier-1.2.0
install ok: channel://pear.phpunit.de/phpUnderControl-0.4.7
root@lamp:~#

Erfolgserlebnis abholen:

root@lamp:~# phpuc -v
phpUnderControl 0.4.7 by Manuel Pichler.

So jetzt wird CruiseControl mit phpuc angereichert.

root@lamp:~# phpuc install /opt/cc
Performing CruiseControl task.
   1. Creating directory "webapps/cruisecontrol/images/php-under-control
   2. Creating directory "webapps/cruisecontrol/js

Performing modify file task.
   1. Creating backup "/webapps/cruisecontrol/buildresults.jsp".
   2. Modifying file "/webapps/cruisecontrol/buildresults.jsp"
   3. Creating backup "/webapps/cruisecontrol/index.jsp".
   4. Modifying file "/webapps/cruisecontrol/index.jsp"
...
  46. Creating file "/webapps/cruisecontrol/xsl/phpunit-pmd-details.xsl"
  47. Creating file "/webapps/cruisecontrol/xsl/phpunit-pmd-summary.xsl"
  48. Creating file "/webapps/cruisecontrol/WEB-INF/lib/php-under-control.jar"
root@lamp:~#

Der finale Start von phpUnderControl over CruiseControl

/etc/init.d/cruisecontrol start

Wie geht es weiter?

Endlich am Laufen beginnt die nächste Herausforderung - ein eigenes Projekt verwalten zu lassen. Das wird ein Thema der bald folgenden Dokumentationen sein.

Links zum Thema

Kategorie: Administration, Projekte, Aktualisiert am 25. Mai 2010 von Jens Klose | Anmelden

6 Comments

Schreibe einen Kommentar - RSS Comments

  1. Pingback from Erstes Projekt in phpUnderControl | Creative Developer Service:

    [...] ist nach der Installation dein neuer Mitarbeiter in der Qualitätsüberwachung. Da im Hintergrund mehrere Builder [...]

    28. April 2009 @ 00:45
  2. Pingback from Administration phpUnderControl | Creative Developer Service:

    [...] dann mal los. CVS hatte ich neben weiteren Versionsverwaltungen ja bereits mit auf dem Entwicklungsserver installiert. Bleibt noch CVS Repository anlegen, Arbeitkopie des Projektes besorgen und dann ins CVS [...]

    11. Mai 2009 @ 03:08
  3. Comment by schiller256:

    Hallo,

    mir sind zwei kleine Fehler aufgefallen. ;-)

    Zum einen bei setzen der Runlevel, es muss defaults heißen und nicht default. Im Codeausschnitt ist es auch richtig.
    update-rc.d cruisecontrol defaults

    Zum anderen kann ich das pear Package pear install --alldeps pear/GraphViz nicht installieren. Es wird nur das Package pear install --alldeps pear/Image_GraphViz gefunden.

    16. Mai 2009 @ 16:42
  4. Comment by Jens Klose:

    big gz schiller256!
    beide Hinweise werden ausgebessert - also nicht mehr suchen ;)

    19. Mai 2009 @ 23:53
  5. Comment by Dennis Becker:

    Ich habe Probleme bei der Installation von phpUnderControl - Auf dem “Metrics” Tab bekomme ich eine Java NullPointerException. Auch das example-Projekt von phpUnderControl funktioniert garnicht. Der Buildprozess läuft einfach nicht. Das “connectfour” Projekt ist allerdings vorhanden. Ich bin ziemlich ratlos. Sollte ich am besten alles nochmal neu installieren? Ich verwende übrigens Ubuntu 8.10 sowie den Zend Server CE. Ich habe auch den Pfad /usr/local/zend/bin zur PATH-Variable hinzugefügt, da der Zend Server die PEAR & PECL Pakete halt in dem vorher genannten Pfad ablegt. Bin für alle Hinweise dankbar :)

    8. Juni 2009 @ 16:22
  6. Comment by Jens Klose:

    Hallo Dennis,

    das Problem sollte zu lösen sein. Die Installation von CruiseControl und die Anpassung mit phpUnderControl scheintst du ja erfolgreich abgeschlossen zu haben, da du den Metrics Tab benutzt und connectfour siehst.

    Bleiben noch folgende Fragen offen:
    1. Kannst du “pear”, “phpuc” und “phpunit” an der Konsole aufrufen?
    2. Hast du in deiner config.xml das Example Projekt?
    Siehe dazu auch: Example Projekt und Administration

    Das connectfour Projekt ist ein Java Beispiel. Es wird schon bei der Installation von CruiseControl mitgeliefert und hat deshalb nicht die XSL Renderung durchlaufen, die von phpUnderControl für die PHP Projekte erwartet wird.

    14. Juni 2009 @ 10:07

Du musst angemeldet sein ,um zu kommentieren.