Skip to content

Wrap IPv6 address in brackets [ ] if needed#36

Merged
laoneo merged 13 commits intojoomla-projects:mainfrom
muhme:install-joomla-with-db-port
Oct 20, 2024
Merged

Wrap IPv6 address in brackets [ ] if needed#36
laoneo merged 13 commits intojoomla-projects:mainfrom
muhme:install-joomla-with-db-port

Conversation

@muhme
Copy link
Contributor

@muhme muhme commented Sep 5, 2024

Summary

In the installJoomla custom command, ensure square brackets are added around an IPv6 address provided in the Cypress config's db_host field before to use it in the Joomla Web Installer's host name field. This should only be done if it is an IPv6 address, the address is not already enclosed in square brackets, and for PostgreSQL if port number is used.

Needed as a puzzle piece for joomla/joomla-cms#43902.

See the Problem

The problem is shown in using JBT >= 1.1.15 (fixed IP-addresses, defaults to unpatched). Notes for this first chapter 'See the problem':

  • It is tested with (old) postgres not the (new) pg driver. To see the problem it doesn't matter, as the Web Installer is using PHP driver.
  • Consider we are focusing on joomla-cypress only, not changing base_url, not testing Cypress custom database commands, only doing the installation step with Joomla Web Installer.
  • Can be watched in noVNC in parallel
  1. Create instance
scripts/create IPv6 44 mariadb
  1. Manual configure MariaDB with PDO driver, jbt_madb IP address and default port in branch_44/cypress.config.mjs file:
    db_type: 'MySQL (PDO)',
    db_host: 'fd00::12',
    db_port: '',
  1. Do the Joomla Web Installer step:
scripts/test 44 system novnc install/Installation.cy.js
  • in Joomla Web Installer database driver MySQL (PDO) and host field fd00::12 is used
  • ❌ Error Could not connect to PDO: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for fd00 failed: Name or service not known
    mariadb
  • This error occurs with both MariaDB and MySQL databases, regardless of whether the MySQLi or MySQL (PDO) driver is used.
  1. Only working is PostgreSQL with PostgreSQL (PDO) driver. Manual configure jbt_pg IP address fd00:13 in branch_44/cypress.config.mjs file:
    db_type: 'PostgreSQL (PDO)',
    db_host: 'fd00::13',
    db_port: '',
  1. Do the Joomla Web Installer step:
scripts/test 44 system novnc install/Installation.cy.js
  • In Joomla Web Installer database driver PostgreSQL (PDO) and host field fd00::13 (w/o square brackets!) is used
  • ✅ Cypress test passed successfully with Joomla Web Installer step

Summary: In the Cypress System Tests during the installation step (using the Joomla Web Installer), IPv6 addresses currently work only with PostgreSQL. IPv6 addresses are not functional for MariaDB and MySQL, whether using the MySQLi or PDO drivers. Using a non-standard port with IPv6 addresses does not work for any database.

Test this PR Isolated

Testing this joomla-cypress-36 PR without any other patches with all used Joomla CMS branches.

  1. Create an installation with the five branches 4.4-dev, 5.1-dev. 5.2-dev. 5.3-dev and 6.0-dev :
scripts/create IPv6
  1. Apply this patch on all five branches, on all five web servers:
scripts/patch joomla-cypress-36

👉 For 5.1-dev this updates joomla-cypress from 1.0.3 to 1.1.1 - which is a good idea anyway

  1. Manual configure MariaDB with PDO driver, jbt_madb IP address and default port in all five branches cypress.config.mjs files and verify:
docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: 'MySQL (PDO)'/\" -e \"s/db_host: '.*'/db_host: 'fd00::12'/\" -e \"s/db_port: '.*'/db_port: ''/\" /jbt/branch_*/cypress.config.mjs"
grep -e db_type -e db_host -e db_port */cypress.config.mjs
  1. Do the Joomla Web Installer step, five times, for each branch:
scripts/test system novnc install/Installation.cy.js
  • ✅ In Joomla Web Installer database driver MySQL (PDO) and host field [fd00::12] is used
  1. Repeated the steps 3 and 4 for the remaining four variants:
  • ✅ Database MariaDB MySQLi, fd00::12
  • ✅ Database MySQL MySQL (PDO), fd00::11
  • ✅ Database MySQL MySQLi, fd00::11
  • ✅ Database PostgreSQL PostgreSQL (PDO), fd00::13
    • Joomla Web Installer database driver host field fd00::13 is used

