Last active
December 3, 2019 05:52
-
-
Save danakishi/576601f46f5762cced4b16c53fa0a446 to your computer and use it in GitHub Desktop.
Database config Kong Gateway v1.0 migrate to YAML config Kong Gateway v1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
message() { | |
echo -e "\033[1;39m$1\033[0m" | |
} | |
# Constants | |
DB_DUMP_FILENAME="maindb.dump" | |
DOCKER_NETWORK="kong-net" | |
DB_CONTAINER_NAME="kong-database" | |
message "Create docker network" | |
docker network create $DOCKER_NETWORK | |
message "Create database container" | |
docker run -d --health-cmd "pg_isready -U postgres" --health-interval 30ms --name $DB_CONTAINER_NAME --network=$DOCKER_NETWORK -e "POSTGRES_USER=kong" -e "POSTGRES_PASSWORD=kong" -e "POSTGRES_DB=kong" postgres:9.5 | |
while [ $(docker inspect -f {{.State.Health.Status}} $DB_CONTAINER_NAME) != "healthy" ] | |
do | |
sleep 0.5 | |
done | |
message "Import dump Kong v1.0 to database container" | |
docker cp $DB_DUMP_FILENAME kong-database:/db.dump | |
docker exec kong-database /bin/bash -c "export PGPASSWORD=kong && /usr/bin/pg_restore -U kong -d kong < /db.dump" | |
message "Run migrations Kong v1.3" | |
docker run --rm --link $DB_CONTAINER_NAME:$DB_CONTAINER_NAME --network=$DOCKER_NETWORK -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=$DB_CONTAINER_NAME" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=kong" kong:1.3 kong migrations up | |
docker run --rm --link $DB_CONTAINER_NAME:$DB_CONTAINER_NAME --network=$DOCKER_NETWORK -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=$DB_CONTAINER_NAME" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=kong" kong:1.3 kong migrations finish | |
message "Export dump Kong v1.3 to YAML file" | |
KONG13=$(docker run -d --link $DB_CONTAINER_NAME:$DB_CONTAINER_NAME --network=$DOCKER_NETWORK -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=$DB_CONTAINER_NAME" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=kong" kong:1.3 kong start) | |
docker exec $KONG13 kong config db_export dump.yml | |
docker cp $KONG13:/dump.yml dump.yml | |
message "Clean" | |
docker stop $KONG13 | |
docker rm $KONG13 | |
docker stop $DB_CONTAINER_NAME | |
docker rm $DB_CONTAINER_NAME | |
docker network rm $DOCKER_NETWORK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment