Skip to content

Commit

Permalink
feat(shell) add kx alias to export config
Browse files Browse the repository at this point in the history
also updates other aliases to first try the kong default file;
kong.yml, and adds an explanation when shelling into container
  • Loading branch information
Tieske committed Aug 31, 2022
1 parent e884efa commit af1de5b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kong-versions/nightly-ee/*
kong-versions/nightly/*
servroot
.pongo
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ 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
---
## 1.1.0 released 14-Jun-2022
Expand Down
1 change: 1 addition & 0 deletions assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions assets/kong_export.sh
Original file line number Diff line number Diff line change
@@ -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."
8 changes: 4 additions & 4 deletions assets/kong_migrations_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions assets/kong_start_dbless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions assets/pongo_profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

0 comments on commit af1de5b

Please sign in to comment.