diff --git a/Dockerfile b/Dockerfile index 96b65e3..0d82b71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,51 +2,45 @@ # 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 +LABEL maintainer="François Jacquet " -ENV DEBIAN_FRONTEND noninteractive - -# Release info. -RUN cat /etc/lsb-release +ENV PGHOST=rosariosisdb \ + PGUSER=postgres \ + PGPASSWORD=postgres \ + PGDATABASE=postgres \ + PGPORT=5432 \ + ROSARIOSIS_YEAR=2017 \ + ROSARIOSIS_LANG='en_US' # Upgrade packages. -# Add universe depot. -RUN sed 's/InRelease$/InRelease universe/' -i /etc/apt/sources.list +# Install git, Apache2 + PHP + PostgreSQL webserver, sendmail, wkhtmltopdf & others utilities. # Change date to force an upgrade: -RUN apt-get update # 2016-06-29 -RUN apt-get upgrade -y +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install postgresql-client wkhtmltopdf libpq-dev libpng-dev libxml2-dev sendmail -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 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 git clone https://github.com/francoisjacquet/rosariosis.git /usr/src/rosariosis -WORKDIR /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 +# 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 # 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/README.md b/README.md index f635048..fefcce5 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 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 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 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 RosarioSIS to store data. + +### ROSARIOSIS_YEAR + +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 RosarioSIS to show in another language + +### ROSARIOSIS_VERSION + +This optional environment variable is used to set the required version of RosarioSIS + + ## 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: diff --git a/bin/init b/bin/init index da50f32..633eca3 100755 --- a/bin/init +++ b/bin/init @@ -1,10 +1,38 @@ #!/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 ${PGDATABASE} | wc -l` + +echo 'Database '$DB_EXISTS +if [ "$DB_EXISTS" -gt "0" ]; then + psql -f /usr/src/rosariosis/rosariosis.sql +else + echo "Database does not exists" +fi + +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- php "$@" +fi + +exec "$@" 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..c9bff36 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +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 + ROSARIOSIS_YEAR: 2017 +# ROSARIOSIS_LANG: 'es_ES'