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 1/8] 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 From 6b09ab1b44b7427939ae400d7ee126318fecc726 Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 07:14:48 -0500 Subject: [PATCH 2/8] Started apache and listening --- bin/init | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/init b/bin/init index 1270966..7afa1ab 100755 --- a/bin/init +++ b/bin/init @@ -24,6 +24,15 @@ 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 +else echo "Database does not exists" fi + +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- php "$@" +fi + +exec "$@" From cd5775376389db19379ab6fbf76ae6cf64b23eee Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 12:48:14 -0500 Subject: [PATCH 3/8] Refactor, using variables --- Dockerfile | 37 +++++++++++++++++++++---------------- docker-compose.yml | 25 +++++++++---------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 29718b4..0d82b71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,31 +4,36 @@ FROM php:5.6-apache -MAINTAINER François Jacquet +LABEL maintainer="François Jacquet " + +ENV PGHOST=rosariosisdb \ + PGUSER=postgres \ + PGPASSWORD=postgres \ + PGDATABASE=postgres \ + PGPORT=5432 \ + ROSARIOSIS_YEAR=2017 \ + ROSARIOSIS_LANG='en_US' # Upgrade packages. -# 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 postgresql-client wkhtmltopdf libpq-dev libpng-dev libxml2-dev sendmail -y; + +# Change date to force an upgrade: +RUN apt-get update && \ + apt-get upgrade -y && \ + 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 + 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 - -WORKDIR /usr/src/rosariosis - -RUN rm -rf /var/www/html && mkdir -p /var/www && \ +# Download and extract rosariosis +ENV ROSARIOSIS_VERSION 'v3.5' +RUN mkdir /usr/src/rosariosis && \ + curl -L https://github.com/francoisjacquet/rosariosis/tarball/${ROSARIOSIS_VERSION} \ + | tar xz --strip-components=1 -C /usr/src/rosariosis && \ + 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 - # Copy our custom RosarioSIS configuration file. COPY conf/config.inc.php /usr/src/rosariosis/config.inc.php COPY conf/.htaccess /usr/src/rosariosis/.htaccess diff --git a/docker-compose.yml b/docker-compose.yml index 391e23a..bc2ae97 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,11 @@ services: db: image: sameersbn/postgresql:9.5 - environment: - POSTGRES_PASSWORD: example - DB_USER: rosario - DB_PASS: rosariopwd - DB_NAME: rosariosis + # environment: + # POSTGRES_PASSWORD: example + # DB_USER: rosario + # DB_PASS: rosariopwd + # DB_NAME: rosariosis web: build: . @@ -18,14 +18,7 @@ services: - 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 + # PGUSER: rosario + # PGPASSWORD: rosariopwd + # PGDATABASE: rosariosis + # ROSARIOSIS_LANG: 'es_ES' From 1d265caa96545a923ccae07e0dfbf5b6fc053abe Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 22:04:45 -0500 Subject: [PATCH 4/8] cheking database from env var --- bin/init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/init b/bin/init index 7afa1ab..633eca3 100755 --- a/bin/init +++ b/bin/init @@ -19,10 +19,10 @@ until psql -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do done -DB_EXISTS=`psql -l | grep rosariosis | wc -l` +DB_EXISTS=`psql -l | grep ${PGDATABASE} | wc -l` echo 'Database '$DB_EXISTS -if [ "$DB_EXISTS" -eq "1" ]; then +if [ "$DB_EXISTS" -gt "0" ]; then psql -f /usr/src/rosariosis/rosariosis.sql else echo "Database does not exists" From 913ea03c601fa87f1e55335ef9ee463c1cb5f895 Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 22:09:16 -0500 Subject: [PATCH 5/8] Deleted ports and configs not needed --- docker-compose.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bc2ae97..2e92727 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,11 @@ services: db: image: sameersbn/postgresql:9.5 - # environment: - # POSTGRES_PASSWORD: example - # DB_USER: rosario - # DB_PASS: rosariopwd - # DB_NAME: rosariosis + environment: + POSTGRES_PASSWORD: example + DB_USER: rosario + DB_PASS: rosariopwd + DB_NAME: rosariosis web: build: . @@ -18,7 +18,8 @@ services: - db environment: PGHOST: db - # PGUSER: rosario - # PGPASSWORD: rosariopwd - # PGDATABASE: rosariosis - # ROSARIOSIS_LANG: 'es_ES' + PGUSER: rosario + PGPASSWORD: rosariopwd + PGDATABASE: rosariosis + ROSARIOSIS_YEAR: 2017 + ROSARIOSIS_LANG: 'es_ES' From 9d844ee2941923bd7613cfead7915f2378268a7e Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Fri, 22 Sep 2017 22:19:02 -0500 Subject: [PATCH 6/8] Added ENV vars to readme --- README.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f635048..013f616 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,49 @@ $ docker build -t rosariosis . RosarioSIS uses a PostgreSQL database: ```bash -$ docker run --name rosariosisdb -d postgres:9.5 --restart=always -$ docker run -e "ROSARIOSIS_ADMIN_EMAIL=admin@example.com" -h `hostname -f` -d -p 80:80 --name rosariosis --link rosariosisdb:rosariosisdb rosariosis --restart=always +$ docker run --name rosariosisdb -d postgres:9.5 +$ docker run -e "ROSARIOSIS_ADMIN_EMAIL=admin@example.com" -h `hostname -f` -d -p 80:80 --name rosariosis --link rosariosisdb:rosariosisdb rosariosis ``` Port 80 will be exposed, so you can visit `localhost` to get started. The default username is `admin` and the default password is `admin`. +## Enviroment Variables + +The RosarioSIS image uses several environment variables which are easy to miss. While none of the variables are required, they may significantly aid you in using the image. + +### PGHOST + +Host of the postgres data + +### PGUSER + +This optional environment variable is used in conjunction with PGPASSWORD to set a user and its password. + +### PGPASSWORD + +This optional environment variable is used in conjunction with PGUSER to set a user and its password. + +### PGDATABASE + +This optional environment variable can be used to define a different name for the default database that is used by rosario to store data. + +### PGPORT + +This optional environment variable can be used to define a different port for the default database that is used by rosario to store data. + +### ROSARIOSIS_YEAR + +This optional environment variable can be used to define a year in the rosario settings. + +### ROSARIOSIS_LANG + +This optional environment variable is used for make rosario to show in another language + +### ROSARIOSIS_VERSION + +This optional environment variable is used to set the required version of Rosario SIS + + ## SMTP RosarioSIS will attempt to send mail via the host's port 25. In order for this to work you must set the hostname of the rosariosis container to that of `host` (or some other hostname that your can appear on a legal `FROM` line) and configure the host to accept SMTP from the container. For postfix this means adding the container IP addresses to `/etc/postfix/main.cf` as in: From c22be4bba4007eb5cb708b8e501e6117db8d54c3 Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Tue, 26 Sep 2017 08:07:33 -0500 Subject: [PATCH 7/8] README rosario -> RosarioSIS --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 013f616..fefcce5 100644 --- a/README.md +++ b/README.md @@ -34,31 +34,31 @@ Host of the postgres data ### PGUSER -This optional environment variable is used in conjunction with PGPASSWORD to set a user and its password. +This optional environment variable is used in conjunction with PGPASSWORD to set a user and its password for the default database that is used by RosarioSIS to store data. ### PGPASSWORD -This optional environment variable is used in conjunction with PGUSER to set a user and its password. +This optional environment variable is used in conjunction with PGUSER to set a user and its password for the default database that is used by RosarioSIS to store data. ### PGDATABASE -This optional environment variable can be used to define a different name for the default database that is used by rosario to store data. +This optional environment variable can be used to define a different name for the default database that is used by RosarioSIS to store data. ### PGPORT -This optional environment variable can be used to define a different port for the default database that is used by rosario to store data. +This optional environment variable can be used to define a different port for the default database that is used by RosarioSIS to store data. ### ROSARIOSIS_YEAR -This optional environment variable can be used to define a year in the rosario settings. +This optional environment variable can be used to define a year in the RosarioSIS settings. ### ROSARIOSIS_LANG -This optional environment variable is used for make rosario to show in another language +This optional environment variable is used for make RosarioSIS to show in another language ### ROSARIOSIS_VERSION -This optional environment variable is used to set the required version of Rosario SIS +This optional environment variable is used to set the required version of RosarioSIS ## SMTP From ed6c71b3cf1db476eff00c8deb7b569587833e11 Mon Sep 17 00:00:00 2001 From: "Sergio C. Orozco Torres" Date: Tue, 26 Sep 2017 22:37:30 -0500 Subject: [PATCH 8/8] Commented spanish language for docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2e92727..c9bff36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,4 +22,4 @@ services: PGPASSWORD: rosariopwd PGDATABASE: rosariosis ROSARIOSIS_YEAR: 2017 - ROSARIOSIS_LANG: 'es_ES' +# ROSARIOSIS_LANG: 'es_ES'