diff --git a/.gitignore b/.gitignore index 5c27f5ac..f0a4f5ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ kong-versions/nightly-ee/* kong-versions/nightly/* servroot +.pongo diff --git a/README.md b/README.md index 16cdc366..c85370bb 100644 --- a/README.md +++ b/README.md @@ -801,6 +801,9 @@ The result should be a new PR on the Pongo repo. * Changed nightly-ee image to the new `master` tag [#300](https://github.com/Kong/kong-pongo/pull/300) + * Added new alias "kx" for export, and added explanation when shelling + [#311](https://github.com/Kong/kong-pongo/pull/311) + --- ## 1.1.0 released 14-Jun-2022 diff --git a/assets/Dockerfile b/assets/Dockerfile index 90bee12c..2359f032 100644 --- a/assets/Dockerfile +++ b/assets/Dockerfile @@ -13,6 +13,7 @@ COPY assets/default-pongo-setup.sh /pongo/default-pongo-setup.sh COPY assets/pongo_pack.lua /pongo/pongo_pack.lua COPY assets/kong_migrations_start.sh /pongo/kong_migrations_start.sh COPY assets/kong_start_dbless.sh /pongo/kong_start_dbless.sh +COPY assets/kong_export.sh /pongo/kong_export.sh COPY assets/parse_git_branch.sh /pongo/parse_git_branch.sh COPY assets/pongo_profile.sh /etc/profile.d/pongo_profile.sh diff --git a/assets/kong_export.sh b/assets/kong_export.sh new file mode 100755 index 00000000..65a1bf07 --- /dev/null +++ b/assets/kong_export.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# export the kong configuration to "kong.yml" + + +echo '' +if [ -f /kong-plugin/kong.yml ]; then + if [ ! "$1" = "-y" ]; then + echo "The file \"kong.yml\" already exists, overwrite? (y/n, or use \"-y\") " + old_stty_cfg=$(stty -g) + stty raw -echo + answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) + stty "$old_stty_cfg" + if ! echo "$answer" | grep -iq "^y" ;then + exit 0 + fi + fi +fi + + +echo "Exporting declarative config to \"kong.yml\"..." +kong config db_export /kong-plugin/kong.yml +if [ $? -ne 0 ]; then + echo "Failed to export to \"kong.yml\"" + exit 1 +fi +echo "Export to \"kong.yml\" complete." diff --git a/assets/kong_migrations_start.sh b/assets/kong_migrations_start.sh index 9f46d47d..5d6a0c74 100755 --- a/assets/kong_migrations_start.sh +++ b/assets/kong_migrations_start.sh @@ -7,16 +7,16 @@ kong migrations bootstrap --force echo '' unset KMS_FILENAME -if [ -f /kong-plugin/kong.yaml ]; then - KMS_FILENAME=kong.yaml -elif [ -f /kong-plugin/kong.yml ]; then +if [ -f /kong-plugin/kong.yml ]; then KMS_FILENAME=kong.yml +elif [ -f /kong-plugin/kong.yaml ]; then + KMS_FILENAME=kong.yaml elif [ -f /kong-plugin/kong.json ]; then KMS_FILENAME=kong.json fi if [ "$KMS_FILENAME" = "" ]; then - echo 'Declarative file "kong.yaml/yml/json" not found, skipping import' + echo 'Declarative file "kong.yml/yaml/json" not found, skipping import' else echo "Found \"$KMS_FILENAME\", importing declarative config..." kong config db_import /kong-plugin/$KMS_FILENAME diff --git a/assets/kong_start_dbless.sh b/assets/kong_start_dbless.sh index 16c93691..958e4c71 100755 --- a/assets/kong_start_dbless.sh +++ b/assets/kong_start_dbless.sh @@ -3,14 +3,14 @@ # will (re)start Kong DBless from a config file; kong.y(a)ml/json unset KDBL_FILENAME -if [ -f /kong-plugin/kong.yaml ]; then - KDBL_FILENAME=kong.yaml -elif [ -f /kong-plugin/kong.yml ]; then +if [ -f /kong-plugin/kong.yml ]; then KDBL_FILENAME=kong.yml +elif [ -f /kong-plugin/kong.yaml ]; then + KDBL_FILENAME=kong.yaml elif [ -f /kong-plugin/kong.json ]; then KDBL_FILENAME=kong.json else - echo 'Error: Declarative file "kong.yaml/yml/json" not found'; + echo 'Error: Declarative file "kong.yml/yaml/json" not found'; exit 1 fi diff --git a/assets/pongo_profile.sh b/assets/pongo_profile.sh index f33751b9..96bdf691 100755 --- a/assets/pongo_profile.sh +++ b/assets/pongo_profile.sh @@ -11,5 +11,17 @@ alias ks='kong restart' alias kp='kong stop' alias kms='/pongo/kong_migrations_start.sh' alias kdbl='/pongo/kong_start_dbless.sh' +alias kx='/pongo/kong_export.sh' PS1="\[\e[00m\]\[\033[1;34m\][$PS1_KONG_VERSION:\[\e[91m\]$PS1_REPO_NAME\$(/pongo/parse_git_branch.sh)\[\033[1;34m\]:\[\033[1;92m\]\w\[\033[1;34m\]]$\[\033[00m\] " + +echo "Welcome to the Pongo shell!" +echo "" +echo "Get started quickly with the following aliases/shortcuts:" +echo " kms - kong migrations start; wipe/initialize the database and start Kong clean," +echo " importing declarative configuration if available." +echo " kdbl - kong start dbless; start Kong in dbless mode, requires a declarative configuration." +echo " ks - kong start; starts Kong with the existing database contents (actually a restart)." +echo " kp - kong stop; stop Kong." +echo " kx - export the current Kong database to a declarative configuration file." +echo ""