From a18c1b8c8e9275313639a6aa6737af1eb3f912d2 Mon Sep 17 00:00:00 2001 From: Bledi Feshti Date: Wed, 11 Sep 2019 09:22:28 +0200 Subject: [PATCH 1/4] docker-entrypoint will now set default configs based on Neo4j Edition --- docker-image-src/3.4/docker-entrypoint.sh | 54 ++++++++++++------ docker-image-src/3.5/docker-entrypoint.sh | 55 +++++++++++++------ docker-image-src/4.0/docker-entrypoint.sh | 55 ++++++++++++------- .../com/neo4j/docker/TestConfSettings.java | 54 ++++++++++++++++-- src/test/resources/confs/EnterpriseConf.conf | 1 + 5 files changed, 161 insertions(+), 58 deletions(-) create mode 100644 src/test/resources/confs/EnterpriseConf.conf diff --git a/docker-image-src/3.4/docker-entrypoint.sh b/docker-image-src/3.4/docker-entrypoint.sh index 54622972..4cc1537d 100755 --- a/docker-image-src/3.4/docker-entrypoint.sh +++ b/docker-image-src/3.4/docker-entrypoint.sh @@ -228,14 +228,15 @@ fi : ${NEO4J_dbms_connectors_default__advertised__address:=${NEO4J_dbms_connectors_defaultAdvertisedAddress:-}} : ${NEO4J_ha_server__id:=${NEO4J_ha_serverId:-}} : ${NEO4J_ha_initial__hosts:=${NEO4J_ha_initialHosts:-}} -: ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} -: ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} -: ${NEO4J_causal__clustering_discovery__listen__address:=${NEO4J_causalClustering_discoveryListenAddress:-"0.0.0.0:5000"}} -: ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} -: ${NEO4J_causal__clustering_transaction__listen__address:=${NEO4J_causalClustering_transactionListenAddress:-"0.0.0.0:6000"}} -: ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} -: ${NEO4J_causal__clustering_raft__listen__address:=${NEO4J_causalClustering_raftListenAddress:-"0.0.0.0:7000"}} -: ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} + : ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} + : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} + : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} + : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} +fi # unset old hardcoded unsupported env variables unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ @@ -252,11 +253,15 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ # Custom settings for dockerized neo4j : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} -: ${NEO4J_ha_host_coordination:=$(hostname):5001} -: ${NEO4J_ha_host_data:=$(hostname):6001} -: ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} -: ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} -: ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_ha_host_coordination:=$(hostname):5001} + : ${NEO4J_ha_host_data:=$(hostname):6001} + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} +fi if [ -d /conf ]; then if secure_mode_enabled; then @@ -333,25 +338,40 @@ if [ "${cmd}" == "neo4j" ]; then fi fi -declare -A CONFIG +declare -A COMMUNITY +declare -A ENTERPRISE -CONFIG=( +COMMUNITY=( [dbms.tx_log.rotation.retention_policy]="100M size" [dbms.memory.pagecache.size]="512M" [dbms.connectors.default_listen_address]="0.0.0.0" [dbms.connector.https.listen_address]="0.0.0.0:7473" [dbms.connector.http.listen_address]="0.0.0.0:7474" [dbms.connector.bolt.listen_address]="0.0.0.0:7687" +) + +ENTERPRISE=( [causal_clustering.transaction_listen_address]="0.0.0.0:6000" [causal_clustering.raft_listen_address]="0.0.0.0:7000" [causal_clustering.discovery_listen_address]="0.0.0.0:5000" ) -for conf in ${!CONFIG[@]} ; do +for conf in ${!COMMUNITY[@]} ; do if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf then - echo -e "\n"$conf=${CONFIG[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi +done + +for conf in ${!ENTERPRISE[@]} ; do + + if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf + then + echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi fi done diff --git a/docker-image-src/3.5/docker-entrypoint.sh b/docker-image-src/3.5/docker-entrypoint.sh index 88a3f326..0a1a5977 100755 --- a/docker-image-src/3.5/docker-entrypoint.sh +++ b/docker-image-src/3.5/docker-entrypoint.sh @@ -228,14 +228,16 @@ fi : ${NEO4J_dbms_connectors_default__advertised__address:=${NEO4J_dbms_connectors_defaultAdvertisedAddress:-}} : ${NEO4J_ha_server__id:=${NEO4J_ha_serverId:-}} : ${NEO4J_ha_initial__hosts:=${NEO4J_ha_initialHosts:-}} -: ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} -: ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} -: ${NEO4J_causal__clustering_discovery__listen__address:=${NEO4J_causalClustering_discoveryListenAddress:-"0.0.0.0:5000"}} -: ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} -: ${NEO4J_causal__clustering_transaction__listen__address:=${NEO4J_causalClustering_transactionListenAddress:-"0.0.0.0:6000"}} -: ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} -: ${NEO4J_causal__clustering_raft__listen__address:=${NEO4J_causalClustering_raftListenAddress:-"0.0.0.0:7000"}} -: ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} + : ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} + : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} + : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} + : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} +fi + # unset old hardcoded unsupported env variables unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ @@ -252,11 +254,15 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ # Custom settings for dockerized neo4j : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} -: ${NEO4J_ha_host_coordination:=$(hostname):5001} -: ${NEO4J_ha_host_data:=$(hostname):6001} -: ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} -: ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} -: ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_ha_host_coordination:=$(hostname):5001} + : ${NEO4J_ha_host_data:=$(hostname):6001} + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} +fi if [ -d /conf ]; then if secure_mode_enabled; then @@ -333,25 +339,40 @@ if [ "${cmd}" == "neo4j" ]; then fi fi -declare -A CONFIG +declare -A COMMUNITY +declare -A ENTERPRISE -CONFIG=( +COMMUNITY=( [dbms.tx_log.rotation.retention_policy]="100M size" [dbms.memory.pagecache.size]="512M" [dbms.connectors.default_listen_address]="0.0.0.0" [dbms.connector.https.listen_address]="0.0.0.0:7473" [dbms.connector.http.listen_address]="0.0.0.0:7474" [dbms.connector.bolt.listen_address]="0.0.0.0:7687" +) + +ENTERPRISE=( [causal_clustering.transaction_listen_address]="0.0.0.0:6000" [causal_clustering.raft_listen_address]="0.0.0.0:7000" [causal_clustering.discovery_listen_address]="0.0.0.0:5000" ) -for conf in ${!CONFIG[@]} ; do +for conf in ${!COMMUNITY[@]} ; do if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf then - echo -e "\n"$conf=${CONFIG[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi +done + +for conf in ${!ENTERPRISE[@]} ; do + + if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf + then + echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi fi done diff --git a/docker-image-src/4.0/docker-entrypoint.sh b/docker-image-src/4.0/docker-entrypoint.sh index bedcfa8a..99b85d20 100755 --- a/docker-image-src/4.0/docker-entrypoint.sh +++ b/docker-image-src/4.0/docker-entrypoint.sh @@ -226,16 +226,16 @@ fi : ${NEO4J_dbms_unmanaged__extension__classes:=${NEO4J_dbms_unmanagedExtensionClasses:-}} : ${NEO4J_dbms_allow__format__migration:=${NEO4J_dbms_allowFormatMigration:-}} : ${NEO4J_dbms_connectors_default__advertised__address:=${NEO4J_dbms_connectors_defaultAdvertisedAddress:-}} -: ${NEO4J_ha_server__id:=${NEO4J_ha_serverId:-}} -: ${NEO4J_ha_initial__hosts:=${NEO4J_ha_initialHosts:-}} -: ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} -: ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} -: ${NEO4J_causal__clustering_discovery__listen__address:=${NEO4J_causalClustering_discoveryListenAddress:-"0.0.0.0:5000"}} -: ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} -: ${NEO4J_causal__clustering_transaction__listen__address:=${NEO4J_causalClustering_transactionListenAddress:-"0.0.0.0:6000"}} -: ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} -: ${NEO4J_causal__clustering_raft__listen__address:=${NEO4J_causalClustering_raftListenAddress:-"0.0.0.0:7000"}} -: ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} + : ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} + : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} + : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} + : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} +fi + # unset old hardcoded unsupported env variables unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ @@ -252,11 +252,13 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ # Custom settings for dockerized neo4j : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} -: ${NEO4J_ha_host_coordination:=$(hostname):5001} -: ${NEO4J_ha_host_data:=$(hostname):6001} -: ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} -: ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} -: ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} + +if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} +fi if [ -d /conf ]; then if secure_mode_enabled; then @@ -333,25 +335,40 @@ if [ "${cmd}" == "neo4j" ]; then fi fi -declare -A CONFIG +declare -A COMMUNITY +declare -A ENTERPRISE -CONFIG=( +COMMUNITY=( [dbms.tx_log.rotation.retention_policy]="100M size" [dbms.memory.pagecache.size]="512M" [dbms.connectors.default_listen_address]="0.0.0.0" [dbms.connector.https.listen_address]="0.0.0.0:7473" [dbms.connector.http.listen_address]="0.0.0.0:7474" [dbms.connector.bolt.listen_address]="0.0.0.0:7687" +) + +ENTERPRISE=( [causal_clustering.transaction_listen_address]="0.0.0.0:6000" [causal_clustering.raft_listen_address]="0.0.0.0:7000" [causal_clustering.discovery_listen_address]="0.0.0.0:5000" ) -for conf in ${!CONFIG[@]} ; do +for conf in ${!COMMUNITY[@]} ; do if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf then - echo -e "\n"$conf=${CONFIG[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi +done + +for conf in ${!ENTERPRISE[@]} ; do + + if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf + then + echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi fi done diff --git a/src/test/java/com/neo4j/docker/TestConfSettings.java b/src/test/java/com/neo4j/docker/TestConfSettings.java index 1e9aac8a..9bacf5de 100644 --- a/src/test/java/com/neo4j/docker/TestConfSettings.java +++ b/src/test/java/com/neo4j/docker/TestConfSettings.java @@ -149,9 +149,9 @@ void testCommentedConfigsAreReplacedByDefaultOnes() throws Exception { container.setWaitStrategy(Wait.forLogMessage(".*Config Dumped.*", 1).withStartupTimeout(Duration.ofSeconds(10))); container.setCommand("dump-config"); container.start(); - //Read the config file to check if the config is appended correctly + //Read the config file to check if the config is set correctly Map configurations = parseConfFile(conf); - Assertions.assertTrue(configurations.containsKey("dbms.memory.pagecache.size"), "conf settings not appended correctly by docker-entrypoint"); + Assertions.assertTrue(configurations.containsKey("dbms.memory.pagecache.size"), "conf settings not set correctly by docker-entrypoint"); Assertions.assertEquals("512M", configurations.get("dbms.memory.pagecache.size"), "conf settings not appended correctly by docker-entrypoint"); @@ -183,13 +183,12 @@ void testConfigsAreNotOverridenByDockerentrypoint() throws Exception { container.stop(); } - @Test void testEnvVarsOverride() throws Exception { //Create container GenericContainer container = createContainer() .withEnv("NEO4J_dbms_memory_pagecache_size", "512m"); - //Mount /conf + //Mount /conf /logs Path confMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "conf-", "/conf"); Path logMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "logs-", "/logs"); SetContainerUser.nonRootUser(container); @@ -199,7 +198,7 @@ void testEnvVarsOverride() throws Exception { //Start the container container.setWaitStrategy(Wait.forHttp("/").forPort(7474).forStatusCode(200)); container.start(); - //Read the config file to check if the config is not overriden + //Read the debug.log to check that dbms.memory.pagecache.size was set correctly Stream lines = Files.lines(logMount.resolve("debug.log")); Optional heapSizeMatch = lines.filter(s -> s.contains("dbms.memory.pagecache.size=512m")).findFirst(); lines.close(); @@ -207,4 +206,49 @@ void testEnvVarsOverride() throws Exception { //Kill the container container.stop(); } + + @Test + void testEnterpriseConfigsAreSetCorrectly() throws Exception { + Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, + "This is testing only ENTERPRISE EDITION configs"); + //Create container + GenericContainer container = createContainer(); + //Mount /conf + Path confMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "conf-", "/conf"); + Path logMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "logs-", "/logs"); + SetContainerUser.nonRootUser(container); + //Create EnterpriseCOnf.conf file + Path confFile = Paths.get("src", "test", "resources", "confs", "EnterpriseConf.conf"); + Files.copy(confFile, confMount.resolve("neo4j.conf")); + //Start the container + container.setWaitStrategy(Wait.forHttp("/").forPort(7474).forStatusCode(200)); + container.start(); + //Read debug.log file to check that the causal_clustering.transaction_listen_address was set correctly + Stream lines = Files.lines(logMount.resolve("debug.log")); + Optional heapSizeMatch = lines.filter(s -> s.contains("causal_clustering.transaction_listen_address=0.0.0.0:9000")).findFirst(); + lines.close(); + Assertions.assertTrue(heapSizeMatch.isPresent(), "causal_clustering.transaction_listen_address was not set correctly"); + //Kill the container + container.stop(); + } + @Test + void testCommunityConfigsAreSetCorrectly() throws Exception { + Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.COMMUNITY, + "This is testing only COMMUNITY EDITION configs"); + //Create container + GenericContainer container = createContainer(); + //Mount /logs + Path logMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "logs-", "/logs"); + SetContainerUser.nonRootUser(container); + //Start the container + container.setWaitStrategy(Wait.forHttp("/").forPort(7474).forStatusCode(200)); + container.start(); + //Read debug.log to check that causal_clustering confs are not present + Stream lines = Files.lines(logMount.resolve("debug.log")); + Optional ccNotPresent = lines.filter(s -> s.contains("causal_clustering.transaction_listen_address")).findFirst(); + lines.close(); + Assertions.assertFalse(ccNotPresent.isPresent(), "causal_clustering.transaction_listen_address should not be on the Community debug.log"); + //Kill the container + container.stop(); + } } \ No newline at end of file diff --git a/src/test/resources/confs/EnterpriseConf.conf b/src/test/resources/confs/EnterpriseConf.conf new file mode 100644 index 00000000..d9088ade --- /dev/null +++ b/src/test/resources/confs/EnterpriseConf.conf @@ -0,0 +1 @@ +causal_clustering.transaction_listen_address=0.0.0.0:9000 \ No newline at end of file From 7168356e7acd5eaf5d1e72589a03d25b94aaaf49 Mon Sep 17 00:00:00 2001 From: Bledi Feshti Date: Wed, 11 Sep 2019 09:56:34 +0200 Subject: [PATCH 2/4] added changes for the 3.3 also --- docker-image-src/3.3/docker-entrypoint.sh | 26 ++++++----------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/docker-image-src/3.3/docker-entrypoint.sh b/docker-image-src/3.3/docker-entrypoint.sh index d4391c19..2f1e8c89 100755 --- a/docker-image-src/3.3/docker-entrypoint.sh +++ b/docker-image-src/3.3/docker-entrypoint.sh @@ -233,14 +233,12 @@ if [ "${NEO4J_EDITION}" == "enterprise" ]; then : ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}} : ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}} - : ${NEO4J_causal__clustering_discovery__listen__address:=${NEO4J_causalClustering_discoveryListenAddress:-"0.0.0.0:5000"}} : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} - : ${NEO4J_causal__clustering_transaction__listen__address:=${NEO4J_causalClustering_transactionListenAddress:-"0.0.0.0:6000"}} : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} - : ${NEO4J_causal__clustering_raft__listen__address:=${NEO4J_causalClustering_raftListenAddress:-"0.0.0.0:7000"}} : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} fi + # unset old hardcoded unsupported env variables unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ NEO4J_dbms_unmanagedExtensionClasses NEO4J_dbms_allowFormatMigration \ @@ -341,9 +339,10 @@ if [ "${cmd}" == "neo4j" ]; then fi fi -declare -A CONFIG +declare -A COMMUNITY +declare -A ENTERPRISE -CONFIG=( +COMMUNITY=( [dbms.tx_log.rotation.retention_policy]="100M size" [dbms.memory.pagecache.size]="512M" [dbms.connectors.default_listen_address]="0.0.0.0" @@ -352,30 +351,19 @@ CONFIG=( [dbms.connector.bolt.listen_address]="0.0.0.0:7687" ) -for conf in ${!CONFIG[@]} ; do - - if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf - then - echo -e "\n"$conf=${CONFIG[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf - fi -done - -declare -A ENTERPRISE - ENTERPRISE=( [causal_clustering.transaction_listen_address]="0.0.0.0:6000" [causal_clustering.raft_listen_address]="0.0.0.0:7000" [causal_clustering.discovery_listen_address]="0.0.0.0:5000" ) -for conf in ${!ENTERPRISE[@]} ; do +for conf in ${!COMMUNITY[@]} ; do - if [ "${NEO4J_EDITION}" == "enterprise" ]; + if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf then - echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf fi done - # list env variables with prefix NEO4J_ and create settings from them unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do From b880bf4c9c46249274fa939e3ee63b9ec1284b32 Mon Sep 17 00:00:00 2001 From: Bledi Feshti Date: Wed, 11 Sep 2019 15:33:56 +0200 Subject: [PATCH 3/4] patches based on the last review --- docker-image-src/3.3/docker-entrypoint.sh | 31 ++++++++++++------- docker-image-src/3.4/docker-entrypoint.sh | 19 +++++------- docker-image-src/3.5/docker-entrypoint.sh | 19 +++--------- docker-image-src/4.0/docker-entrypoint.sh | 15 +++------ .../com/neo4j/docker/TestConfSettings.java | 16 ++++------ 5 files changed, 42 insertions(+), 58 deletions(-) diff --git a/docker-image-src/3.3/docker-entrypoint.sh b/docker-image-src/3.3/docker-entrypoint.sh index 2f1e8c89..d36d0ae2 100755 --- a/docker-image-src/3.3/docker-entrypoint.sh +++ b/docker-image-src/3.3/docker-entrypoint.sh @@ -236,7 +236,14 @@ if [ "${NEO4J_EDITION}" == "enterprise" ]; : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + # Custom settings for dockerized neo4j + : ${NEO4J_ha_host_coordination:=$(hostname):5001} + : ${NEO4J_ha_host_data:=$(hostname):6001} + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} fi + : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} # unset old hardcoded unsupported env variables @@ -252,18 +259,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ NEO4J_causalClustering_raftListenAddress \ NEO4J_causalClustering_raftAdvertisedAddress -# Custom settings for dockerized neo4j -: ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} - -if [ "${NEO4J_EDITION}" == "enterprise" ]; - then - : ${NEO4J_ha_host_coordination:=$(hostname):5001} - : ${NEO4J_ha_host_data:=$(hostname):6001} - : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} - : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} - : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} -fi - if [ -d /conf ]; then if secure_mode_enabled; then check_mounted_folder_readable "/conf" @@ -364,6 +359,18 @@ for conf in ${!COMMUNITY[@]} ; do echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf fi done + +for conf in ${!ENTERPRISE[@]} ; do + + if [ "${NEO4J_EDITION}" == "enterprise" ]; + then + if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf + then + echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf + fi + fi +done + # list env variables with prefix NEO4J_ and create settings from them unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do diff --git a/docker-image-src/3.4/docker-entrypoint.sh b/docker-image-src/3.4/docker-entrypoint.sh index 4cc1537d..44be63a3 100755 --- a/docker-image-src/3.4/docker-entrypoint.sh +++ b/docker-image-src/3.4/docker-entrypoint.sh @@ -236,7 +236,14 @@ if [ "${NEO4J_EDITION}" == "enterprise" ]; : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + # Custom settings for dockerized neo4j + : ${NEO4J_ha_host_coordination:=$(hostname):5001} + : ${NEO4J_ha_host_data:=$(hostname):6001} + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} fi + : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} # unset old hardcoded unsupported env variables unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ @@ -251,18 +258,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ NEO4J_causalClustering_raftListenAddress \ NEO4J_causalClustering_raftAdvertisedAddress -# Custom settings for dockerized neo4j -: ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} - -if [ "${NEO4J_EDITION}" == "enterprise" ]; - then - : ${NEO4J_ha_host_coordination:=$(hostname):5001} - : ${NEO4J_ha_host_data:=$(hostname):6001} - : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} - : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} - : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} -fi - if [ -d /conf ]; then if secure_mode_enabled; then check_mounted_folder_readable "/conf" diff --git a/docker-image-src/3.5/docker-entrypoint.sh b/docker-image-src/3.5/docker-entrypoint.sh index 0a1a5977..62211494 100755 --- a/docker-image-src/3.5/docker-entrypoint.sh +++ b/docker-image-src/3.5/docker-entrypoint.sh @@ -226,8 +226,6 @@ fi : ${NEO4J_dbms_unmanaged__extension__classes:=${NEO4J_dbms_unmanagedExtensionClasses:-}} : ${NEO4J_dbms_allow__format__migration:=${NEO4J_dbms_allowFormatMigration:-}} : ${NEO4J_dbms_connectors_default__advertised__address:=${NEO4J_dbms_connectors_defaultAdvertisedAddress:-}} -: ${NEO4J_ha_server__id:=${NEO4J_ha_serverId:-}} -: ${NEO4J_ha_initial__hosts:=${NEO4J_ha_initialHosts:-}} if [ "${NEO4J_EDITION}" == "enterprise" ]; then @@ -236,7 +234,12 @@ if [ "${NEO4J_EDITION}" == "enterprise" ]; : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + # Custom settings for dockerized neo4j + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} fi + : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} # unset old hardcoded unsupported env variables @@ -252,18 +255,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ NEO4J_causalClustering_raftListenAddress \ NEO4J_causalClustering_raftAdvertisedAddress -# Custom settings for dockerized neo4j -: ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} - -if [ "${NEO4J_EDITION}" == "enterprise" ]; - then - : ${NEO4J_ha_host_coordination:=$(hostname):5001} - : ${NEO4J_ha_host_data:=$(hostname):6001} - : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} - : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} - : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} -fi - if [ -d /conf ]; then if secure_mode_enabled; then check_mounted_folder_readable "/conf" diff --git a/docker-image-src/4.0/docker-entrypoint.sh b/docker-image-src/4.0/docker-entrypoint.sh index 99b85d20..6b2f2462 100755 --- a/docker-image-src/4.0/docker-entrypoint.sh +++ b/docker-image-src/4.0/docker-entrypoint.sh @@ -234,7 +234,12 @@ if [ "${NEO4J_EDITION}" == "enterprise" ]; : ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}} : ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}} : ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}} + # Custom settings for dockerized neo4j + : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} + : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} + : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} fi + : ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} # unset old hardcoded unsupported env variables @@ -250,16 +255,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \ NEO4J_causalClustering_raftListenAddress \ NEO4J_causalClustering_raftAdvertisedAddress -# Custom settings for dockerized neo4j -: ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker} - -if [ "${NEO4J_EDITION}" == "enterprise" ]; - then - : ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000} - : ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000} - : ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000} -fi - if [ -d /conf ]; then if secure_mode_enabled; then check_mounted_folder_readable "/conf" diff --git a/src/test/java/com/neo4j/docker/TestConfSettings.java b/src/test/java/com/neo4j/docker/TestConfSettings.java index 9bacf5de..009d7f8c 100644 --- a/src/test/java/com/neo4j/docker/TestConfSettings.java +++ b/src/test/java/com/neo4j/docker/TestConfSettings.java @@ -208,31 +208,27 @@ void testEnvVarsOverride() throws Exception { } @Test - void testEnterpriseConfigsAreSetCorrectly() throws Exception { + void testEnterpriseOnlyDefaultsConfigsAreSet () throws Exception { Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, "This is testing only ENTERPRISE EDITION configs"); //Create container GenericContainer container = createContainer(); - //Mount /conf - Path confMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "conf-", "/conf"); + //Mount /logs Path logMount = HostFileSystemOperations.createTempFolderAndMountAsVolume(container, "logs-", "/logs"); SetContainerUser.nonRootUser(container); - //Create EnterpriseCOnf.conf file - Path confFile = Paths.get("src", "test", "resources", "confs", "EnterpriseConf.conf"); - Files.copy(confFile, confMount.resolve("neo4j.conf")); //Start the container container.setWaitStrategy(Wait.forHttp("/").forPort(7474).forStatusCode(200)); container.start(); - //Read debug.log file to check that the causal_clustering.transaction_listen_address was set correctly + //Read debug.log to check that causal_clustering confs are set successfully Stream lines = Files.lines(logMount.resolve("debug.log")); - Optional heapSizeMatch = lines.filter(s -> s.contains("causal_clustering.transaction_listen_address=0.0.0.0:9000")).findFirst(); + Optional ccPresent = lines.filter(s -> s.contains("causal_clustering.transaction_advertised_address")).findFirst(); lines.close(); - Assertions.assertTrue(heapSizeMatch.isPresent(), "causal_clustering.transaction_listen_address was not set correctly"); + Assertions.assertTrue(ccPresent.isPresent(), "causal_clustering.transaction_advertised_address should be found on the Enterprise debug.log"); //Kill the container container.stop(); } @Test - void testCommunityConfigsAreSetCorrectly() throws Exception { + void testCommunityDoesNotHaveEnterpriseConfigs() throws Exception { Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.COMMUNITY, "This is testing only COMMUNITY EDITION configs"); //Create container From a1895ec98ede175a0f63c49927664024941fd796 Mon Sep 17 00:00:00 2001 From: Bledi Feshti Date: Wed, 11 Sep 2019 16:50:59 +0200 Subject: [PATCH 4/4] docker-entrypoint will now set default configs based on Neo4j Edition --- src/test/java/com/neo4j/docker/TestConfSettings.java | 5 +++-- src/test/resources/confs/EnterpriseConf.conf | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 src/test/resources/confs/EnterpriseConf.conf diff --git a/src/test/java/com/neo4j/docker/TestConfSettings.java b/src/test/java/com/neo4j/docker/TestConfSettings.java index 009d7f8c..9f70f094 100644 --- a/src/test/java/com/neo4j/docker/TestConfSettings.java +++ b/src/test/java/com/neo4j/docker/TestConfSettings.java @@ -220,10 +220,11 @@ void testEnterpriseOnlyDefaultsConfigsAreSet () throws Exception { container.setWaitStrategy(Wait.forHttp("/").forPort(7474).forStatusCode(200)); container.start(); //Read debug.log to check that causal_clustering confs are set successfully + String expectedTxAddress = container.getContainerId().substring( 0, 12 ) + ":6000"; Stream lines = Files.lines(logMount.resolve("debug.log")); - Optional ccPresent = lines.filter(s -> s.contains("causal_clustering.transaction_advertised_address")).findFirst(); + Optional ccPresent = lines.filter(s -> s.contains("causal_clustering.transaction_advertised_address="+expectedTxAddress)).findFirst(); lines.close(); - Assertions.assertTrue(ccPresent.isPresent(), "causal_clustering.transaction_advertised_address should be found on the Enterprise debug.log"); + Assertions.assertTrue(ccPresent.isPresent(), "causal_clustering.transaction_advertised_address was not set correctly"); //Kill the container container.stop(); } diff --git a/src/test/resources/confs/EnterpriseConf.conf b/src/test/resources/confs/EnterpriseConf.conf deleted file mode 100644 index d9088ade..00000000 --- a/src/test/resources/confs/EnterpriseConf.conf +++ /dev/null @@ -1 +0,0 @@ -causal_clustering.transaction_listen_address=0.0.0.0:9000 \ No newline at end of file