From a49f755b22d0a15db634e13c330d49dc0e75674a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstr=C3=B6m?= <erik@hedenstroem.com> Date: Thu, 7 Aug 2014 14:08:49 +0200 Subject: [PATCH] Working jetty docker image --- Dockerfile | 3 +- README.md | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ init.sh | 20 +++++++---- 3 files changed, 118 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index d85a668..8938fd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,7 +49,6 @@ RUN \ # Default Environment ENV JETTY_VERSION 9.2.2.v20140723 -ENV CARGO_VERSION 1.4.9 # Add startup script ADD init.sh /init.sh @@ -57,5 +56,5 @@ ADD init.sh /init.sh # Expose ports EXPOSE 25 3306 8080 -# Start Jetty +# Start JIRA CMD ["sh", "/init.sh"] diff --git a/README.md b/README.md index 9b2aa23..7ed6119 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,107 @@ ``` docker build --rm -t registry.codemate.se/jetty . ``` + +## Usage + +It's as simple as: + +``` +docker pull registry.codemate.se/jetty +docker run -d registry.codemate.se/jetty +``` + +### Customize exposed port + +By default, the port `8080` (jetty) is mapped to a random port on the docker host. To customize, run: + +``` +docker run -p 8080:8080 -d registry.codemate.se/jetty +``` + +More info about port redirection can be found in the official Docker [documentation](http://docs.docker.io/en/latest/use/port_redirection/). + +### Persist application data on the docker host + +Jetty is configured to scan /opt/app/webapps when starting. To persist data to the docker host simply map a host directory to /opt/app. In the host directory create a webapps folder where place war, xml, or exploded webapps. + +MySQL is configured to store data files in '/opt/app/mysql-data' which will also cause it to be persisted to the host. + +``` +docker run -v /data/jetty-demo-app:/opt/app -d registry.codemate.se/jetty +``` + +### Running a different Jetty version + +By default, the container downloads and installs Jetty 9.2.2.v20140723 on the first boot. To specify which version to install, set the environment variable `JETTY_VERSION`: + +``` +docker run -e JETTY_VERSION=9.2.2.v20140723 -d registry.codemate.se/jetty +``` + +### Overriding Jetty files + +By providing an environment variable name `JETTY_OVERLAY` that points to a directory or URL of a gzipped tar file you can apply an overlay on the Jetty installation. A directory will be recursively copied, and a tarball will be unzipped and extracted in the root of the Jetty installation directory. The overlay enables you to add custom Jetty configurations. + +``` +docker run -e JETTY_OVERLAY=http://10.0.0.1/jetty-config.tgz -d registry.codemate.se/jetty +docker run -e JETTY_OVERLAY=/opt/app/jetty-config -d registry.codemate.se/jetty +``` + +The overlay is fetched using curl so file URLs are valid: + +``` +JETTY_OVERLAY="file:////opt/app/jetty-config,tgz" +``` + +If you need to provide basic auth credentials simply prefix the url with the credentials, for example: + +``` +JETTY_OVERLAY="-u username:password http://10.0.0.1/jetty-config.tgz" +``` + +### Initializing MySQL + +By providing an environment variable name `MYSQL_INIT` that points to an SQL script you initialize the MySQL database. + +``` +docker run -e MYSQL_INIT=http://10.0.0.1/jetty-init.sql -d registry.codemate.se/jetty +``` + +Basic auth credentials and file URLs can be used as mentioned in the overlay section. + +### Combined options + +The following example shows the options we use to start a client site: + +``` +docker run \ + --name ethbutik + -e JAVA_OPTIONS="-javaagent:/opt/app/lib/spring-agent-2.5.6.jar -Djavamonitor.uniqueid=10" \ + -e EXIM=yes \ + -v $DIR:/opt/app \ + -p 8080:8080 \ + -d registry.codemate.se/jetty +``` + + +## Directories + +* `/opt/jetty-distribution-$JETTY_VERSION` - Jetty installation directory +* `/opt/app/webapps` - Directory deployer monitors for webapps +* `/opt/app/mysql-data` - MySQL data. + +## Variables + +* `JETTY_VERSION` - The version to install an run (default `9.2.2.v20140723`) +* `JETTY_OVERLAY` - Jetty installation overlay +* `JAVA_OPTIONS` - Jetty java options +* `MYSQL_INIT` - MySQL init script +* `MYSQL` - yes/no flag to enable MySQL (default is no) +* `EXIM` - yes/no flag to enable Exim (default is no) + +## Exposed ports + +* `25` - Exim SMTP +* `3306` - MySQL +* `8080` - Jetty diff --git a/init.sh b/init.sh index 1dcbb50..c14eee2 100644 --- a/init.sh +++ b/init.sh @@ -4,14 +4,16 @@ set -e # Exit on errors JETTY_DIR=/opt/jetty-distribution-$JETTY_VERSION +WEBAPPS_DIR=/opt/app/webapps +MYSQL_DIR=/opt/app/mysql-data if [ ! -d $JETTY_DIR ]; then curl -s -v -L "http://eclipse.org/downloads/download.php?file=/jetty/$JETTY_VERSION/dist/jetty-distribution-$JETTY_VERSION.tar.gz&r=1" | tar xzf - -C /opt - ln -s $JETTY_DIR /opt/jetty rm -rf /opt/jetty/webapps.demo - curl -s -v -L -o /opt/jetty/webapps/cargo-jetty-7-and-onwards-deployer-$CARGO_VERSION http://repo1.maven.org/maven2/org/codehaus/cargo/cargo-jetty-7-and-onwards-deployer/$CARGO_VERSION/cargo-jetty-7-and-onwards-deployer-$CARGO_VERSION.war useradd jetty -U -s /bin/false - chown -R jetty:jetty /opt/jetty + sed -i -e "s:#\sjetty.deploy.monitoredDirName=webapps:jetty.deploy.monitoredDirName=../app/webapps:" $JETTY_DIR/start.ini + chown -R jetty:jetty $JETTY_DIR + chown -R jetty:jetty ${APP_HOME:-/opt/app} fi @@ -23,9 +25,10 @@ if [ ${JETTY_OVERLAY:+x} ] && [ -d $JETTY_DIR ]; then fi fi -if [ "${START_MYSQL:-no}" = "yes" ]; then - sed -i -e "s#^user\s*=\s*mysql#user = root#" /etc/mysql/my.cnf - sed -i -e "s#^datadir\s*=\s*/var/lib/mysql#datadir = $MYSQL_DIR#" /etc/mysql/my.cnf +if [ "${MYSQL:-no}" = "yes" ]; then + sed -i -e "s:^user\s*=\s*mysql:user = root:" /etc/mysql/my.cnf + sed -i -e "s:^datadir\s*=\s*/var/lib/mysql:datadir = $MYSQL_DIR:" /etc/mysql/my.cnf + sed -i -e "s:^log_error:#log_error:" /etc/mysql/my.cnf if [ ! -d $MYSQL_DIR ]; then mkdir -p $MYSQL_DIR mysql_install_db @@ -37,8 +40,11 @@ if [ "${START_MYSQL:-no}" = "yes" ]; then fi fi -if [ "${START_EXIM:-no}" = "yes" ]; then +if [ "${EXIM:-no}" = "yes" ]; then exim4 -v -bdf -q15m & fi env | sort + +cd $JETTY_DIR +exec java ${JAVA_OPTIONS} -jar start.jar $@ -- GitLab