From b3b328f80c9bd67ee7e2ba44afe3fa6633e7618c Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 01:08:06 -0500 Subject: [PATCH] Actualizado usando imagen php:5.6-apache --- Dockerfile | 43 ++++++++++++++++--------------------------- bin/init | 31 +++++++++++++++++++++++++------ conf/.htaccess | 1 + conf/config.inc.php | 17 +++++++++-------- docker-compose.yml | 31 +++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 41 deletions(-) create mode 100644 conf/.htaccess create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 96b65e3..29718b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,51 +2,40 @@ # https://www.rosariosis.org/ # Best Dockerfile practices: http://crosbymichael.com/dockerfile-best-practices.html -FROM ubuntu +FROM php:5.6-apache MAINTAINER François Jacquet -ENV DEBIAN_FRONTEND noninteractive - -# Release info. -RUN cat /etc/lsb-release - # Upgrade packages. -# Add universe depot. -RUN sed 's/InRelease$/InRelease universe/' -i /etc/apt/sources.list - # Change date to force an upgrade: RUN apt-get update # 2016-06-29 RUN apt-get upgrade -y # Install git, Apache2 + PHP + PostgreSQL webserver, sendmail, wkhtmltopdf & others utilities. -RUN apt-get install git postgresql sendmail wkhtmltopdf supervisor apache2 \ - libapache2-mod-php php-pgsql php-curl php-xmlrpc \ - openssl telnet nmap -y --force-yes +RUN apt-get install postgresql-client wkhtmltopdf libpq-dev libpng-dev libxml2-dev sendmail -y; + +RUN docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \ +docker-php-ext-install -j$(nproc) gd mbstring xml pgsql gettext xmlrpc + +RUN mkdir /usr/src/rosariosis && curl -L https://github.com/francoisjacquet/rosariosis/tarball/v3.5 | tar xz --strip-components=1 -C /usr/src/rosariosis -RUN git clone https://github.com/francoisjacquet/rosariosis.git /usr/src/rosariosis WORKDIR /usr/src/rosariosis +RUN rm -rf /var/www/html && mkdir -p /var/www && \ + ln -s /usr/src/rosariosis/ /var/www/html && chmod 777 /var/www/html &&\ + chown -R www-data:www-data /usr/src/rosariosis + + # Uncomment to checkout a tagged release: # RUN git checkout 2.9.3 -# Links rosariosis directory to Apache document root. -RUN rm -rf /var/www/html && mkdir -p /var/www && ln -s /usr/src/rosariosis/ /var/www/html && chmod 777 /var/www/html - -# Copy our init script (creates rosariosis PostgreSQL DB & import rosariosis.sql file). -COPY bin/init /init - -# Copy our start Apache2 script. -COPY bin/start-apache2 /start-apache2 - -# Copy our custom supervisord.conf file. -COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf - # Copy our custom RosarioSIS configuration file. COPY conf/config.inc.php /usr/src/rosariosis/config.inc.php +COPY conf/.htaccess /usr/src/rosariosis/.htaccess +COPY bin/init /init -RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf EXPOSE 80 -ENTRYPOINT [ "/init" ] +ENTRYPOINT ["/init"] +CMD ["apache2-foreground"] diff --git a/bin/init b/bin/init index da50f32..1270966 100755 --- a/bin/init +++ b/bin/init @@ -1,10 +1,29 @@ #!/bin/bash -DB_EXISTS=`psql -U postgres -h $ROSARIODB_PORT_5432_TCP_ADDR -p $ROSARIODB_PORT_5432_TCP_PORT -l | grep rosariosis | wc -l` - -if [ "$DB_EXISTS" -eq "0" ]; then - psql -U postgres -h $ROSARIODB_PORT_5432_TCP_ADDR -p $ROSARIODB_PORT_5432_TCP_PORT -c "CREATE DATABASE rosariosis WITH ENCODING 'UTF8' TEMPLATE template1" - psql -U postgres -h $ROSARIODB_PORT_5432_TCP_ADDR -p $ROSARIODB_PORT_5432_TCP_PORT rosariosis < rosariosis.sql +echo "Configuring locale" +if [ "$ROSARIOSIS_LANG" == "en_US" ]; then + echo "Found "$ROSARIOSIS_LANG +else + echo "Installing "$ROSARIOSIS_LANG + apt-get install locales + echo $ROSARIOSIS_LANG'.UTF-8 UTF-8' > /etc/locale.gen + locale-gen fi -/usr/bin/supervisord +echo "Configuring database" +RETRIES=5 + +until psql -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do + echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..." + sleep 1 +done + + +DB_EXISTS=`psql -l | grep rosariosis | wc -l` + +echo 'Database '$DB_EXISTS +if [ "$DB_EXISTS" -eq "1" ]; then + psql -f /usr/src/rosariosis/rosariosis.sql +else + echo "Database does not exists" +fi diff --git a/conf/.htaccess b/conf/.htaccess new file mode 100644 index 0000000..3c6a448 --- /dev/null +++ b/conf/.htaccess @@ -0,0 +1 @@ +php_flag display_errors off diff --git a/conf/config.inc.php b/conf/config.inc.php index 6c9e9c6..4d3a2bd 100644 --- a/conf/config.inc.php +++ b/conf/config.inc.php @@ -14,19 +14,20 @@ */ // Database server hostname: use localhost if on same server. -$DatabaseServer = getenv( 'ROSARIODB_PORT_5432_TCP_ADDR' ); + +$DatabaseServer = getenv( 'PGHOST' ); // Database username. -$DatabaseUsername = 'postgres'; +$DatabaseUsername = getenv( 'PGUSER' ); // Database password. -//$DatabasePassword = 'password_here'; +$DatabasePassword = getenv( 'PGPASSWORD' );; // Database name. -$DatabaseName = 'rosariosis'; +$DatabaseName = getenv( 'PGDATABASE' );; // Database port: default is 5432. -$DatabasePort = getenv( 'ROSARIODB_PORT_5432_TCP_PORT' ); +$DatabasePort = getenv( 'PGPORT' ); /** @@ -52,7 +53,7 @@ $pg_dumpPath = '/usr/bin/pg_dump'; * @example /usr/local/bin/wkhtmltopdf * @example C:/Progra~1/wkhtmltopdf/bin/wkhtmltopdf.exe */ -$wkhtmltopdfPath = '/usr/local/bin/wkhtmltopdf'; +$wkhtmltopdfPath = '/usr/bin/wkhtmltopdf'; /** @@ -62,7 +63,7 @@ $wkhtmltopdfPath = '/usr/local/bin/wkhtmltopdf'; * Change after rollover * Should match the database to be able to login */ -$DefaultSyear = '2016'; +$DefaultSyear = getenv( 'ROSARIOSIS_YEAR' ); /** @@ -85,4 +86,4 @@ $RosarioNotifyAddress = getenv( 'ROSARIOSIS_ADMIN_EMAIL' ); * * @example array( 'en_US.utf8', 'fr_FR.utf8', 'es_ES.utf8' ); */ -$RosarioLocales = array( 'en_US.utf8' ); +$RosarioLocales = array( getenv( 'ROSARIOSIS_LANG' ).'.utf8' ); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..391e23a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.1' + +services: + + db: + image: sameersbn/postgresql:9.5 + environment: + POSTGRES_PASSWORD: example + DB_USER: rosario + DB_PASS: rosariopwd + DB_NAME: rosariosis + + web: + build: . + ports: + - "80:80" + depends_on: + - db + environment: + PGHOST: db + PGUSER: rosario + PGPASSWORD: rosariopwd + PGDATABASE: rosariosis + PGPORT: 5432 + ROSARIOSIS_YEAR: 2017 + ROSARIOSIS_LANG: 'es_ES' + + adminer: + image: adminer + ports: + - 8081:8080