Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #63 from marmelab/magento_lb_master_slave
Browse files Browse the repository at this point in the history
[RFR] Add Magento example
  • Loading branch information
manuquentin committed May 29, 2014
2 parents 4885651 + 3aabfbf commit 5086878
Show file tree
Hide file tree
Showing 232 changed files with 78 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cgi-bin/
composer.lock
vendor/
bower_components/
examples/magento-lb-master-slave/htdocs/
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- New components [`python`](https://github.com/marmelab/gaudi/tree/master/example/python), [`django`](https://github.com/marmelab/gaudi/tree/master/example/django) & [`golang`](https://github.com/marmelab/gaudi/tree/master/example/golag)
- Add an `empty-cmd` option to debug containers
- Use color in gaudi output
- Updated [examples](https://github.com/marmelab/gaudi/tree/master/example) with use cases
- Updated [examples](https://github.com/marmelab/gaudi/tree/master/examples) with use cases
- Add a check of gaudi version to retrieve new templates
- Fix #47, #59, #58

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ All templates are listed in [the `templates/` folder](https://github.com/marmela

You can find an example of [how to start a Symfony application](https://github.com/marmelab/gaudi/wiki/HOW-TO:-Run-a-Symfony-Application) in the wiki.

Another examples can be found in [the `example` folder](https://github.com/marmelab/gaudi/tree/master/example).
Another examples can be found in [the `examples` folder](https://github.com/marmelab/gaudi/tree/master/examples).

# Options

Expand Down
16 changes: 0 additions & 16 deletions example/magento/composer.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,69 @@ applications:
8080: 80
links: [front1, front2]
volumes:
.: /var/www
.: /app
custom:
backends: [front1, front2]
probe_url: /up.php

front1:
type: apache
links: [app1]
ports:
8081: 8080
volumes:
.: /var/www
.: /app
modules: [rewrite]
custom:
fastCgi: app1
fastCgiIdleTimeout: 500
documentRoot: /app/htdocs

front2:
type: apache
links: [app2]
ports:
8082: 8080
volumes:
.: /var/www
.: /app
modules: [rewrite]
custom:
fastCgi: app2
fastCgiIdleTimeout: 500
documentRoot: /app/htdocs

app1:
type: hhvm
ports:
9000: 9000
volumes:
.: /var/www
.: /app
apt_get: [php5-gd, php5-intl]
links: [memcached]
custom:
memoryLimit: 512M
maxExecutionTime: 500

app2:
type: hhvm
type: php-fpm
ports:
9001: 9000
volumes:
.: /var/www
.: /app
apt_get: [php5-gd, php5-intl]
links: [memcached]
custom:
memoryLimit: 512M
maxExecutionTime: 500

master:
type: mysql
ports:
3306: 3306
volumes:
/var/tmp/data/master: /var/lib/mysql
after_script:
mysql -e "CREATE DATABASE IF NOT EXISTS magento CHARACTER SET utf8 COLLATE utf8_general_ci;"
custom:
repl: master

Expand Down Expand Up @@ -76,6 +95,12 @@ applications:
repl: slave
master: master

memcached:
type: index
image: borja/docker-memcached
ports:
11211: 11211

phpmyadmin:
type: phpmyadmin
ports:
Expand Down
6 changes: 6 additions & 0 deletions examples/magento-lb-master-slave/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir htdocs
wget http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz
tar zxvf magento-1.9.0.1.tar.gz -C htdocs --strip 1


echo "<?php echo 'ok';" > htdocs/up.php
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion templates/apache/000-default
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
CustomLog ${APACHE_LOG_DIR}/access.log combined

[[ $fastCgi := .Collection.Get (.Container.GetCustomValueAsString "fastCgi") (.Collection.GetType "php-fpm") ]]
[[ $fastCgiIdleTimeout := .Container.GetCustomValue "fastCgiIdleTimeout" "30" ]]
[[ if $fastCgi ]]
FastCgiExternalServer /var/www/cgi-bin/php5.external -host ${[[ $fastCgi.Name | ToUpper ]]_PORT_[[ $fastCgi.GetFirstPort ]]_TCP_ADDR}:${[[ $fastCgi.Name | ToUpper ]]_PORT_[[ $fastCgi.GetFirstPort]]_TCP_PORT}
FastCgiExternalServer /var/www/cgi-bin/php5.external -host ${[[ $fastCgi.Name | ToUpper ]]_PORT_[[ $fastCgi.GetFirstLocalPort ]]_TCP_ADDR}:${[[ $fastCgi.Name | ToUpper ]]_PORT_[[ $fastCgi.GetFirstLocalPort]]_TCP_PORT} -idle-timeout [[ $fastCgiIdleTimeout ]]
Alias /cgi-bin/ /var/www/cgi-bin/
[[end]]
</VirtualHost>
Expand Down
12 changes: 12 additions & 0 deletions templates/apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ ADD fastcgi.conf /etc/apache2/mods-enabled/fastcgi.conf
ADD 000-default /etc/apache2/sites-enabled/000-default
ADD ports.conf /etc/apache2/ports.conf

[[ $fastCgi := .Collection.Get (.Container.GetCustomValueAsString "fastCgi") (.Collection.GetType "php-fpm") ]]
[[ if $fastCgi ]]
[[ $memoryLimit := $fastCgi.GetCustomValue "memoryLimit" "128M" ]]
[[ $maxExecutionTime := $fastCgi.GetCustomValue "maxExecutionTime" "30" ]]
[[ $maxInputTime := $fastCgi.GetCustomValue "maxInputTime" "60" ]]
[[ $locale := $fastCgi.GetCustomValue "locale" "Europe/Paris" ]]

RUN sed -i 's|;date.timezone =|date.timezone = "[[ $locale ]]"|g' /etc/php5/fpm/php.ini
RUN sed -i 's|memory_limit = 128M|memory_limit = [[ $memoryLimit ]]|g' /etc/php5/fpm/php.ini
RUN sed -i 's|max_execution_time = 30|max_execution_time = [[ $maxExecutionTime ]]|g' /etc/php5/fpm/php.ini
RUN sed -i 's|max_input_time = 60|max_input_time = [[ $maxInputTime ]]|g' /etc/php5/fpm/php.ini
[[ end ]]
# Add custom setup script
[[ beforeAfterScripts ]]

Expand Down
2 changes: 1 addition & 1 deletion templates/django/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ ! -d "/app/[[ .Container.GetCustomValue "project_name" "project" ]]/[[ .Con

cd /app/[[ $projectName ]]
sed -i -e "s/'django.db.backends.sqlite3'/'django.db.backends.mysql'/" ./settings.py
sed -i -e "s/'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),/'NAME': 'django',\n\t\t'USER': 'root',\n\t\t'PASSWORD': '',\n\t\t'HOST': os.environ['[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstPort]]_TCP_ADDR']/" ./settings.py
sed -i -e "s/'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),/'NAME': 'django',\n\t\t'USER': 'root',\n\t\t'PASSWORD': '',\n\t\t'HOST': os.environ['[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstLocalPort]]_TCP_ADDR']/" ./settings.py

sed -i -e "s/# from django.contrib import admin/from django.contrib import admin/" ./urls.py
sed -i -e "s/# admin.autodiscover()/admin.autodiscover()/" ./urls.py
Expand Down
4 changes: 4 additions & 0 deletions templates/hhvm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ RUN echo deb http://dl.hhvm.com/debian wheezy main | tee /etc/apt/sources.list.d
RUN apt-get -y update
RUN apt-get install -y --force-yes -f hhvm php5-cli curl

[[ $memoryLimit := .Container.GetCustomValue "memoryLimit" "128M" ]]
[[ $maxExecutionTime := .Container.GetCustomValue "maxExecutionTime" "30" ]]
RUN sed -i -e 's|; php options|; php options\nmemory_limit = [[ $memoryLimit ]]\nmax_execution_time = [[ $maxExecutionTime ]]\ndisplay_startup_errors = On\nerror_reporting = E_ALL\ndisplay_errors = On|' /etc/hhvm/php.ini

[[ if .EmptyCmd]]
CMD /bin/bash
[[ else ]]
Expand Down
4 changes: 2 additions & 2 deletions templates/mysql/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ mysql -e "GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl'; FLUSH
[[ $master := $.Collection.Get $masterName ]]

# Connect to master & retrieve current log file & position
MASTER_STATUS=$(mysql -u root -h $[[ $masterName | ToUpper ]]_PORT_[[ $master.GetFirstPort ]]_TCP_ADDR -e "show master status\G")
MASTER_STATUS=$(mysql -u root -h $[[ $masterName | ToUpper ]]_PORT_[[ $master.GetFirstLocalPort ]]_TCP_ADDR -e "show master status\G")
MASTER_LOG_FILE=$(echo "$MASTER_STATUS" | grep File | sed 's/File://' | sed 's/^ *//;s/ *$//')
MASTER_LOG_POS=$(echo "$MASTER_STATUS" | grep Position | sed 's/Position://' | sed 's/^ *//;s/ *$//')

sed -i -e "s/\[mysqld\]/[mysqld]\nlog-bin\nserver-id = 2/" /etc/mysql/my.cnf
mysql -e "CHANGE MASTER TO MASTER_HOST='$[[$masterName | ToUpper ]]_PORT_[[ $master.GetFirstPort ]]_TCP_ADDR', MASTER_LOG_POS=245, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='$MASTER_LOG_FILE', MASTER_LOG_POS=$MASTER_LOG_POS; START SLAVE;" -uroot
mysql -e "CHANGE MASTER TO MASTER_HOST='$[[$masterName | ToUpper ]]_PORT_[[ $master.GetFirstLocalPort ]]_TCP_ADDR', MASTER_LOG_POS=245, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='$MASTER_LOG_FILE', MASTER_LOG_POS=$MASTER_LOG_POS; START SLAVE;" -uroot

[[ end ]]

Expand Down
4 changes: 2 additions & 2 deletions templates/nginx/default
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[ if (.Container.GetCustomValue "backends")]]
upstream loadBalancing {
[[range (.Container.GetCustomValue "backends")]]
[[ $port := ($.Collection.Get . ).GetFirstPort ]]
[[ $port := ($.Collection.Get . ).GetFirstLocalPort ]]
server ${[[ . | ToUpper ]]_PORT_[[ $port ]]_TCP_ADDR}:${[[ . | ToUpper ]]_PORT_[[ $port ]]_TCP_PORT};
[[end]]
}
Expand Down Expand Up @@ -43,7 +43,7 @@ server {
fastcgi_split_path_info ^(.+\.php)(/.+)$;

[[ $fastCgiName := (.Container.GetCustomValue "fastCgi")]]
[[ $fastCgiPort := (.Collection.Get .Container.Custom.fastCgi ).GetFirstPort]]
[[ $fastCgiPort := (.Collection.Get .Container.Custom.fastCgi ).GetFirstLocalPort]]
fastcgi_pass ${[[ $fastCgiName | ToUpper ]]_PORT_[[ $fastCgiPort ]]_TCP_ADDR}:${[[ $fastCgiName | ToUpper ]]_PORT_[[ $fastCgiPort ]]_TCP_PORT};
fastcgi_index index.php;
include fastcgi_params;
Expand Down
10 changes: 9 additions & 1 deletion templates/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ RUN apt-get -y -f install php5-fpm php5-cli php5-mysql php5-mcrypt php5-curl cur
# Install composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer

[[ $memoryLimit := .Container.GetCustomValue "memoryLimit" "128M" ]]
[[ $maxExecutionTime := .Container.GetCustomValue "maxExecutionTime" "30" ]]
[[ $maxInputTime := .Container.GetCustomValue "maxInputTime" "60" ]]
[[ $locale := .Container.GetCustomValue "locale" "Europe/Paris" ]]

RUN sed -i 's|listen = /var/run/php5-fpm.sock|listen = [[ .Container.GetFirstLocalPort ]]|g' /etc/php5/fpm/pool.d/www.conf
RUN sed -i 's|;cgi.fix_pathinfo=0|cgi.fix_pathinfo=0|g' /etc/php5/fpm/pool.d/www.conf
RUN sed -i 's|;date.timezone =|date.timezone = "Europe/Paris"|g' /etc/php5/fpm/php.ini
RUN sed -i 's|;date.timezone =|date.timezone = "[[ $locale ]]"|g' /etc/php5/fpm/php.ini
RUN sed -i 's|memory_limit = 128M|memory_limit = [[ $memoryLimit ]]|g' /etc/php5/fpm/php.ini
RUN sed -i 's|max_execution_time = 30|max_execution_time = [[ $maxExecutionTime ]]|g' /etc/php5/fpm/php.ini
RUN sed -i 's|max_input_time = 60|max_input_time = [[ $maxInputTime ]]|g' /etc/php5/fpm/php.ini

ADD setup.sh /root/setup.sh
RUN chmod +x /root/setup.sh
Expand Down
4 changes: 2 additions & 2 deletions templates/phpmyadmin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.

[[ $firstLinked := .Container.FirstLinked]]

RUN sed -i "s|if (empty(\$dbserver)) \$dbserver = 'localhost';|if (empty(\$dbserver)) \$dbserver = getenv('[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstPort]]_TCP_ADDR');|g" /etc/phpmyadmin/config.inc.php
RUN sed -i "s|//\$cfg\['Servers'\]\[\$i\]\['host'\] = 'localhost';|\$cfg\['Servers'\]\[\$i\]\['host'\] = getenv('[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstPort]]_TCP_ADDR');|g" /etc/phpmyadmin/config.inc.php
RUN sed -i "s|if (empty(\$dbserver)) \$dbserver = 'localhost';|if (empty(\$dbserver)) \$dbserver = getenv('[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstLocalPort]]_TCP_ADDR');|g" /etc/phpmyadmin/config.inc.php
RUN sed -i "s|//\$cfg\['Servers'\]\[\$i\]\['host'\] = 'localhost';|\$cfg\['Servers'\]\[\$i\]\['host'\] = getenv('[[ $firstLinked.Name | ToUpper ]]_PORT_[[ $firstLinked.GetFirstLocalPort]]_TCP_ADDR');|g" /etc/phpmyadmin/config.inc.php
RUN sed -i "s|// \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\] = TRUE;|\$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\] = TRUE;|g" /etc/phpmyadmin/config.inc.php

# Add setup script
Expand Down
6 changes: 4 additions & 2 deletions templates/varnish/default.vcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[[ $probeUrl := (.Container.GetCustomValue "probe_url" "/") ]]

[[range (.Container.GetCustomValue "backends")]]
[[ $port := ($.Collection.Get . ).GetFirstPort ]]
[[ $port := ($.Collection.Get . ).GetFirstLocalPort ]]
backend [[.]] {
.host = "${[[ . | ToUpper ]]_PORT_[[ $port ]]_TCP_ADDR}";
.port = "${[[ . | ToUpper ]]_PORT_[[ $port ]]_TCP_PORT}";
.probe = {
.url = "/";
.url = "[[ $probeUrl ]]";
.interval = 5s;
.timeout = 1 s;
.window = 5;
Expand Down

0 comments on commit 5086878

Please sign in to comment.