From a5daf6173b081ccea7501033cedbcedff02b5c75 Mon Sep 17 00:00:00 2001
From: Tim Sutton <tim@kartoza.com>
Date: Wed, 16 Mar 2016 03:38:58 +0800
Subject: [PATCH] Merge pull request #4 from shane-axiom/master

---
 resources/overlays/README.txt |   14 +++
 Dockerfile                    |  103 ++++++++++++++++++++++---
 /dev/null                     |   16 ----
 .gitignore                    |    8 +
 resources/plugins/README.txt  |    2 
 build.sh                      |    4 -
 README.md                     |   61 ++++++++++++++
 7 files changed, 173 insertions(+), 35 deletions(-)

diff --git a/.gitignore b/.gitignore
index 51a5941..245321d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,8 @@
-resources/geoserver.zip
+resources/*
+!resources/plugins/
+resources/plugins/*
+!resources/plugins/README.txt
+!resources/overlays/
+resources/overlays/*
+!resources/overlays/README.txt
 .idea
diff --git a/Dockerfile b/Dockerfile
index 9c8243b..c2a94bc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,19 +16,98 @@
 
 #-------------Application Specific Stuff ----------------------------------------------------
 
-RUN apt-get -y install unzip openjdk-7-jre-headless openjdk-7-jre
+ENV GS_VERSION 2.6.1
+ENV GEOSERVER_DATA_DIR /opt/geoserver/data_dir
+
+# Unset Java related ENVs since they may change with Oracle JDK
+ENV JAVA_VERSION=
+ENV JAVA_DEBIAN_VERSION=
+
+# Set JAVA_HOME to /usr/lib/jvm/default-java and link it to OpenJDK installation
+RUN ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/lib/jvm/default-java
+ENV JAVA_HOME /usr/lib/jvm/default-java
 
 ADD resources /tmp/resources
 
-# A little logic that will fetch the geoserver zip file if it
-# is not available locally in the resources dir and
-RUN if [ ! -f /tmp/resources/geoserver.zip ]; then \
-    wget -c http://downloads.sourceforge.net/project/geoserver/GeoServer/2.6.1/geoserver-2.6.1-bin.zip -O /tmp/resources/geoserver.zip; \
-    fi; \
-    unzip /tmp/resources/geoserver.zip -d /opt && mv -v /opt/geoserver* /opt/geoserver
-ENV GEOSERVER_HOME /opt/geoserver
-ENV JAVA_HOME /usr/
+# If a matching Oracle JDK tar.gz exists in /tmp/resources, move it to /var/cache/oracle-jdk7-installer
+# where oracle-java7-installer will detect it
+RUN if ls /tmp/resources/*jdk-*-linux-x64.tar.gz > /dev/null 2>&1; then \
+      mkdir /var/cache/oracle-jdk7-installer && \
+      mv /tmp/resources/*jdk-*-linux-x64.tar.gz /var/cache/oracle-jdk7-installer/; \
+    fi;
 
-#ENTRYPOINT "/opt/geoserver/bin/startup.sh"
-CMD "/opt/geoserver/bin/startup.sh"
-EXPOSE 8080
+# Install Oracle JDK (and uninstall OpenJDK JRE) if the build-arg ORACLE_JDK = true or an Oracle tar.gz
+# was found in /tmp/resources
+ARG ORACLE_JDK=false
+RUN if ls /var/cache/oracle-jdk7-installer/*jdk-*-linux-x64.tar.gz > /dev/null 2>&1 || [ "$ORACLE_JDK" = true ]; then \
+       apt-get autoremove --purge -y openjdk-7-jre-headless && \
+       echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true \
+         | debconf-set-selections && \
+       echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" \
+         > /etc/apt/sources.list.d/webupd8team-java.list && \
+       apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \
+       apt-get update && \
+       apt-get install -y oracle-java7-installer oracle-java7-set-default && \
+       ln -s --force /usr/lib/jvm/java-7-oracle /usr/lib/jvm/default-java && \
+       rm -rf /var/lib/apt/lists/* && \
+       rm -rf /var/cache/oracle-jdk7-installer; \
+       if [ -f /tmp/resources/jce_policy.zip ]; then \
+         unzip -j /tmp/resources/jce_policy.zip -d /tmp/jce_policy && \
+         mv /tmp/jce_policy/*.jar $JAVA_HOME/jre/lib/security/; \
+       fi; \
+    fi;
+
+#Add JAI and ImageIO for great speedy speed.
+WORKDIR /tmp
+RUN wget http://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib-linux-amd64.tar.gz && \
+    wget http://download.java.net/media/jai-imageio/builds/release/1.1/jai_imageio-1_1-lib-linux-amd64.tar.gz && \
+    gunzip -c jai-1_1_3-lib-linux-amd64.tar.gz | tar xf - && \
+    gunzip -c jai_imageio-1_1-lib-linux-amd64.tar.gz | tar xf - && \
+    mv /tmp/jai-1_1_3/lib/*.jar $JAVA_HOME/jre/lib/ext/ && \
+    mv /tmp/jai-1_1_3/lib/*.so $JAVA_HOME/jre/lib/amd64/ && \
+    mv /tmp/jai_imageio-1_1/lib/*.jar $JAVA_HOME/jre/lib/ext/ && \
+    mv /tmp/jai_imageio-1_1/lib/*.so $JAVA_HOME/jre/lib/amd64/ && \
+    rm /tmp/jai-1_1_3-lib-linux-amd64.tar.gz && \
+    rm -r /tmp/jai-1_1_3 && \
+    rm /tmp/jai_imageio-1_1-lib-linux-amd64.tar.gz && \
+    rm -r /tmp/jai_imageio-1_1
+WORKDIR $CATALINA_HOME
+
+# A little logic that will fetch the geoserver war zip file if it
+# is not available locally in the resources dir
+RUN if [ ! -f /tmp/resources/geoserver.zip ]; then \
+    wget -c http://downloads.sourceforge.net/project/geoserver/GeoServer/${GS_VERSION}/geoserver-${GS_VERSION}-war.zip \
+      -O /tmp/resources/geoserver.zip; \
+    fi; \
+    unzip /tmp/resources/geoserver.zip -d /tmp/geoserver \
+    && unzip /tmp/geoserver/geoserver.war -d $CATALINA_HOME/webapps/geoserver \
+    && rm -rf $CATALINA_HOME/webapps/geoserver/data \
+    && rm -rf /tmp/geoserver
+
+# Install any plugin zip files in resources/plugins
+RUN if ls /tmp/resources/plugins/*.zip > /dev/null 2>&1; then \
+      for p in /tmp/resources/plugins/*.zip; do \
+        unzip $p -d /tmp/gs_plugin \
+        && mv /tmp/gs_plugin/*.jar $CATALINA_HOME/webapps/geoserver/WEB-INF/lib/ \
+        && rm -rf /tmp/gs_plugin; \
+      done; \
+    fi
+
+# Overlay files and directories in resources/overlays if they exist
+RUN rm /tmp/resources/overlays/README.txt && \
+    if ls /tmp/resources/overlays/* > /dev/null 2>&1; then \
+      cp -rf /tmp/resources/overlays/* /; \
+    fi;
+
+# Optionally remove Tomcat manager, docs, and examples
+ARG TOMCAT_EXTRAS=true
+RUN if [ "$TOMCAT_EXTRAS" = false ]; then \
+    rm -rf $CATALINA_HOME/webapps/ROOT && \
+    rm -rf $CATALINA_HOME/webapps/docs && \
+    rm -rf $CATALINA_HOME/webapps/examples && \
+    rm -rf $CATALINA_HOME/webapps/host-manager && \
+    rm -rf $CATALINA_HOME/webapps/manager; \
+  fi;
+
+# Delete resources after installation
+RUN rm -rf /tmp/resources
diff --git a/README.md b/README.md
index c340570..9f5c611 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,49 @@
 docker build -t kartoza/postgis .
 ```
 
+### Building with Oracle JDK
+
+To replace OpenJDK Java with the Oracle JDK, set build-arg `ORACLE_JDK=true`:
+
+```shell
+docker build --build-arg ORACLE_JDK=true -t kartoza/postgis .
+```
+
+Alternatively, you can download the Oracle JDK 7 Linux x64 tar.gz currently in use by
+[webupd8team's Oracle JDK installer](https://launchpad.net/~webupd8team/+archive/ubuntu/java/+packages)
+(usually the latest version available from Oracle) and place it in `resources` before building.
+
+To enable strong cryptography when using the Oracle JDK (recommended), download the
+[Oracle Java policy jar zip](http://docs.geoserver.org/latest/en/user/production/java.html#oracle-java)
+for the correct JDK version and place it at `resources/jce_policy.zip` before building.
+
+### Building with plugins
+
+To build a GeoServer image with plugins (e.g. SQL Server plugin, Excel output plugin),
+download the plugin zip files from the GeoServer download page and put them in
+`resources/plugins` before building. You should also download the matching version
+GeoServer WAR zip file to `resources/geoserver.zip`.
+
+### Removing Tomcat extras during build
+
+To remove Tomcat extras including docs, examples, and the manager webapp, set the
+`TOMCAT_EXTRAS` build-arg to `false`:
+
+```shell
+docker build --build-arg TOMCAT_EXTRAS=false -t kartoza/postgis .
+```
+
+### Building with file system overlays (advanced)
+
+The contents of `resources/overlays` will be copied to the image file system
+during the build. For example, to include a static Tomcat `setenv.sh`,
+create the file at `resources/overlays/usr/local/tomcat/bin/setenv.sh`.
+
+You can use this functionality to write a static GeoServer directory to
+`/opt/geoserver/data_dir`, include additional jar files, and more.
+
+Overlay files will overwrite existing destination files, so be careful!
+
 ## Run
 
 You probably want to also have postgis running too. To create a running 
@@ -76,12 +119,26 @@
 docker run -d -v $HOME/geoserver_data:/opt/geoserver/data_dir kartoza/geserver
 ```
 
-You need to ensure the ``geoserver_data`` directory has sufficinet permissions
+You need to ensure the ``geoserver_data`` directory has sufficient permissions
 for the docker process to read / write it.
 
+## Setting Tomcat properties
 
+To set Tomcat properties such as maximum heap memory size, create a `setenv.sh` file such as:
+
+```shell
+JAVA_OPTS="$JAVA_OPTS -Xmx1536M -XX:MaxPermSize=756M"
+JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled"
+```
+
+Then pass the `setenv.sh` file as a volume at `/usr/local/tomcat/bin/setenv.sh` when running:
+
+```shell
+docker run -d -v $HOME/setenv.sh:/usr/local/tomcat/bin/setenv.sh kartoza/geserver
+```
 
 ## Credits
 
 Tim Sutton (tim@kartoza.com)
-May 2014
+Shane St Clair (shane@axiomdatascience.com)
+Alex Leith (alexgleith@gmail.com)
diff --git a/build.sh b/build.sh
index 998aa0e..8c7cff9 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,3 @@
 #!/bin/sh
 
-if [ ! -f resources/geoserver.zip ]
-then
-    wget -c http://downloads.sourceforge.net/project/geoserver/GeoServer/2.5.2/geoserver-2.5.2-bin.zip -O resources/geoserver.zip
-fi
 docker build -t kartoza/geoserver .
diff --git a/resources/overlays/README.txt b/resources/overlays/README.txt
new file mode 100644
index 0000000..4699e93
--- /dev/null
+++ b/resources/overlays/README.txt
@@ -0,0 +1,14 @@
+To include files in the container file system at arbitrary locations, build
+a directory structure from / here and include the files at the desired location.
+
+For example, to include a static Tomcat setenv.sh in the build, place it at:
+
+resources/overlays/usr/local/tomcat/bin/setenv.sh
+
+Other overlay examples include static GeoServer data directories, the Marlin renderer, etc.
+
+Note that overlay files will overwrite existing destination files, and that
+files in the overlay root will be copied to the container root
+(e.g. resources/overlay/somefile.txt will be copied to /somefile.txt).
+
+Be careful!
diff --git a/resources/plugins/README.txt b/resources/plugins/README.txt
new file mode 100644
index 0000000..aa8b33c
--- /dev/null
+++ b/resources/plugins/README.txt
@@ -0,0 +1,2 @@
+Download plugin zips and place them here when building to include them in
+the container's GeoServer deployment.
diff --git a/setup.sh b/setup.sh
deleted file mode 100755
index e69de29..0000000
--- a/setup.sh
+++ /dev/null
diff --git a/sshd.conf b/sshd.conf
deleted file mode 100644
index dc167f4..0000000
--- a/sshd.conf
+++ /dev/null
@@ -1,5 +0,0 @@
-[program:sshd]
-user=root
-command=/usr/sbin/sshd -D
-autorestart=true
-stopsignal=INT
diff --git a/start.sh b/start.sh
deleted file mode 100644
index c5be777..0000000
--- a/start.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-# Put any tasks you would like to have carried
-# out when the container is first created here
-
-# Set the root passwd - grep docker logs for it
-ROOT_PASSWORD=`pwgen -c -n -1 12`
-echo "root:$ROOT_PASSWORD" | chpasswd
-echo "root login password: $ROOT_PASSWORD"
-
-# Also echo out the pg password written to
-# /PGPASSWORD.txt when the image was made
-# by start-postgres.sh
-
-# Launch supervisor
-supervisord -n

--
Gitblit v0.0.0-SNAPSHOT