GoogleCloudPlatform/jetty-runtime

Name: jetty-runtime

Owner: Google Cloud Platform

Description: Google Cloud Platform Jetty Docker image

Created: 2016-08-18 17:14:04.0

Updated: 2018-05-17 20:27:04.0

Pushed: 2018-05-17 20:55:55.0

Homepage:

Size: 6108

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Google Cloud Platform Jetty Docker Image

This repository contains the source for the Google-maintained Jetty docker image. This image can be used as the base image for running Java web applications on Google App Engine Flexible Environment and Google Container Engine. It provides the Jetty Servlet container on top of the OpenJDK image.

This image is mirrored at both launcher.gcr.io/google/jetty and gcr.io/google-appengine/jetty.

The layout of this image is intended to mostly mimic the official docker-jetty image and unless otherwise noted, the official docker-jetty documentation should apply.

Configuring the Jetty image

Arguments passed to the docker run command are passed to Jetty, so the configuration of the jetty server can be seen with a command like:

er run gcr.io/google-appengine/jetty --list-config

Alternate commands can also be passed to the docker run command, so the image can be explored with

er run -it --rm launcher.gcr.io/google/jetty bash

Various environment variables (see below) can also be used to set jetty properties, enable modules and disable modules. These variables may be set either in an app.yaml or passed in to a docker run command eg.

er run -it --rm -e JETTY_PROPERTIES=jetty.http.idleTimeout=10000 launcher.gcr.io/google/jetty 

To update the server configuration in a derived Docker image, the Dockerfile may enable additional modules with RUN commands like:

DIR $JETTY_BASE
java -jar "$JETTY_HOME/start.jar" --add-to-startd=jmx,stats

Modules may be configured in a Dockerfile by editing the properties in the corresponding mod files in /var/lib/jetty/start.d/ or the module can be deactivated by removing that file.

Enabling gzip compression

The gzip handler is bundled with Jetty but not activated by default. To activate this module you have to set the environment variable JETTY_MODULES_ENABLE=gzip

For example with docker:

er run -p 8080 -e JETTY_MODULES_ENABLE=gzip gcr.io/yourproject/yourimage

Or with GAE (app.yaml):

variables:
TTY_MODULES_ENABLE: 'gzip'
Using Quickstart

Jetty provides mechanisms to speed up the start time of your application by pre-scanning its content and generating configuration files. If you are using an extended image you can active quickstart by executing /scripts/jetty/quickstart.sh in your Dockerfile, after the application WAR is added.

 launcher.gcr.io/google/jetty
your-application.war $JETTY_BASE/webapps/root.war

nerate quickstart-web.xml
/scripts/jetty/quickstart.sh
App Engine Flexible Environment

When using App Engine Flexible, you can use the runtime without worrying about Docker by specifying runtime: java in your app.yaml:

ime: java
 flex

The runtime image launcher.gcr.io/google/jetty will be automatically selected if you are attempting to deploy a WAR (*.war file).

If you want to use the image as a base for a custom runtime, you can specify runtime: custom in your app.yaml and then write the Dockerfile like this:

 launcher.gcr.io/google/jetty
your-application.war $APP_DESTINATION_WAR

That will add the WAR in the correct location for the Docker container.

You can also use exploded-war artifacts:

your-application $APP_DESTINATION_EXPLODED_WAR

Once you have this configuration, you can use the Google Cloud SDK to deploy this directory containing the 2 configuration files and the WAR using:

ud app deploy app.yaml
Container Engine & other Docker hosts

For other Docker hosts, you'll need to create a Dockerfile based on this image that copies your application code and installs dependencies. For example:

 launcher.gcr.io/google/jetty
 your-application.war $APP_DESTINATION_WAR

If your artifact is an exploded-war, then use the APP_DESTINATION_EXPLODED_WAR environment variable instead. You can then build the docker container using docker build or Google Cloud Container Builder. By default, the CMD is set to start the Jetty server. You can change this by specifying your own CMD or ENTRYPOINT.

Entry Point Features

The /docker-entrypoint.bash for the image is inherited from the openjdk-runtime and its capabilities are described in the associated README

This image updates the docker CMD and adds the /setup-env.d/50-jetty.bash script to include options and arguments to run the Jetty container, unless an executable argument is passed to the docker image. Additional environment variables are used/set including:

|Env Var | Maven Prop | Value/Comment | |——————|—————–|——————————————————| |JETTY_VERSION |jetty9.version | | |GAE_IMAGE_NAME | |jetty | |GAE_IMAGE_LABEL |docker.tag.long| | |JETTY_HOME |jetty.home |/opt/jetty-home | |JETTY_BASE |jetty.base |/var/lib/jetty | |TMPDIR | |/tmp/jetty | |JETTY_PROPERTIES| |Comma separated list of name=value pairs appended to $JETTY_ARGS | |JETTY_MODULES_ENABLE| |Comma separated list of modules to enable by appending to $JETTY_ARGS | |JETTY_MODULES_DISABLE| |Comma separated list of modules to disable by removing from $JETTY_BASE/start.d | |JETTY_ARGS | |Arguments passed to jetty's start.jar. Any arguments used for custom jetty configuration should be passed here. | |ROOT_WAR | |$JETTY_BASE/webapps/root.war | |ROOT_DIR | |$JETTY_BASE/webapps/root | |JAVA_OPTS | |JVM runtime arguments |

If a WAR file is found at $ROOT_WAR, it is unpacked to $ROOT_DIR if it is newer than the directory or the directory does not exist. If there is no $ROOT_WAR or $ROOT_DIR, then /app is symbolic linked to $ROOT_DIR. If a $ROOT_DIR is discovered or made by this script, then it is set as the working directory. See Extending the image below for some examples of adding an application as a WAR file or directory.

