DCD-558: Move the server.xml defaulting and fallbacks into the template.

This commit is contained in:
Steve Smith 2019-08-13 11:23:20 +10:00
parent b2d80d2267
commit d4b755c63a
3 changed files with 47 additions and 50 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Server port="{{ atl_tomcat_mgmt_port }}"
<Server port="{{ atl_tomcat_mgmt_port | default('8000') }}"
shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
@ -12,18 +12,18 @@
<Service name="Catalina">
<Connector port="{{ atl_tomcat_port }}"
maxThreads="{{ atl_tomcat_maxthreads }}"
minSpareThreads="{{ atl_tomcat_minsparethreads }}"
connectionTimeout="{{ atl_tomcat_connectiontimeout }}"
enableLookups="{{ atl_tomcat_enablelookups }}"
protocol="{{ atl_tomcat_protocol }}"
redirectPort="{{ atl_tomcat_redirectport }}"
acceptCount="{{ atl_tomcat_acceptcount }}"
secure="{{ atl_tomcat_secure }}"
scheme="{{ atl_tomcat_scheme }}"
proxyName="{{ atl_proxy_name }}"
proxyPort="{{ atl_proxy_port }}"
<Connector port="{{ atl_tomcat_port | default('8090') }}"
maxThreads="{{ atl_tomcat_maxthreads | default('200') }}"
minSpareThreads="{{ atl_tomcat_minsparethreads | default('10') }}"
connectionTimeout="{{ atl_tomcat_connectiontimeout | default('20000') }}"
enableLookups="{{ atl_tomcat_enablelookups | default('false') }}"
protocol="{{ atl_tomcat_protocol | default('HTTP/1.1') }}"
redirectPort="{{ atl_tomcat_redirectport | default('8443') }}"
acceptCount="{{ atl_tomcat_acceptcount | default('10') }}"
secure="{{ atl_tomcat_secure | default(catalina_connector_secure) | default('false') }}"
scheme="{{ atl_tomcat_scheme | default(catalina_connector_scheme) | default('http') }}"
proxyName="{{ atl_proxy_name | default(catalina_connector_proxyname) | default('') }}"
proxyPort="{{ atl_proxy_port | default(catalina_connector_proxyport) | default('') }}"
relaxedPathChars="[]|"
relaxedQueryChars="[]|{}^\`&quot;&lt;&gt;"
@ -41,7 +41,7 @@
unpackWARs="true"
autoDeploy="false"
startStopThreads="4">
<Context path="{{ atl_tomcat_contextpath }}"
<Context path="{{ atl_tomcat_contextpath | default(catalina_context_path) | default('') }}"
docBase="../confluence"
debug="0"
reloadable="false"

View File

@ -14,6 +14,11 @@ def set_perms(path, user, group, mode):
shutil.chown(path, user=user, group=group)
os.chmod(path, mode)
# Setup Jinja2 for templating
jenv = j2.Environment(
loader=j2.FileSystemLoader('/opt/atlassian/etc/'),
autoescape=j2.select_autoescape(['xml']))
def gen_cfg(tmpl, target, env, user='root', group='root', mode=0o644):
logging.info("Generating {} from template {}".format(target, tmpl))
cfg = jenv.get_template(tmpl).render(env)
@ -21,57 +26,28 @@ def gen_cfg(tmpl, target, env, user='root', group='root', mode=0o644):
fd.write(cfg)
set_perms(target, user, group, mode)
logging.basicConfig(level=logging.DEBUG)
######################################################################
# Setup inputs and outputs
# Import all ATL_* and Dockerfile environment variables. We
# lower-case these for compatability with Ansible template
# convention. We handle default and legacy mappings below.
# Import all ATL_* and Dockerfile environment variables. We lower-case
# these for compatability with Ansible template convention. We also
# support CATALINA variables from older versions of the Docker images
# for backwards compatability, if the new version is not set.
env = {k.lower(): v
for k, v in os.environ.items()
if k.startswith(('ATL_', 'CONFLUENCE_', 'RUN_'))}
if k.startswith(('ATL_', 'CONFLUENCE_', 'RUN_', 'CATALINA_'))}
# For compatability with the Ansible templates.
env['atl_product_home'] = env['confluence_home']
env['atl_product_home_shared'] = env.get('confluence_shared_home')
# Setup Jinja2 for templating
jenv = j2.Environment(
loader=j2.FileSystemLoader('/opt/atlassian/etc/'),
autoescape=j2.select_autoescape(['xml']))
logging.basicConfig(level=logging.DEBUG)
######################################################################
# Generate server.xml for Tomcat.
defaults = {
# We support some variables from older versions of the Docker images
# for backwards compatability, if the new version is not set.
'atl_proxy_name': os.environ.get('CATALINA_CONNECTOR_PROXYNAME'),
'atl_proxy_port': os.environ.get('CATALINA_CONNECTOR_PROXYPORT'),
'atl_tomcat_secure': os.environ.get('CATALINA_CONNECTOR_SECURE', 'false'),
'atl_tomcat_scheme': os.environ.get('CATALINA_CONNECTOR_SCHEME', 'http'),
'atl_tomcat_contextpath': os.environ.get('CATALINA_CONTEXT_PATH'),
# Other default vals
'atl_tomcat_port': "8090",
'atl_tomcat_mgmt_port': "8000",
'atl_tomcat_maxthreads': "200",
'atl_tomcat_minsparethreads': "10",
'atl_tomcat_connectiontimeout': "20000",
'atl_tomcat_enablelookups': "false",
'atl_tomcat_protocol': "HTTP/1.1",
'atl_tomcat_redirectport': "8443",
'atl_tomcat_acceptcount': "10",
}
for key, defval in defaults.items():
if (key not in env) and defval:
env[key] = defval
gen_cfg('server.xml.j2', env['confluence_install_dir']+'/conf/server.xml', env)

View File

@ -108,6 +108,27 @@ def test_server_xml_defaults(docker_cli, image):
assert connector.get('proxyName') == ''
assert connector.get('proxyPort') == ''
def test_server_xml_catalina_fallback(docker_cli, image):
environment = {
'CATALINA_CONNECTOR_PROXYNAME': 'PROXYNAME',
'CATALINA_CONNECTOR_PROXYPORT': 'PROXYPORT',
'CATALINA_CONNECTOR_SECURE': 'SECURE',
'CATALINA_CONNECTOR_SCHEME': 'SCHEME',
'CATALINA_CONTEXT_PATH': 'CONTEXT'
}
container = run_image(docker_cli, image, environment=environment)
_jvm = wait_for_proc(container, "org.apache.catalina.startup.Bootstrap")
xml = etree.fromstring(container.file('/opt/atlassian/confluence/conf/server.xml').content)
connector = xml.find('.//Connector')
context = xml.find('.//Context')
assert connector.get('proxyName') == 'PROXYNAME'
assert connector.get('proxyPort') == 'PROXYPORT'
assert connector.get('scheme') == 'SCHEME'
assert connector.get('secure') == 'SECURE'
assert context.get('path') == 'CONTEXT'
def test_server_xml_params(docker_cli, image):
environment = {
'ATL_TOMCAT_MGMT_PORT': '8006',