Summary:

  • ✅ In the Cypress System Tests during the installation step (using the Joomla Web Installer), IPv6 addresses work with only this PR joomla-cypress-36 for all five database variants.
  • ❌ Running System Tests with database custom commands on PostgreSQL does not work.
  • ❌ Using a non-standard port with IPv6 addresses does not work for any database.

🎉 Fun fact - this were 30 times the Joomla installation step (5 branches on create + 5 branches x 5 database variants). 🎉

IPv6 with Port Number

Additional patches to see IPv6 addresses working with non-default port for the installation step (PHP database driver), the System Tests (JS database driver used with the custom database commands) and PostgreSQL JS driver are:

  • joomla-cypress-33 - Install Joomla with non-standard db_port
  • joomla-cms-43968 - [cypress] Add db_port in Installation.cy.js
  • joomla-cms-44084 - [cypress] Using NPM Module 'pg' for 'postgres'
  • database-310 - [3.x] Allow to specify port number or UNIX socket in host option also for MySQL (PDO) and PostgreSQL (PDO)
  • database-315 - Allow IPv6 addresses with brackets for pgsql

Unfortunately, without manually resolving the merge conflicts, all these changes could not be applied to every branch. However, it was possible for the 4.4-dev branch (but in using framework 3) with the follwoing sequence:

  1. Create IPv6 installation with only the branch 4.4-dev and first patches:
scripts/create IPv6 44  joomla-cms-43968 database-310 database-315
  1. One more patch to use JS pg driver, as the patch needs npm clean install afterwards:
scripts/patch 44 joomla-cms-44084
docker exec jbt_44 npm ci
  1. Remaining patches (after the npm clean install):
scripts/patch 44 joomla-cypress-33  joomla-cypress-36
  1. Preparing tests with non-default database ports by setting up three port forwardings in the Cypress container:
docker exec jbt_cypress bash -c 'apt-get update && apt-get upgrade -y && apt-get install socat -y'
docker exec -d jbt_cypress socat 'TCP6-LISTEN:4711,fork,reuseaddr' 'TCP6:[fd00::11]:3306'
docker exec -d jbt_cypress socat 'TCP6-LISTEN:4712,fork,reuseaddr' 'TCP6:[fd00::12]:3306'
docker exec -d jbt_cypress socat 'TCP6-LISTEN:4713,fork,reuseaddr' 'TCP6:[fd00::13]:5432'
  1. Manually configure MariaDB with the PDO driver, using the Cypress container's IP address fd00::7 and port 4712, which is forwarded to MariaDB:
docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: 'MySQL (PDO)'/\" -e \"s/db_host: '.*'/db_host: 'fd00::7'/\" -e \"s/db_port: '.*'/db_port: '4712'/\" /jbt/branch_44/cypress.config.mjs" 
  1. Test the installation step (Joomla Web Installer):
scripts/test 44 system novnc install/Installation.cy.js
  • ✅ test passed successfully with using [fd00::7]:4712 in host field
  1. Test the remaining System Tests specifications:
scripts/test 44 system novnc
  1. Repeated the steps 5, 6 and 7 for the remaining four variants:
  • ✅ Database MariaDB MySQLi, fd00::7, 4712
  • ✅ Database MySQL MySQL (PDO), fd00::7, 4711
  • ✅ Database MySQL MySQLi, fd00::7, 4711
  • ✅ Database PostgreSQL PostgreSQL (PDO), fd00::7, 4713

Summary: ✅ IPv6 addresses can be used in Joomla Web Installer durin the System Tests installation step (PHP driver) and in the System Tests specs with custom database commands (using the JS driver) for all five database variants, including with non-default port numbers. All PRs work independently, and none make the situation worse. The implementation for joomla/joomla-cms#43902 is completed 😄

Complete Testing

To complete joomla/joomla-cms#43902 with all six PRs installed, it needs to be tested that hostname only, hostname with port, IPv6 address only, IPv4 address only and IPv4 address with port still work as expected.

Testing Hostname Only

  1. With the JBT instance installed, manually configure MariaDB with the PDO driver, using MariaDB hostname and default port:
docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: 'MySQL (PDO)'/\" -e \"s/db_host: '.*'/db_host: 'jbt_madb'/\" -e \"s/db_port: '.*'/db_port: ''/\" /jbt/branch_44/cypress.config.mjs" 
  1. Test the installation step (Joomla Web Installer):
scripts/test 44 system novnc install/Installation.cy.js
  • ✅ test passed successfully with using jbt_madb in host field
  1. Test the remaining System Tests specifications:
