From b8b52eee234b0f3c9e9af8a1e3593fa0e13e8464 Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Thu, 20 Apr 2017 16:03:52 +0530 Subject: [PATCH 1/6] Added centos container for phppgadmin. --- phppgadmin/centos7/Dockerfile | 19 +++++++++++ phppgadmin/centos7/README.md | 23 ++++++++++++++ phppgadmin/centos7/cccp.yml | 1 + phppgadmin/centos7/fix-permissions.sh | 8 +++++ phppgadmin/centos7/install.sh | 45 +++++++++++++++++++++++++++ phppgadmin/centos7/passwd.template | 14 +++++++++ phppgadmin/centos7/run.sh | 19 +++++++++++ 7 files changed, 129 insertions(+) create mode 100644 phppgadmin/centos7/Dockerfile create mode 100644 phppgadmin/centos7/README.md create mode 100644 phppgadmin/centos7/cccp.yml create mode 100755 phppgadmin/centos7/fix-permissions.sh create mode 100755 phppgadmin/centos7/install.sh create mode 100644 phppgadmin/centos7/passwd.template create mode 100755 phppgadmin/centos7/run.sh diff --git a/phppgadmin/centos7/Dockerfile b/phppgadmin/centos7/Dockerfile new file mode 100644 index 00000000..d971eeb3 --- /dev/null +++ b/phppgadmin/centos7/Dockerfile @@ -0,0 +1,19 @@ +FROM registry.centos.org/centos/centos:7 + +MAINTAINER Mohammed Zeesahan Ahmed + +# RUN yum -y update && yum clean all + +ADD install.sh run.sh fix-permissions.sh passwd.template /opt/scripts/ + +RUN chmod -R 777 /opt/scripts && . /opt/scripts/install.sh + +EXPOSE 8080 8443 + +USER apache + +WORKDIR /usr/share/phpPgAdmin + +ENTRYPOINT ["/opt/scripts/run.sh"] + +CMD ["phppgadmin"] diff --git a/phppgadmin/centos7/README.md b/phppgadmin/centos7/README.md new file mode 100644 index 00000000..dc16a815 --- /dev/null +++ b/phppgadmin/centos7/README.md @@ -0,0 +1,23 @@ +# Containerized PhpPgAdmin + +Know more about what the software is at their [website](http://phppgadmin.sourceforge.net/doku.php%20phppgadmin). + +Note container runs on openshift. + +## Environment variables + + 1. POSTGRESQL_SERVER - The ip or reachable address of the postgresql database to connect to + +## Build container + + $ docker build -t registry.centos.org/centos/phppgadmin:latest -f Dockerfile . + +## Sample usage + +###Run Postgresql: + + $ docker run -e POSTGRESQL_USER=myuser -e POSTGRESQL_PASSWORD=myuser -e POSTGRESQL_DATABASE=myuser -d registry.centos.org/postgresql/postgresql:9.6 + +###Run phppgadmin + + $ docker run -e POSTGRESQL_SERVER="" -d registry.centos.org/centos/phppgadmin:latest diff --git a/phppgadmin/centos7/cccp.yml b/phppgadmin/centos7/cccp.yml new file mode 100644 index 00000000..5c9fd500 --- /dev/null +++ b/phppgadmin/centos7/cccp.yml @@ -0,0 +1 @@ +job-id: phppgadmin diff --git a/phppgadmin/centos7/fix-permissions.sh b/phppgadmin/centos7/fix-permissions.sh new file mode 100755 index 00000000..40df1386 --- /dev/null +++ b/phppgadmin/centos7/fix-permissions.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Fix permissions on the given directory to allow group read/write of +# regular files and execute of directories. +set -eux +find "$1" -exec chown ${2} {} \; +find "$1" -exec chgrp 0 {} \; +find "$1" -exec chmod g+rw {} \; +find "$1" -type d -exec chmod g+x {} + diff --git a/phppgadmin/centos7/install.sh b/phppgadmin/centos7/install.sh new file mode 100755 index 00000000..d210113c --- /dev/null +++ b/phppgadmin/centos7/install.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +#!/usr/bin/env bash + +set -eux; + +# Initialize variables +HTTPD_CONF="/etc/httpd/conf/httpd.conf" +PHP_PGADMIN_HTTPD_CONF="/etc/httpd/conf.d/phpPgAdmin.conf" +HTTPD_WELCOME="/etc/httpd/conf.d/welcome.conf" +INSTALL_PKGS="httpd phpPgAdmin highlight policycoreutils-python nss_wrapper gettext"; + +# Setup necessary packages +yum -y install epel-release && yum -y install ${INSTALL_PKGS}; + +# Fixup Configurations +rm -rf ${HTTPD_WELCOME}; +sed -i 's/^Listen 80/Listen 8080\\\nListen 8443/g' ${HTTPD_CONF}; +sed -i 's/^Listen 8080\\/Listen 8080/g' ${HTTPD_CONF}; +sed -i 's/^Group apache/Group root/g' ${HTTPD_CONF}; +mkdir -p /etc/httpd/logs && touch /etc/httpd/logs/error_log && touch /etc/httpd/logs/access_log; +cat >${PHP_PGADMIN_HTTPD_CONF} < + + # Apache 2.4 + Require all granted + #Require host example.com + + + # Apache 2.2 + Order allow, deny + Allow from all + + + +EOF + +# Fix the permissions +for item in "/etc/httpd" "/var/www" "/usr/share/phpPgAdmin" "/etc/phpPgAdmin"; do + . /opt/scripts/fix-permissions.sh ${item} apache; +done + +chmod -R 777 /etc/httpd/logs \ No newline at end of file diff --git a/phppgadmin/centos7/passwd.template b/phppgadmin/centos7/passwd.template new file mode 100644 index 00000000..744ecd84 --- /dev/null +++ b/phppgadmin/centos7/passwd.template @@ -0,0 +1,14 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +operator:x:11:0:operator:/root:/sbin/nologin +games:x:12:100:games:/usr/games:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +nobody:x:99:99:Nobody:/:/sbin/nologin +apache:x:${USER_ID}:${GROUP_ID}:Apache User:${HOME}:/bin/bash \ No newline at end of file diff --git a/phppgadmin/centos7/run.sh b/phppgadmin/centos7/run.sh new file mode 100755 index 00000000..2000cf1c --- /dev/null +++ b/phppgadmin/centos7/run.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +export USER_ID=$(id -u); +export GROUP_ID=$(id -g); +envsubst < /opt/scripts/passwd.template > /tmp/passwd; +export LD_PRELOAD=libnss_wrapper.so; +export NSS_WRAPPER_PASSWD=/tmp/passwd; +export NSS_WRAPPER_GROUP=/etc/group; + +PHP_PG_ADMIN_CONFIG="/etc/phpPgAdmin/config.inc.php" +POSTGRESQL_SERVER=${POSTGRESQL_SERVER:-"localhost"} + +sed -i "s/conf\['servers'\]\[0\]\['host'\] = '.*'/conf\['servers'\]\[0\]\['host'\] = '${POSTGRESQL_SERVER}'/g" ${PHP_PG_ADMIN_CONFIG}; + +if [ $1 == "phppgadmin" ]; then + exec /usr/sbin/httpd -DFOREGROUND; +else + exec $1 +fi From 184254c8e2fea39e3d6668b6476275efafed7098 Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Fri, 21 Apr 2017 12:28:26 +0530 Subject: [PATCH 2/6] Fixed the non-inclusion of /var/lib/php in permission fixes. --- phppgadmin/centos7/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phppgadmin/centos7/install.sh b/phppgadmin/centos7/install.sh index d210113c..732930a9 100755 --- a/phppgadmin/centos7/install.sh +++ b/phppgadmin/centos7/install.sh @@ -38,8 +38,8 @@ Alias /phpPgAdmin /usr/share/phpPgAdmin EOF # Fix the permissions -for item in "/etc/httpd" "/var/www" "/usr/share/phpPgAdmin" "/etc/phpPgAdmin"; do +for item in "/etc/httpd" "/var/www" "/usr/share/phpPgAdmin" "/etc/phpPgAdmin" "/var/lib/php"; do . /opt/scripts/fix-permissions.sh ${item} apache; done -chmod -R 777 /etc/httpd/logs \ No newline at end of file +chmod -R 777 /etc/httpd/logs From cc03713316b12bd5c70fda32e2b5a83366ee9b96 Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Fri, 21 Apr 2017 12:30:41 +0530 Subject: [PATCH 3/6] Removed extra shebang. --- phppgadmin/centos7/install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/phppgadmin/centos7/install.sh b/phppgadmin/centos7/install.sh index 732930a9..67e91a5d 100755 --- a/phppgadmin/centos7/install.sh +++ b/phppgadmin/centos7/install.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -#!/usr/bin/env bash - set -eux; # Initialize variables From d306b7ca04cb6f24efb7ca49f7cbfaf709eabd65 Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Fri, 21 Apr 2017 12:34:50 +0530 Subject: [PATCH 4/6] Added some information to the README. --- phppgadmin/centos7/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phppgadmin/centos7/README.md b/phppgadmin/centos7/README.md index dc16a815..99be3134 100644 --- a/phppgadmin/centos7/README.md +++ b/phppgadmin/centos7/README.md @@ -2,7 +2,10 @@ Know more about what the software is at their [website](http://phppgadmin.sourceforge.net/doku.php%20phppgadmin). -Note container runs on openshift. +Notes: + 1. Container runs on openshift. + 2. For sharing sessions, please share the /var/lib/php accross the containers with appropriate permissions + 3. You can provide your own custom config by mounting same into /etc/phpPgAdmin/config.inc.php. Just bear in mind, file permissions. ## Environment variables From cead0327fbf4251c5b94063959be18d670ffb374 Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Fri, 21 Apr 2017 13:33:50 +0530 Subject: [PATCH 5/6] Updated to tail log files. --- phppgadmin/centos7/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phppgadmin/centos7/run.sh b/phppgadmin/centos7/run.sh index 2000cf1c..3b89b151 100755 --- a/phppgadmin/centos7/run.sh +++ b/phppgadmin/centos7/run.sh @@ -13,7 +13,7 @@ POSTGRESQL_SERVER=${POSTGRESQL_SERVER:-"localhost"} sed -i "s/conf\['servers'\]\[0\]\['host'\] = '.*'/conf\['servers'\]\[0\]\['host'\] = '${POSTGRESQL_SERVER}'/g" ${PHP_PG_ADMIN_CONFIG}; if [ $1 == "phppgadmin" ]; then - exec /usr/sbin/httpd -DFOREGROUND; + /usr/sbin/httpd && tail -f /var/log/httpd/*; else exec $1 fi From cf0068e768957c59a9345091f90ffc0cbfaad41e Mon Sep 17 00:00:00 2001 From: mohammedzee1000 Date: Fri, 21 Apr 2017 19:39:47 +0530 Subject: [PATCH 6/6] Updated config to show logs on stdout and stderr. --- phppgadmin/centos7/install.sh | 2 ++ phppgadmin/centos7/run.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/phppgadmin/centos7/install.sh b/phppgadmin/centos7/install.sh index 67e91a5d..174a063a 100755 --- a/phppgadmin/centos7/install.sh +++ b/phppgadmin/centos7/install.sh @@ -16,6 +16,8 @@ rm -rf ${HTTPD_WELCOME}; sed -i 's/^Listen 80/Listen 8080\\\nListen 8443/g' ${HTTPD_CONF}; sed -i 's/^Listen 8080\\/Listen 8080/g' ${HTTPD_CONF}; sed -i 's/^Group apache/Group root/g' ${HTTPD_CONF}; +sed -i 's/logs\/error_log/\/dev\/stderr/g' ${HTTPD_CONF}; +sed -i 's/logs\/access_log/\/dev\/stdout/g' ${HTTPD_CONF}; mkdir -p /etc/httpd/logs && touch /etc/httpd/logs/error_log && touch /etc/httpd/logs/access_log; cat >${PHP_PGADMIN_HTTPD_CONF} <