The command line executed is effectively (where $@ are the args passed into the docker entry point):

 $JAVA_OPTS \
 -Djetty.base=$JETTY_BASE \
 -jar $JETTY_HOME/start.jar \
 "$@"
Logging

This image is configured to use Java Util Logging(JUL) to capture all logging from the container and its dependencies. Applications that also use the JUL API will inherit the same logging configuration.

By default JUL is configured to use a ConsoleHandler to send logs to the stderr of the container process. When run on as a GCP deployment, all output to stderr is captured and is available via the Stackdriver logging console, however more detailed and integrated logs are available if the Stackdriver logging mechanism is used directly (see below).

To alter logging configuration a new logging.properties file must be provided to the image that among other things can: alter log levels generated by Loggers; alter log levels accepted by handlers; add/remove/configure log handlers.

Providing logging.properties via the web application

A new logging configuration file can be provided as part of the application (typically at WEB-INF/logging.properties) and the Java System Property java.util.logging.config.file updated to reference it.

When running in a GCP environment, the system property can be set in app.yaml:

variables:
TTY_ARGS: -Djava.util.logging.config.file=WEB-INF/logging.properties

If the image is run directly, then a -e argument to the docker run command can be used to set the system property:

er run \
 JETTY_ARGS=-Djava.util.logging.config.file=WEB-INF/logging.properties \
.
Providing logging.properties via a custom image

If this image is being used as the base of a custom image, then the following Dockerfile commands can be used to add either replace the existing logging configuration file or to add a new logging.properties file.

The default logging configuration file is located at /var/lib/jetty/etc/java-util-logging.properties, which can be replaced in a custom image is built. The default configuration can be replaced with a Dockerfile like:

 gcr.io/google-appengine/jetty
logging.properties /var/lib/jetty/etc/java-util-logging.properties

Alternately an entirely new location for the file can be provided and the environment amended in a Dockerfile like:

 gcr.io/google-appengine/jetty
logging.properties /etc/logging.properties
JETTY_ARGS -Djava.util.logging.config.file=/etc/logging.properties

Providing logging.properties via docker run

A logging.properties file may be added to an existing images using the docker run command if the deployment environment allows for the run arguments to be modified. The -v option can be used to bind a new logging.properties file to the running instance and the -e option can be used to set the system property to point to it:

er run -it --rm \
mylocaldir/logging.properties:/etc/logging.properties \
ETTY_ARGS="-Djava.util.logging.config.file=/etc/logging.properties" \

Enhanced Stackdriver Logging (BETA)

When running on the Google Cloud Platform Flex environment, the Java Util Logging can be configured to send logs to Google Stackdriver Logging by providing a logging.properties file that configures a LoggingHandler as follows:

lers=com.google.cloud.logging.LoggingHandler

tional configuration
el=INFO
google.cloud.logging.LoggingHandler.level=FINE
google.cloud.logging.LoggingHandler.log=gae_app.log
google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s

When deployed on the GCP Flex environment, an image so configured will automatically be configured with:

When deployed in other environments, logging enhancers can be manually configured by setting a comma separated list of class names as the com.google.cloud.logging.LoggingHandler.enhancers property.

When using Stackdriver logging, it is recommended that io.grpc and sun.net logging level is kept at INFO level, as both these packages are used by Stackdriver internals and can result in verbose and/or initialisation problems.

Distributed Session Storage (BETA)

This image can be configured to use Google Cloud Datastore for clustered session storage by enabling the gcp-datastore-sessions jetty module. You can do this in your app.yaml:

variables:
TTY_MODULES_ENABLE: gcp-datastore-sessions

Jetty will use the default namespace in Datastore, but you can also choose a namespace to use by using the jetty.session.gcloud.namespace property.

Extending the image

The image produced by this project may be automatically used/extended by the Cloud SDK and/or App Engine maven plugin. Alternately it may be explicitly extended with a custom Dockerfile.

The latest released version of this image is available at launcher.gcr.io/google/jetty, alternately you may build and push your own version with the shell commands:

clean install
er tag jetty:latest gcr.io/your-project-name/jetty:your-label
ud docker -- push gcr.io/your-project-name/jetty:your-label
Adding the root WAR application to an image

A standard war file may be deployed as the root context in an extended image by placing the war file in the docker build directory and using a Dockerfile like:

 launcher.gcr.io/google/jetty
 your-application.war $APP_DESTINATION_WAR

An exploded-war can also be used:

 your-application $APP_DESTINATION_EXPLODED_WAR
Adding the root application to an image

If the application exists as directory (i.e. an expanded war file), then directory must be placed in the docker build directory and using a Dockerfile like:

 launcher.gcr.io/google/jetty
 your-application-dir $JETTY_BASE/webapps/root
Mounting the root application at local runtime

If no root WAR or root directory is found, the docker-entrypoint.bash script will link the /app directory as the root application. Thus the root application can be added to the image via a runtime mount:

er run -v /some-path/your-application:/app launcher.gcr.io/google/jetty  
Enabling dry-run

The image's default start command will first run the jetty start.jar as a –dry-run to generate the JVM start command before starting the jetty web server. If you wish to generate the start command in your Dockerfile rather than at container start-time, you can run the /scripts/jetty/generate-jetty-start.sh script to generate it for you, i.e.

/scripts/jetty/generate-jetty-start.sh

NOTE: Make sure that the web application and any additional custom jetty modules have been added to the container BEFORE running this script.

Development Guide

Contributing changes

Licensing

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.