From 87acd48ff624e795dcd71a0a46eb73eb9a71e4d9 Mon Sep 17 00:00:00 2001 From: Christopher Bennell Date: Wed, 17 Apr 2024 12:36:54 -0400 Subject: [PATCH 1/7] Add test case for mysqldump deprecation This is a test for a proposed change to lando/core, to address lando/mariadb#47. --- examples/tooling/.lando.yml | 22 ++++++ examples/tooling/README.md | 38 +++++++++++ examples/tooling/scripts/sql-export.sh | 93 ++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 examples/tooling/.lando.yml create mode 100644 examples/tooling/README.md create mode 100755 examples/tooling/scripts/sql-export.sh diff --git a/examples/tooling/.lando.yml b/examples/tooling/.lando.yml new file mode 100644 index 0000000..d815920 --- /dev/null +++ b/examples/tooling/.lando.yml @@ -0,0 +1,22 @@ +name: lando-mariadb-tooling +services: + database: + type: mariadb:11.3 +tooling: + 'db-export-test [file]': + service: :host + cmd: bash ./scripts/sql-export.sh + user: 'root' + options: + host: + description: The database service to use + default: database + alias: + - h + stdout: + description: Dump database to stdout + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/mariadb": ../.. diff --git a/examples/tooling/README.md b/examples/tooling/README.md new file mode 100644 index 0000000..5a03a53 --- /dev/null +++ b/examples/tooling/README.md @@ -0,0 +1,38 @@ +MariaDB Example +=============== + +This example exists primarily to test the following documentation: + +* [MariaDB Service](https://docs.devwithlando.io/tutorials/mariadb.html) + +Start up tests +-------------- + +Run the following commands to get up and running with this example. + +```bash +# Should start up successfully +lando poweroff +lando start +``` + +Verification commands +--------------------- + +Run the following commands to validate things are rolling as they should. + +```bash +# Should not see deprecation warning on db-export +lando db-export-test | ( ! grep "Deprecated" ) +``` + +Destroy tests +------------- + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be destroyed with success +lando destroy -y +lando poweroff +``` diff --git a/examples/tooling/scripts/sql-export.sh b/examples/tooling/scripts/sql-export.sh new file mode 100755 index 0000000..70b142d --- /dev/null +++ b/examples/tooling/scripts/sql-export.sh @@ -0,0 +1,93 @@ +#!/bin/bash +set -e + +# Get the lando logger +. /helpers/log.sh + +# Set the module +LANDO_MODULE="sqlexport" + +# Set generic things +HOST=localhost +SERVICE=$LANDO_SERVICE_NAME +STDOUT=false + +# Get type-specific config +if [[ ${POSTGRES_DB} != '' ]]; then + DATABASE=${POSTGRES_DB:-database} + PORT=${LANDO_DB_EXPORT_PORT:-5432} + USER=${LANDO_DB_EXPORT_USER:-postgres} +else + DATABASE=${MYSQL_DATABASE:-database} + PORT=${LANDO_DB_EXPORT_PORT:-3306} + USER=${LANDO_DB_EXPORT_USER:-root} +fi + +# Set the default filename +FILE=${DATABASE}.`date +"%Y-%m-%d-%s"`.sql + +# PARSE THE ARGZZ +# TODO: compress the mostly duplicate code below? +while (( "$#" )); do + case "$1" in + # This doesn't do anything anymore + # we just keep it around for option validation + -h|--host|--host=*) + if [ "${1##--host=}" != "$1" ]; then + shift + else + shift 2 + fi + ;; + --stdout) + STDOUT=true + shift + ;; + --) + shift + break + ;; + -*|--*=) + shift + ;; + *) + if [[ "$1" = /* ]]; then + FILE="${1//\\//}" + else + FILE="$(pwd)/${1//\\//}" + fi + shift + ;; + esac +done + +# Get type-specific dump cpmmand +if [[ ${POSTGRES_DB} != '' ]]; then + DUMPER="pg_dump postgresql://$USER@localhost:$PORT/$DATABASE" +elif [[ ${MARIADB_DATABASE} != '' && -x $(command -v mariadb-dump) ]]; then + DUMPER="mariadb-dump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}" +else + DUMPER="mysqldump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}" +fi + +# Do the dump to stdout +if [ "$STDOUT" == "true" ]; then + $DUMPER +else + # Inform the user of things + echo "Preparing to export $FILE from database '$DATABASE' on service '$SERVICE' as user $USER..." + + # Clean up last dump before we dump again + unalias rm 2> /dev/null || true + rm -f ${FILE} 2> /dev/null + $DUMPER > ${FILE} || { rm -f ${FILE}; lando_red "Failed to create file: ${FILE}"; exit 1; } + + # Gzip the mysql database dump file + gzip $FILE + # Reset perms on linux + if [ "$LANDO_HOST_OS" = "linux" ] && [ $(id -u) = 0 ]; then + chown $LANDO_HOST_UID:$LANDO_HOST_GID "${FILE}.gz" + fi + # Report + lando_green "Success ${FILE}.gz was created!" +fi From dc4eff72c730bfca8d56e9182b99103c08302bdb Mon Sep 17 00:00:00 2001 From: Christopher Bennell Date: Thu, 18 Apr 2024 09:09:55 -0400 Subject: [PATCH 2/7] Improve mysqldump deprecation test Make better use of `grep` in the test, and direct output of dump command to STDOUT so the test doesn't generate export files. --- examples/tooling/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tooling/README.md b/examples/tooling/README.md index 5a03a53..334a666 100644 --- a/examples/tooling/README.md +++ b/examples/tooling/README.md @@ -23,7 +23,7 @@ Run the following commands to validate things are rolling as they should. ```bash # Should not see deprecation warning on db-export -lando db-export-test | ( ! grep "Deprecated" ) +lando db-export-test --stdout | grep -vz "Deprecated" ``` Destroy tests From 9bdeb186ff67c0228815b5895700a1f53cdf2f7a Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 11 Jun 2024 13:54:56 -0700 Subject: [PATCH 3/7] #47: Test a db-export type tooling command. --- examples/tooling/.lando.yml | 2 +- examples/tooling/scripts/sql-export.sh | 93 -------------------------- 2 files changed, 1 insertion(+), 94 deletions(-) delete mode 100755 examples/tooling/scripts/sql-export.sh diff --git a/examples/tooling/.lando.yml b/examples/tooling/.lando.yml index d815920..7e1d33f 100644 --- a/examples/tooling/.lando.yml +++ b/examples/tooling/.lando.yml @@ -5,7 +5,7 @@ services: tooling: 'db-export-test [file]': service: :host - cmd: bash ./scripts/sql-export.sh + cmd: '/helpers/sql-export.sh' user: 'root' options: host: diff --git a/examples/tooling/scripts/sql-export.sh b/examples/tooling/scripts/sql-export.sh deleted file mode 100755 index 70b142d..0000000 --- a/examples/tooling/scripts/sql-export.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash -set -e - -# Get the lando logger -. /helpers/log.sh - -# Set the module -LANDO_MODULE="sqlexport" - -# Set generic things -HOST=localhost -SERVICE=$LANDO_SERVICE_NAME -STDOUT=false - -# Get type-specific config -if [[ ${POSTGRES_DB} != '' ]]; then - DATABASE=${POSTGRES_DB:-database} - PORT=${LANDO_DB_EXPORT_PORT:-5432} - USER=${LANDO_DB_EXPORT_USER:-postgres} -else - DATABASE=${MYSQL_DATABASE:-database} - PORT=${LANDO_DB_EXPORT_PORT:-3306} - USER=${LANDO_DB_EXPORT_USER:-root} -fi - -# Set the default filename -FILE=${DATABASE}.`date +"%Y-%m-%d-%s"`.sql - -# PARSE THE ARGZZ -# TODO: compress the mostly duplicate code below? -while (( "$#" )); do - case "$1" in - # This doesn't do anything anymore - # we just keep it around for option validation - -h|--host|--host=*) - if [ "${1##--host=}" != "$1" ]; then - shift - else - shift 2 - fi - ;; - --stdout) - STDOUT=true - shift - ;; - --) - shift - break - ;; - -*|--*=) - shift - ;; - *) - if [[ "$1" = /* ]]; then - FILE="${1//\\//}" - else - FILE="$(pwd)/${1//\\//}" - fi - shift - ;; - esac -done - -# Get type-specific dump cpmmand -if [[ ${POSTGRES_DB} != '' ]]; then - DUMPER="pg_dump postgresql://$USER@localhost:$PORT/$DATABASE" -elif [[ ${MARIADB_DATABASE} != '' && -x $(command -v mariadb-dump) ]]; then - DUMPER="mariadb-dump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}" -else - DUMPER="mysqldump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}" -fi - -# Do the dump to stdout -if [ "$STDOUT" == "true" ]; then - $DUMPER -else - # Inform the user of things - echo "Preparing to export $FILE from database '$DATABASE' on service '$SERVICE' as user $USER..." - - # Clean up last dump before we dump again - unalias rm 2> /dev/null || true - rm -f ${FILE} 2> /dev/null - $DUMPER > ${FILE} || { rm -f ${FILE}; lando_red "Failed to create file: ${FILE}"; exit 1; } - - # Gzip the mysql database dump file - gzip $FILE - # Reset perms on linux - if [ "$LANDO_HOST_OS" = "linux" ] && [ $(id -u) = 0 ]; then - chown $LANDO_HOST_UID:$LANDO_HOST_GID "${FILE}.gz" - fi - # Report - lando_green "Success ${FILE}.gz was created!" -fi From 4f1cb28aee884453a7fb3f431be177e0b51d3bc4 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 11 Jun 2024 13:55:39 -0700 Subject: [PATCH 4/7] #47: Make sure we actually add the test. --- .github/workflows/pr-mariadb-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-mariadb-tests.yml b/.github/workflows/pr-mariadb-tests.yml index a36060b..8a17ac2 100644 --- a/.github/workflows/pr-mariadb-tests.yml +++ b/.github/workflows/pr-mariadb-tests.yml @@ -34,6 +34,7 @@ jobs: - examples/11.2 - examples/11.3 - examples/custom + - examples/tooling steps: - name: Checkout code uses: actions/checkout@v3 From 8c62b22db788ccb6a86d1d4f35337e93fec1585a Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 11 Jun 2024 14:39:37 -0700 Subject: [PATCH 5/7] #47: Better name for the test. --- examples/tooling/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tooling/README.md b/examples/tooling/README.md index 334a666..cc9b196 100644 --- a/examples/tooling/README.md +++ b/examples/tooling/README.md @@ -1,5 +1,5 @@ -MariaDB Example -=============== +MariaDB Tooling Example +======================= This example exists primarily to test the following documentation: From 4fab896869c286affdf368ea4c8b68d98b0fe872 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 11 Jun 2024 15:13:47 -0700 Subject: [PATCH 6/7] Make checklinks happy. --- docs/config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index 5b8ce6f..fd9baa1 100644 --- a/docs/config.md +++ b/docs/config.md @@ -5,9 +5,9 @@ description: Learn how to configure the Lando MariaDB service. # Configuration -Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/core/v3/lando-service.html) to get a good handle on how the magicks work. +Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/core/v3/services/lando.html) to get a good handle on how the magicks work. -Also note that options, in addition to the [build steps](https://docs.lando.dev/core/v3/lando-service.html#build-steps) and [overrides](https://docs.lando.dev/core/v3/lando-service.html#overrides) that are available to every service, are shown below: +Also note that options, in addition to the [build steps](https://docs.lando.dev/core/v3/services/lando.html#build-steps) and [overrides](https://docs.lando.dev/core/v3/services/lando.html#overrides) that are available to every service, are shown below: ::: warning Be careful when switching database type, version or credentials! You should be careful switching database `type`, `version` or `creds`. From 162a2599361801a8bc80085ca31e0305e52642e4 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 11 Jun 2024 15:53:44 -0700 Subject: [PATCH 7/7] Make checklinks happy. --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 3a633eb..18a761e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,7 +8,7 @@ next: ./config.html [MariaDB](https://mariadb.org/) is a very common database server which is *EXTREMELY* similar to MySQL but has a guarantee of being open source. -You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/core/v3/lando-service.html) top-level config in your [Landofile](https://docs.lando.dev/core/v3). +You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/core/v3/services/lando.html) top-level config in your [Landofile](https://docs.lando.dev/core/v3). ```yaml services: @@ -27,7 +27,7 @@ services: * [10.5](https://hub.docker.com/r/bitnami/mariadb/tags?name=10.5.) * [10.4](https://hub.docker.com/r/bitnami/mariadb/tags?name=10.4.) * **[10.3](https://hub.docker.com/r/bitnami/mariadb/tags?name=10.3.)** **(default)** -* [custom](https://docs.lando.dev/core/v3/lando-service.html#overrides) +* [custom](https://docs.lando.dev/core/v3/services/lando.html#overrides) ## Legacy versions