Skip to content

Commit

Permalink
Now have 2 versions : PHP 5.6 should be 'stable' and PHP 7.2 on xhgui…
Browse files Browse the repository at this point in the history
… master
  • Loading branch information
Emmanuel Dyan committed Apr 17, 2018
1 parent c4290b0 commit 5911eb7
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 70 deletions.
61 changes: 0 additions & 61 deletions Dockerfile

This file was deleted.

24 changes: 17 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@

set -e

docker build -t "inet_phing_test" .
if [ -z "$1" -o ! -d "php$1" ]; then
echo "You must define a valid PHP version to build as parameter (5.6 or 7.2)"
exit 1
fi

VERSION=$1
GREEN='\033[0;32m'
NC='\033[0m' # No Color

cd php$1
docker build -t "edyan_phing_php${VERSION}_test" .
echo ""
echo ""

if [ $? -eq 0 ]; then
echo -e "\x1b[1;32mBuild Done. To run it: \e[0m"
echo ' docker run -d --rm --hostname "phing-test-ctn" --name "phing-test-ctn" inet_phing_test'
echo ' docker exec -i -t "phing-test-ctn" /bin/bash'
echo -e "${GREEN}Build Done${NC}."
echo ""
echo "Run :"
echo " docker run --rm --hostname phing_php${VERSION}-test-ctn --name phing_php${VERSION}-test-ctn edyan_phing_php${VERSION}_test"
echo " docker exec -i -t phing_php${VERSION}-test-ctn /bin/bash"
echo "Once Done : "
echo ' docker stop "phing-test-ctn"'
echo " docker stop phing_php${VERSION}-test-ctn"
echo ""
echo "Or if you want to directly enter the container, then remove it : "
echo ' docker run -ti --rm inet_phing_test /bin/bash'
echo " docker run -ti --rm edyan_phing_php${VERSION}_test /bin/bash"
fi
78 changes: 78 additions & 0 deletions php5.6/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
FROM edyan/php:5.6
MAINTAINER Emmanuel Dyan <emmanueldyan@gmail.com>

ARG DEBIAN_FRONTEND=noninteractive

