<commit_before># Google Cloud Platform Tomcat Runtime Image

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

This repository contains the source for the Google-maintained Tomcat [docker](https://docker.com) image.

# Using the Tomcat image

Create a `Dockerfile` based on the image and add your application WAR as `ROOT.war` to the current working directory.

```dockerfile
FROM gcr.io/google-appengine/tomcat
COPY your-application.war ROOT.war
```

## Running on App Engine Flexible

### Using the `gcloud beta app deploy` command

Simply choose the Java runtime with Tomcat as the server preference in `app.yaml`.

```yaml
runtime: java
env: flex
runtime_config:
  server: tomcat8
```

Then you can deploy using the `gcloud beta app deploy` [command](https://cloud.google.com/sdk/gcloud/reference/beta/app/deploy). Note that the "beta" command is currently required.

### Using custom Dockerfile

Specify a custom runtime in `app.yaml`.

```yaml
runtime: custom
env: flex
```

Then create a `Dockerfile` that uses the Tomcat runtime image.

```dockerfile
FROM gcr.io/google-appengine/tomcat
COPY your-application.war ROOT.war
```

## Configuration
The Tomcat instance can be configured through the environment variable `TOMCAT_PROPERTIES` which is
a comma-separated list of `name=value` pairs appended to `catalina.properties`.

# Security best practices

## Execute tomcat with a non-root user
For security purposes it is recommended to start the Tomcat instance using the `tomcat` user. 

You can do so by adding `USER tomcat` at the end of your Dockerfile.

```dockerfile
FROM gcr.io/google-appengine/tomcat
COPY your-application.war ROOT.war

RUN chown tomcat:tomcat $CATALINA_BASE/webapps/ROOT.war
USER tomcat
```

# Distributed sessions
This image can be configured to store Tomcat sessions in the [Google Cloud Datastore](https://cloud.google.com/datastore/docs) which allows
multiple instances of Tomcat to share sessions.

You can enable this feature by adding `distributed-sessions` to the list of enabled modules.
For example on Google App Engine:
 
```yaml
env_variables:
  TOMCAT_MODULES_ENABLE: distributed-sessions
```

## Configuration
The distributed sessions module can be configured through the environment variable `TOMCAT_PROPERTIES`.

|  Property | Description  | Default  | 
|---|---|---|
| session.DatastoreStore.namespace    |  Namespace to use in the Datastore.                         |  tomcat-gcp-persistent-session |
| session.DatastoreStore.sessionKind  |  Name of the entity used to store sessions in the Datastore. |  TomcatGCloudSession |
| session.DatastoreStore.sessionMaxInactiveTime |  Defines the maximum time (in seconds) a session can be inactive before being deleted by the expiration process. | 3600 |

## Running outside of Google Cloud
If you are using the runtime outside of Google Cloud, you will want to make sure that your application has access to
the Datastore. In this case, check out the [Google Cloud Authentication](https://developers.google.com/identity/protocols/application-default-credentials) guide.

# Development Guide

* See [instructions](DEVELOPING.md) on how to build and test this image.

## Contributing changes

* See [CONTRIBUTING.md](CONTRIBUTING.md)

# Licensing

* See [LICENSE](LICENSE)<commit_msg>Restructure documentation  (#69)<commit_after># Google Cloud Platform Tomcat Runtime Image

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

This repository contains the source for the Google-maintained Tomcat [docker](https://docker.com) image.

## Using the Tomcat image



### Running on App Engine Flexible

#### Cloud SDK

Simply choose the Java runtime with Tomcat as the server preference in `app.yaml`.

```yaml
runtime: java
env: flex
runtime_config:
  server: tomcat8
```

Then you can deploy using the `gcloud beta app deploy` [command](https://cloud.google.com/sdk/gcloud/reference/beta/app/deploy). Note that the "beta" command is currently required.

#### Using custom Dockerfile

Specify a custom runtime in `app.yaml`.

```yaml
runtime: custom
env: flex
```

Then create a `Dockerfile` that uses the Tomcat runtime image as specified in [Other platforms](#other-platforms).

### Other platforms

Create a `Dockerfile` based on the image and add your application WAR as `ROOT.war` to the current working directory.

```dockerfile
FROM gcr.io/google-appengine/tomcat
COPY your-application.war ROOT.war
```

## Configuring Tomcat

### Tomcat properties
The Tomcat instance can be configured through the environment variable `TOMCAT_PROPERTIES` which is
a comma-separated list of `name=value` pairs appended to `catalina.properties`.

### Security best practices

#### Execute tomcat with a non-root user
For security purposes it is recommended to start the Tomcat instance using the `tomcat` user. 

You can do so by adding `USER tomcat` at the end of your Dockerfile.

```dockerfile
FROM gcr.io/google-appengine/tomcat
COPY your-application.war ROOT.war

RUN chown tomcat:tomcat $CATALINA_BASE/webapps/ROOT.war
USER tomcat
```

## Optional Modules
### Distributed sessions
This image can be configured to store Tomcat sessions in the [Google Cloud Datastore](https://cloud.google.com/datastore/docs) which allows
multiple instances of Tomcat to share sessions.

You can enable this feature by adding `distributed-sessions` to the list of optional modules, which is specified in the `TOMCAT_MODULES_ENABLE` environment variable.

For example on Google App Engine:
 
```yaml
env_variables:
  TOMCAT_MODULES_ENABLE: distributed-sessions
```

The distributed sessions module can be configured through the environment variable `TOMCAT_PROPERTIES`.

|  Property | Description  | Default  | 
|---|---|---|
| session.DatastoreStore.namespace    |  Namespace to use in the Datastore.                         |  tomcat-gcp-persistent-session |
| session.DatastoreStore.sessionKind  |  Name of the entity used to store sessions in the Datastore. |  TomcatGCloudSession |
| session.DatastoreStore.sessionMaxInactiveTime |  Defines the maximum time (in seconds) a session can be inactive before being deleted by the expiration process. | 3600 |

#### Running outside of Google Cloud
If you are using the runtime outside of Google Cloud, you will want to make sure that your application has access to
the Datastore. In this case, check out the [Google Cloud Authentication](https://developers.google.com/identity/protocols/application-default-credentials) guide.

## Development Guide

* See [instructions](DEVELOPING.md) on how to build and test this image.

### Contributing changes

* See [CONTRIBUTING.md](CONTRIBUTING.md)

## Licensing

* See [LICENSE](LICENSE)
{'fraction_non_alphanumeric': 0.08830022075055188, 'fraction_numerical': 0.0017660044150110375, 'mean_word_length': 4.639834024896266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '158591', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1873, 'n_words': 743}