DCD-545: Break confluence.cfg.xml into fragments and generate the DB section.

This commit is contained in:
Steve Smith 2019-08-09 14:54:39 +10:00
parent 7144efb130
commit 917e45ead6
8 changed files with 198 additions and 63 deletions

View File

@ -0,0 +1,16 @@
<!-- Start confluence.cfg.cluster.xml.j2 -->
<property name="confluence.cluster">true</property>
<property name="shared-home">{{ atl_product_home_shared }}</property>
<property name="confluence.cluster.home">{{ atl_product_home_shared }}</property>
<property name="confluence.cluster.aws.iam.role">{{ atl_hazelcast_network_aws_iam_role }}</property>
<property name="confluence.cluster.aws.region">{{ atl_hazelcast_network_aws_iam_region }}</property>
<property name="confluence.cluster.aws.host.header">{{ atl_hazelcast_network_aws_host_header }}</property>
<property name="confluence.cluster.aws.tag.key">{{ atl_hazelcast_network_aws_tag_key }}</property>
<property name="confluence.cluster.aws.tag.value">{{ atl_hazelcast_network_aws_tag_value }}</property>
<property name="confluence.cluster.join.type">aws</property>
<property name="confluence.cluster.name">{{ atl_aws_stack_name }}</property>
<property name="confluence.cluster.ttl">1</property>
<!-- End confluence.cfg.cluster.xml.j2 -->

View File

@ -0,0 +1,19 @@
<!-- Start confluence.cfg.db.xml.j2 -->
<property name="confluence.database.choice">{{ atl_db_choice }}</property>
<property name="hibernate.dialect">{{ atl_db_dialect }}</property>
<property name="hibernate.connection.driver_class">{{ atl_db_driver }}</property>
<property name="hibernate.connection.url">{{ atl_jdbc_url }}</property>
<property name="hibernate.connection.username">{{ atl_jdbc_user }}</property>
<property name="hibernate.connection.password">{{ atl_jdbc_password }}</property>
<property name="hibernate.c3p0.min_size">{{ atl_db_poolminsize }}</property>
<property name="hibernate.c3p0.max_size">{{ atl_db_poolmaxsize }}</property>
<property name="hibernate.c3p0.timeout">{{ atl_db_timeout }}</property>
<property name="hibernate.c3p0.idle_test_period">{{ atl_db_idletestperiod }}</property>
<property name="hibernate.c3p0.max_statements">{{ atl_db_maxstatements }}</property>
<property name="hibernate.c3p0.validate">{{ atl_db_validate }}</property>
<property name="hibernate.c3p0.acquire_increment">{{ atl_db_acquireincrement }}</property>
<property name="hibernate.c3p0.preferredTestQuery">{{ atl_db_validationquery }}</property>
<!-- End confluence.cfg.db.xml.j2 -->

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Start confluence.cfg.head.xml.j2 -->
<confluence-configuration>
<setupStep>setupstart</setupStep>
<setupType>custom</setupType>
<buildNumber>0</buildNumber>
<properties>
<property name="confluence.database.connection.type">database-type-standard</property>
<property name="webwork.multipart.saveDir">${localHome}/temp</property>
<property name="attachments.dir">${confluenceHome}/attachments</property>
<!-- End confluence.cfg.head.xml.j2 -->

View File

