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 #66 from marmelab/ruby_template
Browse files Browse the repository at this point in the history
[RFR] Introduce ruby template
  • Loading branch information
manuquentin committed Jun 4, 2014
2 parents e6700bf + b2e0b56 commit 30ad825
Show file tree
Hide file tree
Showing 34 changed files with 361 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
vendor/
bower_components/
examples/magento-lb-master-slave/htdocs/
examples/ruby-on-rails-mod-passenger/ror/
15 changes: 15 additions & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ func (c *Container) GetCustomValue(params ...string) interface{} {
return nil
}

func (c *Container) SetCustomValue(name, value string) string {
c.Custom[name] = value

return ""
}

func (c *Container) GetCustomValueAsString(params ...string) string {
if value, ok := c.Custom[params[0]]; ok {
return value.(string)
Expand Down Expand Up @@ -261,6 +267,15 @@ func (c *Container) FirstLinked() *Container {
return nil
}


func (c *Container) GetFirstMountedDir() string {
for _, volume := range c.Volumes {
return volume
}

return ""
}

func (c *Container) DependsOf(otherComponentType string) bool {
for _, dep := range c.Dependencies {
if dep.Type == otherComponentType {
Expand Down
20 changes: 20 additions & 0 deletions examples/ruby-on-rails-mod-passenger/.gaudi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
applications:
app:
type: ror
volumes:
.: /app
ports:
8080: 8080
links: [db]
custom:
project_name: ror
documentRoot: /app/ror/public
serverType: apache

db:
type: mysql
ports:
3306: 3306
after_script: mysql -e "CREATE DATABASE IF NOT EXISTS ror_development CHARACTER SET utf8 COLLATE utf8_general_ci;" -uroot
volumes:
.gaudi/mysql: /var/lib/mysql
11 changes: 11 additions & 0 deletions examples/ruby/.gaudi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
applications:
app:
type: ruby
volumes:
.: /app
after_script: ruby /app/hello.rb
#custom:
# version: 2.1.2

# sudo gaudi
# sudo docker logs app
1 change: 1 addition & 0 deletions examples/ruby/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello from ruby\n"
24 changes: 12 additions & 12 deletions templates/_includes/beforeAfterScripts.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[[ if (.Container.HasBeforeScript) ]]
[[ if (.Container.HasBeforeScriptFile) ]]
ADD [[.Container.BeforeScript]] /root/before-setup.sh
[[ else ]]
RUN echo '[[.Container.BeforeScript]]' > /root/before-setup.sh
[[ end ]]
[[ if (.Container.HasBeforeScriptFile) ]]
ADD [[.Container.BeforeScript]] /root/before-setup.sh
[[ else ]]
RUN echo '[[.Container.BeforeScript]]' > /root/before-setup.sh
[[ end ]]

RUN chmod +x /root/before-setup.sh
RUN chmod +x /root/before-setup.sh
[[ end ]]

[[ if (.Container.HasAfterScript) ]]
[[ if (.Container.HasAfterScriptFile) ]]
ADD [[.Container.AfterScript]] /root/after-setup.sh
[[ else ]]
RUN echo '[[.Container.AfterScript]]' > /root/after-setup.sh
[[ end ]]
[[ if (.Container.HasAfterScriptFile) ]]
ADD [[.Container.AfterScript]] /root/after-setup.sh
[[ else ]]
RUN echo '[[.Container.AfterScript]]' > /root/after-setup.sh
[[ end ]]

RUN chmod +x /root/after-setup.sh
RUN chmod +x /root/after-setup.sh
[[ end ]]
6 changes: 6 additions & 0 deletions templates/_includes/installNodeJS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Install nodejs with nvm
[[ $nodeVersion := .Container.GetCustomValue "nodeVersion" (.Container.GetCustomValue "version" "0.10.20")]]

RUN git clone https://github.com/creationix/nvm.git /.nvm
#RUN echo "/.nvm/nvm.sh" >> /etc/bash.bashrc
RUN /bin/bash -c '. /.nvm/nvm.sh && nvm install v[[ $nodeVersion ]] && nvm use v[[ $nodeVersion ]] && nvm alias default v[[ $nodeVersion ]] && ln -s /.nvm/v[[ $nodeVersion ]]/bin/node /usr/bin/node && ln -s /.nvm/v[[ $nodeVersion ]]/bin/npm /usr/bin/npm'
14 changes: 14 additions & 0 deletions templates/_includes/installRvm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Install ruby via RVM
[[ $version := (.Container.GetCustomValue "version" "2.1.2") ]]

RUN apt-get install -y --reinstall procps
RUN curl -L https://get.rvm.io | bash -s stable

ENV PATH /usr/local/rvm/bin/:$PATH
ENV PATH /usr/local/rvm/rubies/ruby-[[ $version ]]/bin/:$PATH
ENV PATH /usr/local/rvm/gems/ruby-[[ $version ]]/bin/:$PATH

RUN rvm install [[ $version ]]
RUN rvm use [[ $version ]] --default


4 changes: 2 additions & 2 deletions templates/ambassador/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ FROM stackbrew/debian:wheezy

RUN apt-get install -y -f socat

CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/' | sh \
&& /bin/bash
CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/' | sh \
&& /bin/bash
82 changes: 42 additions & 40 deletions templates/apache/000-default
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
<VirtualHost *:[[ .Container.GetFirstLocalPort ]]>
ServerAdmin webmaster@localhost

[[ $documentRoot := (.Container.GetCustomValue "documentRoot") ]]
[[ if $documentRoot ]]
DocumentRoot [[ $documentRoot ]]
[[ else ]]
DocumentRoot /var/www
[[ end ]]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

[[ if $documentRoot ]]
ServerAdmin webmaster@localhost

[[ $documentRoot := (.Container.GetCustomValue "documentRoot") ]]
[[ if $documentRoot ]]
DocumentRoot [[ $documentRoot ]]
[[ else ]]
DocumentRoot /var/www
[[ end ]]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

[[ if $documentRoot ]]
<Directory [[ $documentRoot ]]>
[[ else ]]
<Directory /var/www/>
[[ end ]]
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

[[ if(.Container.DependsOf "django" )]]
[[ $django := (.Collection.GetType "django") ]]
WSGIScriptAlias / /app/[[ (.Collection.GetType "django").GetCustomValue "project_name" "project" ]]/wsgi.py
[[ if(.Container.DependsOf "django" )]]
[[ $django := (.Collection.GetType "django") ]]
WSGIScriptAlias / /app/[[ $django.GetCustomValue "project_name" "project" ]]/wsgi.py

Alias /static/admin /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin
Alias /static/ /app/[[ $django.GetCustomValue "project_name" "project" ]]/[[ $django.GetCustomValue "app_name" "myapp" ]]/static/
Alias /uploads/ /app/uploads/
[[ end ]]
[[ end ]]

<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log

ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined

CustomLog ${APACHE_LOG_DIR}/access.log combined
[[ $fastCgi := .Collection.Get (.Container.GetCustomValueAsString "fastCgi") (.Collection.GetType "php-fpm") ]]
[[ if $fastCgi ]]
[[ $fastCgiIdleTimeout := .Container.GetCustomValue "fastCgiIdleTimeout" "30" ]]
[[ $fastCgiPath := "/var/www/cgi-bin/php5.external" ]]

[[ $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.GetFirstLocalPort ]]_TCP_ADDR}:${[[ $fastCgi.Name | ToUpper ]]_PORT_[[ $fastCgi.GetFirstLocalPort]]_TCP_PORT} -idle-timeout [[ $fastCgiIdleTimeout ]]
Alias /cgi-bin/ /var/www/cgi-bin/
[[end]]
FastCgiExternalServer [[ $fastCgiPath ]] -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>

31 changes: 16 additions & 15 deletions templates/apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ RUN echo "deb-src http://ftp.fr.debian.org/debian/ wheezy non-free" >> /etc/apt/
[[ updateApt ]]
[[ addUserFiles ]]

RUN apt-get install -y -f apache2-mpm-worker libapache2-mod-fastcgi php5-fpm
RUN sed -i 's/;pm.start_servers/pm.start_servers/g' /etc/php5/fpm/pool.d/www.conf
RUN apt-get install -y -f apache2-mpm-worker libapache2-mod-fastcgi
RUN a2enmod actions fastcgi alias

[[range (.Container.GetCustomValue "modules")]]
RUN a2enmod [[.]]
RUN a2enmod [[.]]
[[end]]
RUN service apache2 reload

[[ if(.Container.DependsOf "django" )]]
RUN apt-get install -y -f python2.7 python-dev python-setuptools libmysqlclient-dev
RUN easy_install pip
RUN pip install django==1.6
RUN pip install mysql-python
RUN apt-get install -y -f python2.7 python-dev python-setuptools libmysqlclient-dev
RUN easy_install pip
RUN pip install django==1.6
RUN pip install mysql-python

RUN apt-get install -y -f libapache2-mod-wsgi
RUN apt-get install -y -f libapache2-mod-wsgi

RUN echo "WSGIPythonPath /app/[[ (.Collection.GetType "django").GetCustomValue "project_name" "project" ]]:/usr/local/lib/python2.7/site-packages" >> /etc/apache2/httpd.conf
RUN echo "WSGIPythonPath /app/[[ (.Collection.GetType "django").GetCustomValue "project_name" "project" ]]:/usr/local/lib/python2.7/site-packages" >> /etc/apache2/httpd.conf
[[ end ]]

# Add setup script
Expand All @@ -35,16 +34,18 @@ 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" ]]
[[ if and $fastCgi (or (eq $fastCgi.Type "php-fpm") (eq $fastCgi.Type "hhvm"))]]
[[ $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 apt-get install -y -f php5-fpm
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
RUN sed -i 's|;pm.start_servers|pm.start_servers|g' /etc/php5/fpm/pool.d/www.conf
[[ end ]]
# Add custom setup script
[[ beforeAfterScripts ]]
Expand All @@ -53,7 +54,7 @@ ADD ports.conf /etc/apache2/ports.conf
CMD /bin/bash
[[ else ]]
CMD [[ if (.Container.HasBeforeScript) ]] /bin/bash /root/before-setup.sh && [[end]] /bin/bash /root/setup.sh \
&& /etc/init.d/apache2 start \
[[ if (.Container.HasAfterScript) ]] && /bin/bash /root/after-setup.sh \[[end]]
&& /bin/bash
&& /etc/init.d/apache2 start \
[[ if (.Container.HasAfterScript) ]] && /bin/bash /root/after-setup.sh \[[end]]
&& /bin/bash
[[ end ]]
14 changes: 7 additions & 7 deletions templates/apache/fastcgi.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /cgi-bin/php5.external
AddHandler php5-fcgi .php
Action php5-fcgi /cgi-bin/php5.external

<Location "/cgi-bin/php5.external">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</Location>
<Location "/cgi-bin/php5.external">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</Location>
</IfModule>
7 changes: 1 addition & 6 deletions templates/bower/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ FROM stackbrew/debian:wheezy
[[ updateApt ]]
[[ addUserFiles ]]

[[ $version := .Container.GetCustomValue "fastCgi" "0.10.20"]]

# Install nodejs with nvm
RUN git clone https://github.com/creationix/nvm.git /.nvm
RUN echo "/.nvm/nvm.sh" >> /etc/bash.bashrc
RUN /bin/bash -c '. /.nvm/nvm.sh && nvm install v[[ $version ]] && nvm use v[[ $version ]] && nvm alias default v[[ $version ]] && ln -s /.nvm/v[[ $version ]]/bin/node /usr/bin/node && ln -s /.nvm/v[[ $version ]]/bin/npm /usr/bin/npm'
[[ installNodeJS ]]

# Install NPM
RUN curl https://www.npmjs.org/install.sh | clean=no sh
Expand Down
2 changes: 1 addition & 1 deletion templates/cassandra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN sed -i -e "s/rpc_address:\slocalhost/rpc_address: 0.0.0.0/" /etc/cassandra/c
RUN sed -i -e "s/#MAX_HEAP_SIZE=\"4G\"/MAX_HEAP_SIZE=\"[[ (.Container.GetCustomValue "maxHeapSize" "512M") ]]\"/" /etc/cassandra/cassandra-env.sh
RUN sed -i -e "s/#HEAP_NEWSIZE=\"800M\"/HEAP_NEWSIZE=\"[[ (.Container.GetCustomValue "heapNewSize" "128M") ]]\"/" /etc/cassandra/cassandra-env.sh

[[ if .EmptyCmd]]
[[ if .EmptyCmd ]]
CMD /bin/bash
[[ else ]]
CMD /etc/init.d/cassandra start && /bin/bash
Expand Down
16 changes: 8 additions & 8 deletions templates/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN echo "deb-src http://ftp.fr.debian.org/debian/ wheezy non-free" >> /etc/apt/
[[ updateApt ]]
[[ addUserFiles ]]

WORKDIR /app
WORKDIR [[ .Container.GetFirstMountedDir ]]

RUN apt-get install -y -f python2.7 python-dev python-setuptools libmysqlclient-dev
RUN easy_install pip
Expand All @@ -15,7 +15,7 @@ RUN pip install mysql-python
RUN pip install south

[[range (.Container.GetCustomValue "pip_modules")]]
RUN pip install [[.]]
RUN pip install [[.]]
[[end]]

# Add setup script
Expand All @@ -25,13 +25,13 @@ RUN chmod +x /root/setup.sh
# Add custom setup script
[[ beforeAfterScripts ]]

[[ if .EmptyCmd]]
[[ if .EmptyCmd ]]
CMD /bin/bash
[[ else ]]
CMD [[ if (.Container.HasBeforeScript) ]] /bin/bash /root/before-setup.sh && [[end]] /bin/bash /root/setup.sh \
[[ if (.Container.HasAfterScript) ]] && /bin/bash /root/after-setup.sh \[[end]]
[[ if eq (.Collection.IsComponentDependingOf .Container "apache") false ]]
&& python manage.py runserver 0.0.0.0:[[ .Container.GetFirstLocalPort "8000" ]] \
[[end]]
&& /bin/bash
[[ if (.Container.HasAfterScript) ]] && /bin/bash /root/after-setup.sh \[[end]]
[[ if eq (.Collection.IsComponentDependingOf .Container "apache") false ]]
&& python manage.py runserver 0.0.0.0:[[ .Container.GetFirstLocalPort "8000" ]] \
[[end]]
&& /bin/bash
[[ end ]]
Loading

0 comments on commit 30ad825

Please sign in to comment.