diff --git a/.gitignore b/.gitignore index 1034d0286..3396e4bac 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ .idea .vscode /dist +/docker-build /mac-build /pip-build /src-build diff --git a/Makefile b/Makefile index 877324879..30a7ef6ed 100644 --- a/Makefile +++ b/Makefile @@ -47,11 +47,14 @@ check-js: install-node linter cd web && yarn run karma start -- --single-run # Include all clean sub-targets in clean -clean: clean-appbundle clean-dist clean-docs clean-pip clean-src +clean: clean-appbundle clean-docker clean-dist clean-docs clean-pip clean-src clean-appbundle: rm -rf mac-build/ +clean-docker: + rm -rf docker-build/ + clean-dist: rm -rf dist/ @@ -64,6 +67,9 @@ clean-pip: clean-src: rm -rf src-build/ +docker: + ./pkg/docker/build.sh + docs: LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 $(MAKE) -C docs/en_US -f Makefile.sphinx html diff --git a/pkg/docker/Dockerfile b/pkg/docker/Dockerfile new file mode 100644 index 000000000..86a79ad48 --- /dev/null +++ b/pkg/docker/Dockerfile @@ -0,0 +1,48 @@ +######################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2017, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +######################################################################### + +# Get the basics out of the way +FROM centos:latest + +LABEL name="pgAdmin 4" \ + vendor="The pgAdmin Development Team" \ + license="PostgreSQL" + +# We only need the web/ directory, and a few other things +COPY web /var/www/pgadmin +COPY requirements.txt /var/www/pgadmin + +# Install everything we need. Use easy_install to get pip, to avoid setting up EPEL +RUN yum install -y python-setuptools python-devel httpd mod_wsgi gcc +RUN easy_install pip + +# Now install the Python runtime dependencies +RUN pip install -r /var/www/pgadmin/requirements.txt + +# Create required directories for running +RUN mkdir -p /var/log/pgadmin +RUN chown -R apache /var/log/pgadmin +RUN mkdir -p /var/lib/pgadmin +RUN chown -R apache /var/lib/pgadmin + +# Apache config time +COPY pgadmin4.conf /etc/httpd/conf.d/ +COPY entry.sh / + +# Finally, remove packages we only needed for building +RUN yum -y remove gcc cpp glibc-devel glibc-headers kernel-headers libgomp libmpc mpfr + +# Default config options +ENV PGADMIN_DEFAULT_EMAIL container@pgadmin.org +ENV PGADMIN_DEFAULT_PASSWORD Conta1ner + +EXPOSE 80 443 + +# Start the service +ENTRYPOINT ["/bin/bash", "/entry.sh"] diff --git a/pkg/docker/build.sh b/pkg/docker/build.sh new file mode 100755 index 000000000..ca8d631f5 --- /dev/null +++ b/pkg/docker/build.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +######################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2017, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +######################################################################### + +# Runtime checks +if [ ! -d runtime -a ! -d web ]; then + echo This script must be run from the top-level directory of the source tree. + exit 1 +fi + +if [ ! -d .git -a ! -f .git/config ]; then + echo This script must be run from a git checkout of the source tree. + exit 1 +fi + +# Get the required package info +APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'` +APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'` +APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //'` +APP_LONG_VERSION=$APP_RELEASE.$APP_REVISION +APP_SHORT_VERSION=`echo $APP_LONG_VERSION | cut -d . -f1,2` +APP_SUFFIX=`grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g"` +if [ ! -z $APP_SUFFIX ]; then + export APP_LONG_VERSION=$APP_LONG_VERSION-$APP_SUFFIX +fi +CONTAINER_NAME=`echo $APP_NAME | sed 's/ //g' | awk '{print tolower($0)}'` + +# Output basic details to show we're working +echo Building Docker Container for $APP_NAME version $APP_LONG_VERSION... + +# Create/clearout the build directory +echo Creating/cleaning required directories... +if [ -d docker-build ]; then + rm -rf docker-build +fi + +mkdir docker-build + +# Create the output directory if not present +if [ ! -d dist ]; then + mkdir dist +fi + +# Build the clean tree +for FILE in `git ls-files web` +do + echo Adding $FILE + # We use tar here to preserve the path, as Mac (for example) doesn't support cp --parents + tar cf - $FILE | (cd docker-build; tar xf -) +done + +pushd web + yarn install + yarn run bundle + + for FILE in `ls -d pgAdmin/static/js/generated/*` + do + echo Adding $FILE + tar cf - $FILE | (cd ../docker-build/web; tar xf -) + done +popd + +# Build the docs +if [ -d docs/en_US/_build/html ]; then + rm -rf docs/en_US/_build/html +fi + +LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 make -C docs/en_US -f Makefile.sphinx html + +mkdir docker-build/web/docs +cp -R docs/en_US/_build/html/* docker-build/web/docs/ + +# Configure pgAdmin +echo "HELP_PATH = '../../docs/'" >> docker-build/web/config_distro.py +echo "DEFAULT_BINARY_PATHS = {" >> docker-build/web/config_distro.py +echo " 'pg': ''," >> docker-build/web/config_distro.py +echo " 'ppas': ''," >> docker-build/web/config_distro.py +echo " 'gpdb': ''" >> docker-build/web/config_distro.py +echo "}" >> docker-build/web/config_distro.py + +# Copy the Docker specific assets into place +cp pkg/docker/Dockerfile docker-build/ +cp pkg/docker/entry.sh docker-build/ +cp pkg/docker/pgadmin4.conf docker-build/ +cp requirements.txt docker-build/ + +# Build the container +docker build docker-build -t $CONTAINER_NAME \ + -t $CONTAINER_NAME:latest \ + -t $CONTAINER_NAME:$APP_RELEASE \ + -t $CONTAINER_NAME:$APP_LONG_VERSION \ No newline at end of file diff --git a/pkg/docker/entry.sh b/pkg/docker/entry.sh new file mode 100644 index 000000000..b5e6b5c37 --- /dev/null +++ b/pkg/docker/entry.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +######################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2017, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +######################################################################### + +export PGADMIN_SETUP_EMAIL=${PGADMIN_DEFAULT_EMAIL} +export PGADMIN_SETUP_PASSWORD=${PGADMIN_DEFAULT_PASSWORD} + +/usr/sbin/httpd -D FOREGROUND \ No newline at end of file diff --git a/pkg/docker/pgadmin4.conf b/pkg/docker/pgadmin4.conf new file mode 100644 index 000000000..ddd518875 --- /dev/null +++ b/pkg/docker/pgadmin4.conf @@ -0,0 +1,22 @@ +######################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2017, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +######################################################################### + +ServerName pgadmin4 + + + WSGIDaemonProcess pgadmin processes=1 threads=25 + WSGIScriptAlias / /var/www/pgadmin/pgAdmin4.wsgi + + + WSGIProcessGroup pgadmin + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + \ No newline at end of file