Skip to content

Commit 0aa857a

Browse files
chrisfarmsnebhale
authored andcommitted
allow setting command line args for distzip
Adds the ability to configure the args passed to the start script when using the distzip container format. This lets you, for example, set: JBP_CONFIG_DIST_ZIP : '{ arguments: "server config.yml" }' to add "server config.yml" as arguments to the start script. It is analogous to JBP_CONFIG_JAVA_MAIN. [resolves #721][resolves #811] Signed-off-by: Ben Hale <[email protected]>
1 parent 03e8eec commit 0aa857a

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

config/dist_zip.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2020 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the DistZip container
17+
---
18+
arguments:

config/dist_zip_like.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2020 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the DistZip container
17+
---
18+
arguments:

docs/container-dist_zip.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ The Dist Zip Container allows applications packaged in [`distZip`-style][] to be
1616
</table>
1717
Tags are printed to standard output by the buildpack detect script
1818

19-
If the application uses Spring, [Spring profiles][] can be specified by setting the [`SPRING_PROFILES_ACTIVE`][] environment variable. This is automatically detected and used by Spring. The Spring Auto-reconfiguration Framework will specify the `cloud` profile in addition to any others.
19+
If the application uses Spring, [Spring profiles][] can be specified by setting the [`SPRING_PROFILES_ACTIVE`][] environment variable. This is automatically detected and used by Spring. The Spring Auto-reconfiguration Framework will specify the `cloud` profile in addition to any others.
2020

2121
## Configuration
22-
The Dist Zip Container cannot be configured.
22+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
2323

24+
The container can be configured by modifying the `config/dist_zip.yml` file in the buildpack fork.
25+
26+
| Name | Description
27+
| ---- | -----------
28+
| `arguments` | Optional command line arguments to be passed to the start script. The arguments are specified as a single YAML scalar in plain style or enclosed in single or double quotes.
29+
30+
[Configuration and Extension]: ../README.md#configuration-and-extension
2431
[`distZip`-style]: http://www.gradle.org/docs/current/userguide/application_plugin.html
2532
[Spring profiles]:http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/
2633
[`SPRING_PROFILES_ACTIVE`]: http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/env/AbstractEnvironment.html#ACTIVE_PROFILES_PROPERTY_NAME

lib/java_buildpack/container/dist_zip_like.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def release
4747
@droplet.environment_variables.as_env_vars,
4848
@droplet.java_home.as_env_var,
4949
'exec',
50-
qualify_path(start_script(root), @droplet.root)
50+
qualify_path(start_script(root), @droplet.root),
51+
arguments
5152
].flatten.compact.join(' ')
5253
end
5354

@@ -76,11 +77,17 @@ def supports?
7677

7778
private
7879

80+
ARGUMENTS_PROPERTY = 'arguments'
81+
7982
PATTERN_APP_CLASSPATH = /^declare -r app_classpath=\"(.*)\"$/.freeze
8083

8184
PATTERN_CLASSPATH = /^CLASSPATH=(.*)$/.freeze
8285

83-
private_constant :PATTERN_APP_CLASSPATH, :PATTERN_CLASSPATH
86+
private_constant :ARGUMENTS_PROPERTY, :PATTERN_APP_CLASSPATH, :PATTERN_CLASSPATH
87+
88+
def arguments
89+
@configuration[ARGUMENTS_PROPERTY]
90+
end
8491

8592
def augment_app_classpath(content)
8693
additional_classpath = (@droplet.additional_libraries + @droplet.root_libraries).sort.map do |library|

spec/java_buildpack/container/dist_zip_like_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@
5858
'$PWD/bin/application')
5959
end
6060

61+
context do
62+
let(:configuration) { { 'arguments' => 'some arguments' } }
63+
64+
it 'returns command line arguments when they are specified',
65+
app_fixture: 'container_dist_zip' do
66+
67+
expect(component.release).to end_with('some arguments')
68+
end
69+
end
70+
6171
end

spec/java_buildpack/container/dist_zip_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@
5252
expect(component.detect).to be_nil
5353
end
5454

55+
context do
56+
let(:configuration) { { 'arguments' => 'some arguments' } }
57+
58+
it 'returns command line arguments when they are specified',
59+
app_fixture: 'container_dist_zip' do
60+
61+
expect(component.release).to end_with('some arguments')
62+
end
63+
end
64+
5565
end

0 commit comments

Comments
 (0)