Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21cc07bd48 | ||
|
|
902545bdb4 | ||
|
|
ea3cd5ef30 | ||
|
|
9010e1551f | ||
|
|
c05c47187a | ||
|
|
9ee6c3c5cf | ||
|
|
a391fa88dc | ||
|
|
59d285f2f1 | ||
|
|
3eaa1dc5cd | ||
|
|
6de1077806 | ||
|
|
eb8ea7d8a6 | ||
|
|
b94af2bf3a |
@@ -1,6 +1,6 @@
|
||||
# dokku postgres [](https://travis-ci.org/dokku/dokku-postgres) [](https://webchat.freenode.net/?channels=dokku)
|
||||
|
||||
Official postgres plugin for dokku. Currently defaults to installing [postgres 10.2](https://hub.docker.com/_/postgres/).
|
||||
Official postgres plugin for dokku. Currently defaults to installing [postgres 10.4](https://hub.docker.com/_/postgres/).
|
||||
|
||||
## requirements
|
||||
|
||||
@@ -46,6 +46,7 @@ postgres:start <name> Start a previously stopped postgres service
|
||||
postgres:stop <name> Stop a running postgres service
|
||||
postgres:unexpose <name> Unexpose a previously exposed postgres service
|
||||
postgres:unlink <name> <app> Unlink the postgres service from the app
|
||||
postgres:upgrade <name> Upgrade service <service> to the specified version
|
||||
```
|
||||
|
||||
## usage
|
||||
@@ -59,7 +60,7 @@ dokku postgres:create lolipop
|
||||
# it *must* be compatible with the
|
||||
# official postgres image
|
||||
export POSTGRES_IMAGE="postgres"
|
||||
export POSTGRES_IMAGE_VERSION="10.2"
|
||||
export POSTGRES_IMAGE_VERSION="10.4"
|
||||
dokku postgres:create lolipop
|
||||
|
||||
# you can also specify custom environment
|
||||
@@ -184,7 +185,7 @@ OR
|
||||
|
||||
## upgrade/downgrade
|
||||
|
||||
At the moment a database can’t be upgraded (or downgraded) inplace. Instead a clone has to be made, like this:
|
||||
At the moment a database can’t be upgraded (or downgraded) inplace. Instead a clone has to be made, like this:
|
||||
|
||||
```shell
|
||||
# Our original DB using PG 9.5
|
||||
@@ -267,7 +268,7 @@ dokku postgres:connect db < ./dump.sql
|
||||
## Security
|
||||
|
||||
The connection to the database is done over SSL. A self-signed certificate is
|
||||
automatically generated when creating the service. It can be replaced by a
|
||||
automatically generated when creating the service. It can be replaced by a
|
||||
custom certificate by overwriting the `server.crt` and `server.key` files in
|
||||
`/var/lib/dokku/services/postgres/<DB_NAME>/data`.
|
||||
The `server.key` must be chmoded to 600 and must be owned by the postgres user
|
||||
|
||||
@@ -273,6 +273,18 @@ service_backup_unset_encryption() {
|
||||
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT"
|
||||
}
|
||||
|
||||
service_container_rm() {
|
||||
declare desc="Stops a service and removes the running container"
|
||||
declare SERVICE="$1"
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
|
||||
service_stop "$SERVICE"
|
||||
dokku_log_verbose_quiet "Removing container"
|
||||
if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then
|
||||
dokku_log_fail "Unable to remove container for service $SERVICE"
|
||||
fi
|
||||
}
|
||||
|
||||
service_enter() {
|
||||
declare desc="enters running app container of specified proc type"
|
||||
declare SERVICE="$1" && shift 1
|
||||
@@ -300,6 +312,17 @@ service_exposed_ports() {
|
||||
done
|
||||
}
|
||||
|
||||
service_image_exists() {
|
||||
declare desc="Checks if the current image exists"
|
||||
local IMAGE="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||
|
||||
if [[ "$(docker images -q "$IMAGE" 2> /dev/null)" == "" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
service_info() {
|
||||
declare desc="Retrieves information about a given service"
|
||||
declare SERVICE="$1" INFO_FLAG="$2"
|
||||
|
||||
2
config
2
config
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
export POSTGRES_IMAGE=${POSTGRES_IMAGE:="postgres"}
|
||||
export POSTGRES_IMAGE_VERSION=${POSTGRES_IMAGE_VERSION:="10.2"}
|
||||
export POSTGRES_IMAGE_VERSION=${POSTGRES_IMAGE_VERSION:="10.4"}
|
||||
export POSTGRES_ROOT=${POSTGRES_ROOT:="/var/lib/dokku/services/postgres"}
|
||||
export POSTGRES_HOST_ROOT=${POSTGRES_HOST_ROOT:=$POSTGRES_ROOT}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ service_create() {
|
||||
|
||||
service_parse_args "${@:2}"
|
||||
|
||||
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
|
||||
if ! service_image_exists "$SERVICE"; then
|
||||
if [[ "$PLUGIN_DISABLE_PULL" == "true" ]]; then
|
||||
dokku_log_warn "${PLUGIN_DISABLE_PULL_VARIABLE} environment variable detected. Not running pull command." 1>&2
|
||||
dokku_log_warn " docker pull ${IMAGE}" 1>&2
|
||||
@@ -130,14 +130,13 @@ service_start() {
|
||||
|
||||
dokku_log_info2_quiet "Starting container"
|
||||
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
|
||||
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
|
||||
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
||||
|
||||
if [[ -n $PREVIOUS_ID ]]; then
|
||||
docker start "$PREVIOUS_ID" > /dev/null
|
||||
service_port_unpause "$SERVICE"
|
||||
dokku_log_info2 "Container started"
|
||||
elif $IMAGE_EXISTS && [[ -n "$PASSWORD" ]]; then
|
||||
elif service_image_exists "$SERVICE" && [[ -n "$PASSWORD" ]]; then
|
||||
service_create_container "$SERVICE"
|
||||
else
|
||||
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku postgres service plugin"
|
||||
version = "1.3.0"
|
||||
version = "1.4.0"
|
||||
[plugin.config]
|
||||
|
||||
38
subcommands/upgrade
Executable file
38
subcommands/upgrade
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_BASE_PATH/common/functions"
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||
|
||||
service-upgrade-cmd() {
|
||||
#E you can upgrade an existing service to a new image or image-version
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:upgrade lolipop
|
||||
#A service, service to run command against
|
||||
#F -c|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
|
||||
#F -i|--image IMAGE, the image name to start the service with
|
||||
#F -i|--image-version IMAGE_VERSION, the image version to start the service with
|
||||
declare desc="upgrade service <service> to the specified versions"
|
||||
local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||
declare SERVICE="$1" CLONE_FLAGS_LIST="${@:2}"
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
|
||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||
local ID="$(cat "$SERVICE_ROOT/ID")"
|
||||
is_container_status "$ID" "Running" || dokku_log_fail "Service ${SERVICE} container is not running"
|
||||
|
||||
service_parse_args "${@:2}"
|
||||
|
||||
if ! service_image_exists "$SERVICE"; then
|
||||
dokku_log_fail "Unable to proceed with upgrade, image ${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION} does not exist"
|
||||
fi
|
||||
|
||||
dokku_log_info2 "Upgrading $SERVICE to $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||
dokku_log_info2 "Stopping $SERVICE"
|
||||
service_container_rm "$SERVICE"
|
||||
service_start "$SERVICE" "${@:2}"
|
||||
dokku_log_info2 "Done"
|
||||
}
|
||||
|
||||
service-upgrade-cmd "$@"
|
||||
@@ -22,7 +22,7 @@ case "$1" in
|
||||
echo "mongo 3.2.9 12eadb136159 2 days ago 291.1 MB"
|
||||
echo "mysql 5.7.12 57d56ac47bed 2 days ago 321.3 MB"
|
||||
echo "nats 0.9.4 9216d5a4eec8 2 days ago 109.3 MB"
|
||||
echo "postgres 10.2 6412eb70175e 2 days ago 265.7 MB"
|
||||
echo "postgres 10.4 6412eb70175e 2 days ago 265.7 MB"
|
||||
echo "rabbitmq 3.6.5-management 327b803301e9 2 days ago 143.5 MB"
|
||||
echo "redis 3.2.3 9216d5a4eec8 2 days ago 109.3 MB"
|
||||
echo "rethinkdb 2.3.4 f27010a550ec 2 days ago 196.3 MB"
|
||||
@@ -71,7 +71,7 @@ case "$1" in
|
||||
echo 'c0f74fc90377 mongo:3.2.9 "/entrypoint.sh mong" 11 seconds ago Up 10 seconds 27017/tcp dokku.mongo.l'
|
||||
echo '0f33b1c86da9 mysql:5.7.12 "/entrypoint.sh mysq" 11 seconds ago Up 10 seconds 3306/tcp dokku.mysql.l'
|
||||
echo '9f10b6dc12d5 nats:0.9.4 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 4222/tcp dokku.nats.l'
|
||||
echo '7f899b723c08 postgres:10.2 "/docker-entrypoint." 11 seconds ago Up 10 seconds 5432/tcp dokku.postgres.l'
|
||||
echo '7f899b723c08 postgres:10.4 "/docker-entrypoint." 11 seconds ago Up 10 seconds 5432/tcp dokku.postgres.l'
|
||||
echo '5e50a462661e rabbitmq:3.6.5-management "/docker-entrypoint." 11 seconds ago Up 10 seconds 5672/tcp, 15672/tcp dokku.rabbitmq.l'
|
||||
echo 'c39ca00fa3c6 redis:3.2.3 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 6379/tcp dokku.redis.l'
|
||||
echo 'dc98c2939a80 rethinkdb:2.3.4 "rethinkdb --bind al" 11 seconds ago Up 10 seconds 8080/tcp, 28015/tcp, 29015/tcp dokku.rethinkdb.l'
|
||||
|
||||
@@ -11,20 +11,20 @@ teardown() {
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:list) with no exposed ports, no linked apps" {
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:list"
|
||||
assert_contains "${lines[*]}" "l postgres:10.2 running - -"
|
||||
assert_contains "${lines[*]}" "l postgres:10.4 running - -"
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:list) with exposed ports" {
|
||||
dokku "$PLUGIN_COMMAND_PREFIX:expose" l 4242
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:list"
|
||||
assert_contains "${lines[*]}" "l postgres:10.2 running 5432->4242 -"
|
||||
assert_contains "${lines[*]}" "l postgres:10.4 running 5432->4242 -"
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:list) with linked app" {
|
||||
dokku apps:create my_app
|
||||
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:list"
|
||||
assert_contains "${lines[*]}" "l postgres:10.2 running - my_app"
|
||||
assert_contains "${lines[*]}" "l postgres:10.4 running - my_app"
|
||||
dokku --force apps:destroy my_app
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user