Giter Site home page Giter Site logo

jetty-runtime's Introduction

Google Cloud Platform Jetty Docker Image

This repository contains the source for the gcr.io/google-appengine/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.

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.

Building the Jetty image

To build the image you need git, docker and maven installed:

git clone https://github.com/GoogleCloudPlatform/jetty-runtime.git
cd jetty-runtime
mvn clean install

Running the Jetty image

The resulting image is called jetty (with more specific tags also created) and can be run with:

docker run jetty

Google Modules & Configuration

The jetty base in this image has some additional google specific modules:

Module Description enabled
gae enables JSON formatted server logging; enables request log; true

The $JETTY_BASE/resources/jetty-logging.properties file configures the jetty logging mechanism to use java.util.logging'. This is configured using $JETTY_BASE/etc/java-util-logging.propertieswhich set a JSON formatter for logging to/var/log/app_engine/app.%g.log.json`.

The request log also defaults to log into /var/log/app_engine/ by the gae module

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:

docker run jetty --list-config

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

docker run -it --rm jetty bash

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

WORKDIR $JETTY_BASE
RUN 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.

App Engine Flexible Environment

This image works with App Engine Flexible Environment as a custom runtime. In order to use it, you need to build the image (let's call it YOUR_BUILT_IMAGE), (and optionally push it to a Docker registery like gcr.io). Then, you can add to any pure Java EE 7 Web Application projects these 2 configuration files next to the exploded WAR directory:

Dockerfile file would be:

  FROM YOUR_BUILT_IMAGE
  add . /app

That will add the Web App Archive directory in the correct location for the Docker container.

Then, an app.yaml file to configure the App Engine Flexible Environment product:

  runtime: custom
  vm: true

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

 gcloud app deploy app.yaml

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 appends to the setup-env.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 set including:

Env Var Maven Prop Value
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_ARGS -Djetty.base=$JETTY_BASE -jar $JETTY_HOME/start.jar
ROOT_WAR $JETTY_BASE/webapps/root.war
ROOT_DIR $JETTY_BASE/webapps/root
JAVA_OPTS $JAVA_OPTS $JETTY_ARGS

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 $JAVA_OPTS \
     -Djetty.base=$JETTY_BASE \
     -jar $JETTY_HOME/start.jar \
     "$@"

The configuration of the jetty container in this image can be viewed by running the image locally:

docker run --rm -it jetty:9.4 --list-config --list-modules

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 verion of this image is available at gcr.io/google-appengine/jetty, alternately you may build and push your own version with the shell commands:

mvn clean install
docker tag jetty:latest gcr.io/your-project-name/jetty:your-label
gcloud 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:

FROM gcr.io/google-appengine/jetty
COPY your-application.war $JETTY_BASE/webapps/root.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:

FROM gcr.io/google-appengine/jetty
COPY 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:

docker run -v /some-path/your-application:/app gcr.io/google-appengine/jetty  

Contributing changes

Licensing

jetty-runtime's People

Contributors

ajkannan avatar aozarov avatar chanseokoh avatar gregw avatar hegemonic avatar janbartel avatar jboynes avatar jmcc0nn3ll avatar joakime avatar ludoch avatar meltsufin avatar rauls5382 avatar walkerwatch avatar yubin154 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.