@ -0,0 +1,7 @@
<!-- Start confluence.cfg.tail.xml.j2 -->
</properties>
</confluence-configuration>
<!-- End confluence.cfg.tail.xml.j2 -->

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<confluence-configuration>
<setupStep>setupstart</setupStep>
<setupType>custom</setupType>
<buildNumber>0</buildNumber>
<properties>
<property name="confluence.database.choice">postgresql</property>
<property name="confluence.database.connection.type">database-type-standard</property>
<property name="hibernate.dialect">com.atlassian.confluence.impl.hibernate.dialect.PostgreSQLDialect</property>
<property name="webwork.multipart.saveDir">${localHome}/temp</property>
<property name="attachments.dir">${confluenceHome}/attachments</property>
<property name="hibernate.connection.driver_class">{{ atl_db_driver }}</property>
<property name="hibernate.connection.url">{{ atl_jdbc_url }}</property>
<property name="hibernate.connection.username">{{ atl_jdbc_user }}</property>
<property name="hibernate.connection.password">{{ atl_jdbc_password }}</property>
<property name="hibernate.c3p0.min_size">{{ atl_db_poolminsize }}</property>
<property name="hibernate.c3p0.max_size">{{ atl_db_poolmaxsize }}</property>
<property name="hibernate.c3p0.timeout">{{ atl_db_timeout }}</property>
<property name="hibernate.c3p0.idle_test_period">{{ atl_db_idletestperiod }}</property>
<property name="hibernate.c3p0.max_statements">{{ atl_db_maxstatements }}</property>
<property name="hibernate.c3p0.validate">{{ atl_db_validate }}</property>
<property name="hibernate.c3p0.acquire_increment">{{ atl_db_acquireincrement }}</property>
<property name="hibernate.c3p0.preferredTestQuery">select version();</property>
<property name="shared-home">{{ atl_product_home_shared }}</property>
<property name="confluence.cluster">true</property>
<property name="confluence.cluster.home">{{ atl_product_home_shared }}</property>
<property name="confluence.cluster.aws.iam.role">{{ atl_hazelcast_network_aws_iam_role }}</property>
<property name="confluence.cluster.aws.region">{{ atl_hazelcast_network_aws_iam_region }}</property>
<property name="confluence.cluster.aws.host.header">{{ atl_hazelcast_network_aws_host_header }}</property>
<property name="confluence.cluster.aws.tag.key">{{ atl_hazelcast_network_aws_tag_key }}</property>
<property name="confluence.cluster.aws.tag.value">{{ atl_hazelcast_network_aws_tag_value }}</property>
<property name="confluence.cluster.join.type">aws</property>
<property name="confluence.cluster.name">{{ atl_aws_stack_name }}</property>
<property name="confluence.cluster.ttl">1</property>
</properties>
</confluence-configuration>

View File