scripts/test 44 system novnc
  1. Repeated the steps 1, 2 and 4 for the remaining four variants:
  • ✅ Database MariaDB MySQLi, jbt_madb, ''
  • ✅ Database MySQL MySQL (PDO), jbt_mysql, ''
  • ✅ Database MySQL MySQLi, jbt_mysql, ''
  • ✅ Database PostgreSQL PostgreSQL (PDO), jbt_pg, ''

IPv6 Address Only

As this is always the same procedure, it is automated in bash:

host=("fd00::11" "fd00::11" "fd00::12" "fd00::12" "fd00::13")
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")

for i in "${!types[@]}"; do
  docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: '${types[$i]}'/\" -e \"s/db_host: '.*'/db_host: '${host[$i]}'/\" -e \"s/db_port: '.*'/db_port: ''/\" /jbt/branch_44/cypress.config.mjs"
  scripts/test 44 system novnc install/Installation.cy.js
  scripts/test 44 system novnc
done

Afterward, the logs are checked for errors:

tail -5 logs/*
  • ✅ All tests passed successfully with using e.g. [fd00::11], [fd00::12] or fd00::13 (for PostgreSQL w/o square brackets) in Web Installer host field

IPv4 Address Only

IPv4 addresses with the default port work the same way. Since the network setup uses a dual-stack configuration with IPv6, no new installation is required. The test is once again automated with:

host=("10.0.0.11" "10.0.0.11" "10.0.0.12" "10.0.0.12" "10.0.0.13")
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")

for i in "${!types[@]}"; do
  docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: '${types[$i]}'/\" -e \"s/db_host: '.*'/db_host: '${host[$i]}'/\" -e \"s/db_port: '.*'/db_port: ''/\" /jbt/branch_44/cypress.config.mjs"
  scripts/test 44 system novnc install/Installation.cy.js
  scripts/test 44 system novnc
done

Afterward, again the logs are checked for errors:

tail -5 logs/*
  • ✅ All tests passed successfully with using e.g. 10.0.0.11 in Web Installer host field

Hostname and Port Number

Same procedure, using Cypress container id hostname 9a7562bf16dc and port forwardings:

ports=("4711" "4711" "4712" "4712" "4713")
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")

for i in "${!types[@]}"; do
  docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: '${types[$i]}'/\" -e \"s/db_host: '.*'/db_host: '9a7562bf16dc'/\" -e \"s/db_port: '.*'/db_port: '${ports[$i]}'/\" /jbt/branch_44/cypress.config.mjs"
  scripts/test 44 system novnc install/Installation.cy.js
  scripts/test 44 system novnc
done

Afterward, again the logs are checked for errors:

tail -5 logs/*
  • ✅ All tests passed successfully with using e.g. 9a7562bf16dc:4711 in Web Installer host field
  • 👉 First tests with jbt_cypress as the hostname for the Cypress container failed with PostgreSQL:
    could not translate host name "jbt_cypress:4713" to address
    The reason is that underscores are not valid characters in hostnames.
    As a result, JBT will need to update all hostnames. e.g. from jbt_cypressjbt-cypress 😱

IPv4 Address and Port Number

Same procedure, using Cypress container IPv4 address 10.0.0.7 and the port forwardings:

ports=("4711" "4711" "4712" "4712" "4713")
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")

for i in "${!types[@]}"; do
  docker exec jbt_cypress bash -c "sed -i -e \"s/db_type: '.*'/db_type: '${types[$i]}'/\" -e \"s/db_host: '.*'/db_host: '10.0.0.7'/\" -e \"s/db_port: '.*'/db_port: '${ports[$i]}'/\" /jbt/branch_44/cypress.config.mjs"
  scripts/test 44 system novnc install/Installation.cy.js
  scripts/test 44 system novnc
done

Afterward, again the logs are checked for errors:

tail -5 logs/*
  • ✅ All tests passed successfully with using e.g. 10.0.0.7:4711 in Web Installer host field

@muhme muhme changed the title Wrap IPv6 in brackets [ ] if port is specified. Wrap IPv6 address in brackets [ ] if needed Sep 7, 2024
* Update README.md

Correcting image file name

* Use absolute URL to see image in NPM README too
@muhme muhme force-pushed the install-joomla-with-db-port branch from dfb99c9 to f5455d5 Compare September 30, 2024 13:11
@muhme muhme marked this pull request as ready for review October 8, 2024 15:37
@laoneo laoneo merged commit 9dee4e5 into joomla-projects:main Oct 20, 2024
@laoneo
Copy link
Contributor

laoneo commented Oct 20, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants