Skip to content

Commit b2bdeb8

Browse files
committed
Merge branch 'violetagg-tomcat_external_configuration'
2 parents e2aaccc + 010e2f9 commit b2bdeb8

File tree

7 files changed

+149
-5
lines changed

7 files changed

+149
-5
lines changed

config/tomcat.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ tomcat:
1919
version: 8.0.+
2020
repository_root: ! '{default.repository.root}/tomcat'
2121
context_path:
22+
external_configuration_enabled: false
23+
external_configuration:
24+
version: 1.+
25+
repository_root: ""
2226
lifecycle_support:
2327
version: 2.+
2428
repository_root: ! '{default.repository.root}/tomcat-lifecycle-support'

docs/container-tomcat.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Tomcat Container allows servlet 2 and 3 web applications to be run. These a
88
</tr>
99
<tr>
1010
<td><strong>Tags</strong></td>
11-
<td><tt>tomcat-instance=&lang;version&rang;</tt>, <tt>tomcat-lifecycle-support=&lang;version&rang;</tt>, <tt>tomcat-logging-support=&lang;version&rang;</tt> <tt>tomcat-redis-store=&lang;version&rang;</tt> <i>(optional)</i></td>
11+
<td><tt>tomcat-instance=&lang;version&rang;</tt>, <tt>tomcat-lifecycle-support=&lang;version&rang;</tt>, <tt>tomcat-logging-support=&lang;version&rang;</tt>, <tt>tomcat-redis-store=&lang;version&rang;</tt> <i>(optional)</i>, <tt>tomcat-external_configuration=&lang;version&rang;</tt> <i>(optional)</i></td>
1212
</tr>
1313
</table>
1414
Tags are printed to standard output by the buildpack detect script
@@ -49,6 +49,9 @@ The container can be configured by modifying the [`config/tomcat.yml`][] file in
4949
| `tomcat.context_path` | The context path to expose the application at.
5050
| `tomcat.repository_root` | The URL of the Tomcat repository index ([details][repositories]).
5151
| `tomcat.version` | The version of Tomcat to use. Candidate versions can be found in [this listing](http://download.pivotal.io.s3.amazonaws.com/tomcat/index.yml).
52+
| `tomcat.external_configuration_enabled` | Set to `true` to be able to supply an external Tomcat configuration. Default is `false`.
53+
| `external_configuration.version` | The version of the External Tomcat Configuration to use. Candidate versions can be found in the the repository that you have created to house the External Tomcat Configuration. Note: It is required the external configuration to allow symlinks.
54+
| `external_configuration.repository_root` | The URL of the External Tomcat Configuration repository index ([details][repositories]).
5255

5356
### Common configurations
5457
The version of Tomcat can be configured by setting an environment variable.
@@ -65,7 +68,34 @@ $ cf set-env my-application JBP_CONFIG_TOMCAT '{tomcat: { context_path: /first-s
6568

6669

6770
### Additional Resources
68-
The container can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/tomcat` directory in the buildpack fork. For example, to override the default `logging.properties` add your custom file to `resources/tomcat/conf/logging.properties`.
71+
The container can also be configured by overlaying a set of resources on the default distribution. To do this follow one of the options below.
72+
73+
#### Buildpack Fork
74+
Add files to the `resources/tomcat` directory in the buildpack fork. For example, to override the default `logging.properties` add your custom file to `resources/tomcat/conf/logging.properties`.
75+
76+
#### External Tomcat Configuration
77+
Supply a repository with an external Tomcat configuration.
78+
79+
Example in a manifest.yml
80+
```
81+
env:
82+
JBP_CONFIG_TOMCAT: "{ tomcat: { external_configuration_enabled: true }, external_configuration: { repository_root: \"http://repository...\" } }"
83+
```
84+
85+
The artifacts that the repository provides must be in TAR format and must follow the Tomcat archive structure:
86+
87+
```
88+
tomcat
89+
|__conf
90+
|__context.xml
91+
|__server.xml
92+
|__web.xml
93+
|...
94+
```
95+
96+
Notes:
97+
* It is required the external configuration to allow symlinks. For more information check [Tomcat 7 configuration] or [Tomcat 8 configuration].
98+
* `JasperListener` is removed in Tomcat 8 so you should not add it to the server.xml.
6999

70100
## Session Replication
71101
By default, the Tomcat instance is configured to store all Sessions and their data in memory. Under certain circumstances it my be appropriate to persist the Sessions and their data to a repository. When this is the case (small amounts of data that should survive the failure of any individual instance), the buildpack can automatically configure Tomcat to do so by binding an appropriate service.
@@ -98,3 +128,5 @@ Additional supporting functionality can be found in the [`java-buildpack-support
98128
[`SPRING_PROFILES_ACTIVE`]: http://docs.spring.io/spring/docs/4.0.0.RELEASE/javadoc-api/org/springframework/core/env/AbstractEnvironment.html#ACTIVE_PROFILES_PROPERTY_NAME
99129
[Tomcat wiki]: http://wiki.apache.org/tomcat/HowTo/FasterStartUp
100130
[version syntax]: extending-repositories.md#version-syntax-and-ordering
131+
[Tomcat 7 configuration]: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Standard_Implementation
132+
[Tomcat 8 configuration]: http://tomcat.apache.org/tomcat-8.0-doc/config/resources.html#Common_Attributes

lib/java_buildpack/container/tomcat.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
require 'java_buildpack/container'
1919
require 'java_buildpack/container/tomcat/tomcat_insight_support'
2020
require 'java_buildpack/container/tomcat/tomcat_instance'
21+
require 'java_buildpack/container/tomcat/tomcat_external_configuration'
2122
require 'java_buildpack/container/tomcat/tomcat_lifecycle_support'
2223
require 'java_buildpack/container/tomcat/tomcat_logging_support'
2324
require 'java_buildpack/container/tomcat/tomcat_access_logging_support'
@@ -49,7 +50,7 @@ def command
4950

5051
# (see JavaBuildpack::Component::ModularComponent#sub_components)
5152
def sub_components(context)
52-
[
53+
components = [
5354
TomcatInstance.new(sub_configuration_context(context, 'tomcat')),
5455
TomcatLifecycleSupport.new(sub_configuration_context(context, 'lifecycle_support')),
5556
TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')),
@@ -58,6 +59,12 @@ def sub_components(context)
5859
TomcatGemfireStore.new(sub_configuration_context(context, 'gemfire_store')),
5960
TomcatInsightSupport.new(context)
6061
]
62+
63+
tomcat_configuration = @configuration['tomcat']
64+
components << TomcatExternalConfiguration.new(sub_configuration_context(context, 'external_configuration')) if
65+
tomcat_configuration['external_configuration_enabled']
66+
67+
components
6168
end
6269

6370
# (see JavaBuildpack::Component::ModularComponent#supports?)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2016 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'java_buildpack/component/versioned_dependency_component'
18+
require 'java_buildpack/container'
19+
20+
module JavaBuildpack
21+
module Container
22+
23+
# Encapsulates the detect, compile, and release functionality for Tomcat external configuration.
24+
class TomcatExternalConfiguration < JavaBuildpack::Component::VersionedDependencyComponent
25+
include JavaBuildpack::Container
26+
27+
# (see JavaBuildpack::Component::BaseComponent#compile)
28+
def compile
29+
download_tar
30+
end
31+
32+
# (see JavaBuildpack::Component::BaseComponent#release)
33+
def release
34+
end
35+
36+
protected
37+
38+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
39+
def supports?
40+
true
41+
end
42+
43+
end
44+
45+
end
46+
end
1.06 KB
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2016 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
require 'component_helper'
19+
require 'java_buildpack/container/tomcat/tomcat_external_configuration'
20+
21+
describe JavaBuildpack::Container::TomcatExternalConfiguration do
22+
include_context 'component_helper'
23+
24+
let(:component_id) { 'tomcat' }
25+
26+
it 'always detects' do
27+
expect(component.detect).to eq("tomcat-external-configuration=#{version}")
28+
end
29+
30+
it 'extracts Tomcat external configuration files from a GZipped TAR',
31+
app_fixture: 'container_tomcat',
32+
cache_fixture: 'stub-tomcat-external-configuration.tar.gz' do
33+
34+
component.compile
35+
36+
expect(sandbox + 'conf/context.xml').to exist
37+
expect(sandbox + 'conf/server.xml').to exist
38+
end
39+
40+
end

spec/java_buildpack/container/tomcat_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
'lifecycle_support' => lifecycle_support_configuration,
3636
'logging_support' => logging_support_configuration,
3737
'access_logging_support' => access_logging_support_configuration,
38-
'redis_store' => redis_store_configuration }
38+
'redis_store' => redis_store_configuration,
39+
'external_configuration' => tomcat_external_configuration }
3940
end
4041

41-
let(:tomcat_configuration) { double('tomcat-configuration') }
42+
let(:tomcat_configuration) { { 'external_configuration_enabled' => false } }
4243

4344
let(:lifecycle_support_configuration) { double('lifecycle-support-configuration') }
4445

@@ -48,6 +49,8 @@
4849

4950
let(:redis_store_configuration) { double('redis-store-configuration') }
5051

52+
let(:tomcat_external_configuration) { double('tomcat_external_configuration') }
53+
5154
it 'detects WEB-INF',
5255
app_fixture: 'container_tomcat' do
5356

@@ -88,6 +91,18 @@
8891
' run')
8992
end
9093

94+
context do
95+
96+
let(:tomcat_configuration) { { 'external_configuration_enabled' => true } }
97+
98+
it 'creates submodule TomcatExternalConfiguration' do
99+
expect(JavaBuildpack::Container::TomcatExternalConfiguration)
100+
.to receive(:new).with(sub_configuration_context(tomcat_external_configuration))
101+
102+
component.sub_components context
103+
end
104+
end
105+
91106
end
92107

93108
class StubTomcat < JavaBuildpack::Container::Tomcat

0 commit comments

Comments
 (0)