@ -43,7 +43,58 @@ log "Generating ${CONFLUENCE_INSTALL_DIR}/conf/server.xml"
> ${CONFLUENCE_INSTALL_DIR}/conf/server.xml
######################################################################
# Configure login properties
# Confluence config files
log "Generating ${CONFLUENCE_HOME}/confluence.cfg.xml"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.head.xml.j2 \
> ${CONFLUENCE_HOME}/confluence.cfg.xml
: ${ATL_JDBC_URL:=}
if [[ ! -z "$ATL_JDBC_URL" ]]; then
declare -A databases=(
["mysql-driver"]="com.mysql.jdbc.Driver"
["mysql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.MySQLDialect"
["postgresql-driver"]="org.postgresql.Driver"
["postgresql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.PostgreSQLDialect"
["mssql-driver"]="com.microsoft.sqlserver.jdbc.SQLServerDriver"
["mssql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.SQLServerDialect"
["oracle12c-driver"]="oracle.jdbc.driver.OracleDriver"
["oracle12c-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.OracleDialect"
)
# Must be supplied
export atl_jdbc_url=${ATL_JDBC_URL}
export atl_jdbc_user=${ATL_JDBC_USER}
export atl_jdbc_password=${ATL_JDBC_PASSWORD}
export atl_db_choice=${ATL_DB_TYPE}
export atl_db_driver=${databases[${atl_db_choice}"-driver"]}
export atl_db_dialect=${databases[${atl_db_choice}"-dialect"]}
# Defaults, can be overridden
export atl_db_poolmaxsize=${ATL_DB_POOLMAXSIZE:=100}
export atl_db_poolminsize=${ATL_DB_POOLMINSIZE:=20}
export atl_db_timeout=${ATL_DB_TIMEOUT:=30}
export atl_db_idletestperiod=${ATL_DB_IDLETESTPERIOD:=100}
export atl_db_maxstatements=${ATL_DB_MAXSTATEMENTS:=0}
export atl_db_validate=${ATL_DB_VALIDATE:=false}
export atl_db_acquireincrement=${ATL_DB_ACQUIREINCREMENT:=1}
export atl_db_validationquery=${ATL_DB_VALIDATIONQUERY:=select 1}
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.db.xml.j2 \
>> ${CONFLUENCE_HOME}/confluence.cfg.xml
fi
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.tail.xml.j2 \
>> ${CONFLUENCE_HOME}/confluence.cfg.xml
chown ${RUN_USER}.${RUN_GROUP} ${CONFLUENCE_HOME}/confluence.cfg.xml
chmod 0640 ${CONFLUENCE_HOME}/confluence.cfg.xml
# The default is two weeks, in seconds, same as the seraph default.
export atl_autologin_cookie_age=${ATL_AUTOLOGIN_COOKIE_AGE:=1209600}
@ -54,6 +105,14 @@ log "Generating ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/seraph-conf
> ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/seraph-config.xml
export atl_product_home=${CONFLUENCE_HOME}
log "Generating ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence-init.properties.j2 \
> ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties
# Start Confluence as the correct user
if [ "${UID}" -eq 0 ]; then
echo "User is currently root. Will change directory ownership to ${RUN_USER}:${RUN_GROUP}, then downgrade permission to ${RUN_USER}"

View File

@ -16,6 +16,8 @@ vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e
if [[ -z "$vars" ]]; then
echo "Warning: No variable was found in $template, syntax is {{VAR}}" >&2
cat $template
exit
fi
var_value() {

View File

@ -31,6 +31,16 @@ def wait_for_proc(container, proc_str, max_wait=10):
raise TimeoutError("Failed to find target process")
def wait_for_file(container, path, max_wait=10):
waited = 0
while waited < max_wait:
if container.file(path).exists:
return
time.sleep(0.1)
waited += 0.1
raise TimeoutError("Failed to find target process")
######################################################################
# Tests
@ -140,7 +150,7 @@ def test_server_xml_params(docker_cli, image):
def test_seraph_defaults(docker_cli, image):
container = run_image(docker_cli, image)
_jvm = wait_for_proc(container, "org.apache.catalina.startup.Bootstrap")
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/seraph-config.xml")
xml = etree.fromstring(container.file('/opt/atlassian/confluence/confluence/WEB-INF/classes/seraph-config.xml').content)
param = xml.xpath('//param-name[text()="autologin.cookie.age"]')[0].getnext()
@ -149,7 +159,7 @@ def test_seraph_defaults(docker_cli, image):
def test_seraph_login_set(docker_cli, image):
container = run_image(docker_cli, image, environment={"ATL_AUTOLOGIN_COOKIE_AGE": "TEST_VAL"})
_jvm = wait_for_proc(container, "org.apache.catalina.startup.Bootstrap")
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/seraph-config.xml")
xml = etree.fromstring(container.file('/opt/atlassian/confluence/confluence/WEB-INF/classes/seraph-config.xml').content)
param = xml.xpath('//param-name[text()="autologin.cookie.age"]')[0].getnext()
@ -158,26 +168,73 @@ def test_seraph_login_set(docker_cli, image):
def test_conf_init_set(docker_cli, image):
container = run_image(docker_cli, image, environment={"CONFLUENCE_HOME": "/tmp/"})
_jvm = wait_for_proc(container, "org.apache.catalina.startup.Bootstrap")
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/confluence-init.properties")
init = container.file('/opt/atlassian/confluence/confluence/WEB-INF/classes/confluence-init.properties')
assert init.contains("confluence.home = /tmp/")
#
# def test_confluence_cfg_xml_defaults(docker_cli, image):
# environment = {
#
# }
# container = docker_cli.containers.run(image, environment=environment, detach=True)
# confluence_cfg_xml = get_fileobj_from_container(container, '/var/atlassian/application-data/confluence/confluence.cfg.xml')
# xml = etree.parse(confluence_cfg_xml)
#
#
# def test_confluence_cfg_xml_params(docker_cli, image):
# environment = {
#
# }
# container = docker_cli.containers.run(image, environment=environment, detach=True)
# confluence_cfg_xml = get_fileobj_from_container(container, '/var/atlassian/application-data/confluence/confluence.cfg.xml')
# xml = etree.parse(confluence_cfg_xml)
def test_confluence_xml_default(docker_cli, image):
container = run_image(docker_cli, image)
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/confluence-init.properties")
#_jvm = wait_for_proc(container, "org.apache.catalina.startup.Bootstrap")
xml = etree.fromstring(container.file('/var/atlassian/application-data/confluence/confluence.cfg.xml').content)
assert xml.xpath('/confluence-configuration/buildNumber')[0].text == "0"
assert xml.xpath('/confluence-configuration/properties/property[@name="hibernate.connection.url"]') == []
def test_confluence_xml_postgres(docker_cli, image):
environment = {
'ATL_DB_TYPE': 'postgresql',
'ATL_JDBC_URL': 'atl_jdbc_url',
'ATL_JDBC_USER': 'atl_jdbc_user',
'ATL_JDBC_PASSWORD': 'atl_jdbc_password'
}
container = run_image(docker_cli, image, environment=environment)
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/confluence-init.properties")
xml = etree.fromstring(container.file('/var/atlassian/application-data/confluence/confluence.cfg.xml').content)
assert xml.xpath('//property[@name="hibernate.connection.url"]')[0].text == "atl_jdbc_url"
assert xml.xpath('//property[@name="hibernate.connection.username"]')[0].text == "atl_jdbc_user"
assert xml.xpath('//property[@name="hibernate.connection.password"]')[0].text == "atl_jdbc_password"
assert xml.xpath('//property[@name="confluence.database.choice"]')[0].text == "postgresql"
assert xml.xpath('//property[@name="hibernate.dialect"]')[0].text == "com.atlassian.confluence.impl.hibernate.dialect.PostgreSQLDialect"
assert xml.xpath('//property[@name="hibernate.connection.driver_class"]')[0].text == "org.postgresql.Driver"
assert xml.xpath('//property[@name="hibernate.c3p0.min_size"]')[0].text == "20"
assert xml.xpath('//property[@name="hibernate.c3p0.max_size"]')[0].text == "100"
assert xml.xpath('//property[@name="hibernate.c3p0.timeout"]')[0].text == "30"
assert xml.xpath('//property[@name="hibernate.c3p0.idle_test_period"]')[0].text == "100"
assert xml.xpath('//property[@name="hibernate.c3p0.max_statements"]')[0].text == "0"
assert xml.xpath('//property[@name="hibernate.c3p0.validate"]')[0].text == "false"
assert xml.xpath('//property[@name="hibernate.c3p0.acquire_increment"]')[0].text == "1"
assert xml.xpath('//property[@name="hibernate.c3p0.preferredTestQuery"]')[0].text == "select 1"
def test_confluence_xml_postgres_all_set(docker_cli, image):
environment = {
'ATL_DB_TYPE': 'postgresql',
'ATL_JDBC_URL': 'atl_jdbc_url',
'ATL_JDBC_USER': 'atl_jdbc_user',
'ATL_JDBC_PASSWORD': 'atl_jdbc_password',
'ATL_DB_POOLMAXSIZE': 'x100',
'ATL_DB_POOLMINSIZE': 'x20',
'ATL_DB_TIMEOUT': 'x30',
'ATL_DB_IDLETESTPERIOD': 'x100',
'ATL_DB_MAXSTATEMENTS': 'x0',
'ATL_DB_VALIDATE': 'xfalse',
'ATL_DB_ACQUIREINCREMENT': 'x1',
'ATL_DB_VALIDATIONQUERY': 'xselect 1'
}
container = run_image(docker_cli, image, environment=environment)
wait_for_file(container, "/opt/atlassian/confluence/confluence/WEB-INF/classes/confluence-init.properties")
xml = etree.fromstring(container.file('/var/atlassian/application-data/confluence/confluence.cfg.xml').content)
assert xml.xpath('//property[@name="hibernate.c3p0.min_size"]')[0].text == "x20"
assert xml.xpath('//property[@name="hibernate.c3p0.max_size"]')[0].text == "x100"
assert xml.xpath('//property[@name="hibernate.c3p0.timeout"]')[0].text == "x30"
assert xml.xpath('//property[@name="hibernate.c3p0.idle_test_period"]')[0].text == "x100"
assert xml.xpath('//property[@name="hibernate.c3p0.max_statements"]')[0].text == "x0"
assert xml.xpath('//property[@name="hibernate.c3p0.validate"]')[0].text == "xfalse"
assert xml.xpath('//property[@name="hibernate.c3p0.acquire_increment"]')[0].text == "x1"
assert xml.xpath('//property[@name="hibernate.c3p0.preferredTestQuery"]')[0].text == "xselect 1"