# Installation
RUN apt-get update && \
# Upgrade the system
apt-get upgrade -y && \
# Install packages
apt-get install -y --no-install-recommends ca-certificates git mongodb-server nginx supervisor && \
# Clone xhgui and install 0.7.1, then remove useless files
git clone https://github.com/perftools/xhgui /usr/local/src/xhgui && \
cd /usr/local/src/xhgui && \
git checkout tags/v0.7.1 && \
rm -Rf /usr/local/src/xhgui/.git \
/usr/local/src/xhgui/.scrutinizer.yml \
/usr/local/src/xhgui/.travis.yml \
/usr/local/src/xhgui/phpunit.xml \
/usr/local/src/xhgui/README.md \
/usr/local/src/xhgui/tests && \
# Clean
apt-get purge git -y && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/* /var/cache/* /var/log/*


# Installing XhGui
WORKDIR /usr/local/src/xhgui
COPY conf/xhgui.config.php /usr/local/src/xhgui/config/config.php
# Install composer
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
curl https://getcomposer.org/download/1.6.4/composer.phar -s -S -o composer.phar && \
chmod 0755 composer.phar && \
./composer.phar selfupdate --stable && \
sed -i 's/composer\.phar update/composer.phar install --no-dev/g' install.php && \
php install.php && \
chown -R www-data:www-data /usr/local/src/xhgui && \
# Clean
rm -f composer.phar && \
apt-get purge curl -y && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/* /var/cache/* /var/log/*


# Prepare Mongodb
RUN mkdir -p /data/db /var/log/mongodb && \
chown -R mongodb:mongodb /data /var/log/mongodb


# Prepare nginx
COPY conf/nginx.default.conf /etc/nginx/sites-available/default
RUN mkdir /var/log/nginx && \
chown -R www-data:www-data /var/log/nginx


# Supervisord
RUN mkdir -p /var/log/supervisor
COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


# Global directives
VOLUME ["/usr/local/src/xhgui"]

EXPOSE 80 27017

ENV FPM_UID 33
ENV FPM_GID 33

COPY post-run.sh /root/post-run.sh
RUN chmod +x /root/post-run.sh

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
File renamed without changes.
6 changes: 6 additions & 0 deletions conf/supervisord.conf → php5.6/conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[supervisord]
nodaemon=true
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor.log

[program:fpm]
command=/usr/sbin/php5-fpm -c /etc/php5/fpm --nodaemonize
Expand All @@ -21,3 +23,7 @@ user=mongodb
command=/root/post-run.sh
stdout_events_enabled=true
stderr_events_enabled=true
autostart=true
autorestart=false
startretries=0
exitcodes = 0
File renamed without changes.
3 changes: 1 addition & 2 deletions scripts/post-run.sh → php5.6/post-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Right Permissions
usermod -u $FPM_UID www-data
groupmod -g $FPM_GID www-data
chown -R www-data:www-data /var/log/php /usr/local/src/xhgui

chown -R www-data:www-data /usr/local/src/xhgui /var/log/php /var/log/nginx

# Define indexes for mongodb
for i in $(seq 1 90); do
Expand Down
77 changes: 77 additions & 0 deletions php7.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
FROM edyan/php:7.2
MAINTAINER Emmanuel Dyan <emmanueldyan@gmail.com>

ARG DEBIAN_FRONTEND=noninteractive

# Installation
RUN apt update && \
# Upgrade the system
apt upgrade -y && \
# Install packages
apt install -y --no-install-recommends ca-certificates git mongodb-server nginx supervisor && \
# Clone xhgui and install 0.7.1, then remove useless files
git clone https://github.com/perftools/xhgui /usr/local/src/xhgui && \
cd /usr/local/src/xhgui && \
# Keep Master | git checkout tags/v0.7.1 && \
rm -Rf /usr/local/src/xhgui/.git \
/usr/local/src/xhgui/.scrutinizer.yml \
/usr/local/src/xhgui/.travis.yml \
/usr/local/src/xhgui/phpunit.xml \
/usr/local/src/xhgui/README.md \
/usr/local/src/xhgui/tests && \
# Clean
apt purge git -y && \
apt autoremove -y && \
apt autoclean && \
apt clean && \
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/* /var/cache/* /var/log/*


# Installing XhGui
WORKDIR /usr/local/src/xhgui
COPY conf/xhgui.config.php /usr/local/src/xhgui/config/config.php
# Install composer
RUN apt update && \
apt install -y --no-install-recommends curl && \
curl https://getcomposer.org/download/1.6.4/composer.phar -s -S -o composer.phar && \
chmod 0755 composer.phar && \
./composer.phar selfupdate --stable && \
sed -i 's/composer\.phar update/composer.phar install --no-dev/g' install.php && \
php install.php && \
chown -R www-data:www-data /usr/local/src/xhgui && \
# Clean
rm -f composer.phar && \
apt purge curl -y && \
apt autoremove -y && \
apt autoclean && \
apt clean && \
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/* /var/cache/* /var/log/*


# Prepare Mongodb
RUN mkdir -p /data/db /var/log/mongodb && \
chown -R mongodb:mongodb /data /var/log/mongodb


# Prepare nginx
COPY conf/nginx.default.conf /etc/nginx/sites-available/default
RUN mkdir /var/log/nginx && \
chown -R www-data:www-data /var/log/nginx

# Supervisord
RUN mkdir -p /var/log/supervisor
COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


# Global directives
VOLUME ["/usr/local/src/xhgui"]

EXPOSE 80 27017

ENV FPM_UID 33
ENV FPM_GID 33

COPY post-run.sh /root/post-run.sh
RUN chmod +x /root/post-run.sh

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
20 changes: 20 additions & 0 deletions php7.2/conf/nginx.default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80 default_server;
listen [::]:80 default_server;

root /usr/local/src/xhgui/webroot;

index index.php;

server_name _;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param script_filename $document_root$fastcgi_script_name;
}
}
29 changes: 29 additions & 0 deletions php7.2/conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[supervisord]
nodaemon=true
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor.log

[program:fpm]
command=/usr/sbin/php-fpm7.2 -c /etc/php/7.2/fpm --nodaemonize
stdout_events_enabled=true
stderr_events_enabled=true

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;" -c /etc/nginx/nginx.conf
stdout_events_enabled=true
stderr_events_enabled=true

[program:mongodb]
command=/usr/bin/mongod --smallfiles --dbpath /data/db
stdout_events_enabled=true
stderr_events_enabled=true
user=mongodb

[program:post-run]
command=/root/post-run.sh
stdout_events_enabled=true
stderr_events_enabled=true
autostart=true
autorestart=false
startretries=0
exitcodes = 0
19 changes: 19 additions & 0 deletions php7.2/conf/xhgui.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
return array(
'debug' => false,
'mode' => 'development',
'save.handler' => 'mongodb',
'db.host' => 'mongodb://127.0.0.1',
'db.db' => 'xhprof',
'db.options' => array(),
'templates.path' => dirname(__DIR__) . '/src/templates',
'date.format' => 'M jS H:i:s',
'detail.count' => 6,
'page.limit' => 25,
'profiler.enable' => function () {
return true;
},
'profiler.simple_url' => function ($url) {
return preg_replace('/\=\d+/', '', $url);
}
);
34 changes: 34 additions & 0 deletions php7.2/post-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Right Permissions
usermod -u $FPM_UID www-data
groupmod -g $FPM_GID www-data
chown -R www-data:www-data /usr/local/src/xhgui /var/log/php /var/log/nginx

# Define indexes for mongodb
for i in $(seq 1 90); do
mongo --eval "printjson(db.serverStatus())" > /dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi


if [ $i -eq 90 ]; then
exit 1
fi

sleep 1
done

mongo > /dev/null 2>&1 <<EOF
use xhprof
db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
db.results.ensureIndex( { 'profile.main().wt' : -1 } )
db.results.ensureIndex( { 'profile.main().mu' : -1 } )
db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
db.results.ensureIndex( { 'meta.url' : 1 } )
db.results.ensureIndex( { "meta.request_ts" : 1 }, { expireAfterSeconds : 432000 } )
EOF

exit 0

0 comments on commit 5911eb7

Please sign in to comment.