Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1aae1afe5c | ||
|
|
3288779806 | ||
|
|
428e95ef08 | ||
|
|
0bd701736f | ||
|
|
03e4c519f1 | ||
|
|
0c04ad8dcb | ||
|
|
13eeed1582 | ||
|
|
b1cc1c7914 | ||
|
|
8701fe04e2 | ||
|
|
d654334225 | ||
|
|
409cd36b63 | ||
|
|
5a181a6a4c | ||
|
|
077aa4dc11 | ||
|
|
6ebdb98ac8 | ||
|
|
b7e092db39 | ||
|
|
3f338c7985 | ||
|
|
1cde514fba |
28
README.md
28
README.md
@@ -1,6 +1,6 @@
|
||||
# dokku postgres [](https://github.com/dokku/dokku-postgres/actions/workflows/ci.yml?query=branch%3Amaster) [](https://webchat.libera.chat/?channels=dokku)
|
||||
# dokku postgres [](https://github.com/dokku/dokku-postgres/actions/workflows/ci.yml?query=branch%3Amaster) [](https://webchat.libera.chat/?channels=dokku)
|
||||
|
||||
Official postgres plugin for dokku. Currently defaults to installing [postgres 14.4](https://hub.docker.com/_/postgres/).
|
||||
Official postgres plugin for dokku. Currently defaults to installing [postgres 14.5](https://hub.docker.com/_/postgres/).
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -41,6 +41,7 @@ postgres:linked <service> <app> # check if the postgres servi
|
||||
postgres:links <service> # list all apps linked to the postgres service
|
||||
postgres:list # list all postgres services
|
||||
postgres:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log(s) for this service
|
||||
postgres:pause <service> # pause a running postgres service
|
||||
postgres:promote <service> <app> # promote service <service> as DATABASE_URL in <app>
|
||||
postgres:restart <service> # graceful shutdown and restart of the postgres service container
|
||||
postgres:start <service> # start a previously stopped postgres service
|
||||
@@ -95,7 +96,7 @@ export POSTGRES_CUSTOM_ENV="USER=alpha;HOST=beta"
|
||||
dokku postgres:create lollipop
|
||||
```
|
||||
|
||||
Official Postgres docker images does not include postgis extension (amongst others). The following example creates a new postgres service using `postgis/postgis:13-3.1` image, which includes the `postgis` extension.
|
||||
Official Postgres "$DOCKER_BIN" image ls does not include postgis extension (amongst others). The following example creates a new postgres service using `postgis/postgis:13-3.1` image, which includes the `postgis` extension.
|
||||
|
||||
```shell
|
||||
dokku postgres:create postgis-database --image "postgis/postgis" --image-version "13-3.1"
|
||||
@@ -376,12 +377,25 @@ dokku postgres:start lollipop
|
||||
dokku postgres:stop <service>
|
||||
```
|
||||
|
||||
Stop the service and the running container:
|
||||
Stop the service and removes the running container:
|
||||
|
||||
```shell
|
||||
dokku postgres:stop lollipop
|
||||
```
|
||||
|
||||
### pause a running postgres service
|
||||
|
||||
```shell
|
||||
# usage
|
||||
dokku postgres:pause <service>
|
||||
```
|
||||
|
||||
Pause the running container for the service:
|
||||
|
||||
```shell
|
||||
dokku postgres:pause lollipop
|
||||
```
|
||||
|
||||
### graceful shutdown and restart of the postgres service container
|
||||
|
||||
```shell
|
||||
@@ -722,8 +736,8 @@ Remove the scheduled backup from cron:
|
||||
dokku postgres:backup-unschedule lollipop
|
||||
```
|
||||
|
||||
### Disabling `docker pull` calls
|
||||
### Disabling `docker image pull` calls
|
||||
|
||||
If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `POSTGRES_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.
|
||||
If you wish to disable the `docker image pull` calls that the plugin triggers, you may set the `POSTGRES_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.
|
||||
|
||||
Please ensure the proper images are in place when `docker pull` is disabled.
|
||||
Please ensure the proper images are in place when `docker image pull` is disabled.
|
||||
|
||||
@@ -35,7 +35,7 @@ def header(service):
|
||||
return " ".join(
|
||||
[
|
||||
f"# dokku {service}",
|
||||
f'[](https://github.com/dokku/dokku-{service}/actions/workflows/ci.yml?query=branch%3Amaster)',
|
||||
f'[](https://github.com/dokku/dokku-{service}/actions/workflows/ci.yml?query=branch%3Amaster)',
|
||||
f'[](https://webchat.libera.chat/?channels=dokku)',
|
||||
]
|
||||
)
|
||||
@@ -148,6 +148,7 @@ def usage_lifecycle(service, variable, alias, image, scheme, ports, options, uni
|
||||
"promote",
|
||||
"start",
|
||||
"stop",
|
||||
"pause",
|
||||
"restart",
|
||||
"upgrade",
|
||||
]
|
||||
@@ -222,11 +223,11 @@ def usage_docker_pull(service, variable, alias, image, scheme, ports, options, u
|
||||
service_prefix = service.upper()
|
||||
return "\n".join(
|
||||
[
|
||||
"### Disabling `docker pull` calls",
|
||||
"### Disabling `docker image pull` calls",
|
||||
"",
|
||||
f"If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.",
|
||||
f"If you wish to disable the `docker image pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.",
|
||||
"",
|
||||
"Please ensure the proper images are in place when `docker pull` is disabled.",
|
||||
"Please ensure the proper images are in place when `docker image pull` is disabled.",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ docker_ports_options() {
|
||||
get_container_ip() {
|
||||
declare desc="retrieve the ip address of a container"
|
||||
declare CONTAINER_ID="$1"
|
||||
docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$CONTAINER_ID" 2>/dev/null
|
||||
"$DOCKER_BIN" container inspect --format '{{ .NetworkSettings.IPAddress }}' "$CONTAINER_ID" 2>/dev/null
|
||||
}
|
||||
|
||||
get_database_name() {
|
||||
@@ -153,7 +153,7 @@ is_container_status() {
|
||||
declare desc="return 0 or 1 depending upon whether a given container has a certain status"
|
||||
declare CID="$1" STATUS="$2"
|
||||
local TEMPLATE="{{.State.$STATUS}}"
|
||||
local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" 2>/dev/null || true)
|
||||
local CONTAINER_STATUS=$("$DOCKER_BIN" container inspect -f "$TEMPLATE" "$CID" 2>/dev/null || true)
|
||||
|
||||
if [[ "$CONTAINER_STATUS" == "true" ]]; then
|
||||
return 0
|
||||
@@ -208,7 +208,7 @@ retry-docker-command() {
|
||||
local i=0 success=false
|
||||
until [ $i -ge 100 ]; do
|
||||
set +e
|
||||
suppress_output docker exec "$ID" sh -c "$COMMAND"
|
||||
suppress_output "$DOCKER_BIN" container exec "$ID" sh -c "$COMMAND"
|
||||
exit_code=$?
|
||||
set -e
|
||||
if [[ "$exit_code" == 0 ]]; then
|
||||
@@ -281,7 +281,7 @@ service_backup() {
|
||||
BACKUP_TMPDIR=$(mktemp -d --tmpdir)
|
||||
trap 'rm -rf "$BACKUP_TMPDIR" > /dev/null' RETURN INT TERM EXIT
|
||||
|
||||
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
"$DOCKER_BIN" container inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
|
||||
|
||||
(service_export "$SERVICE" >"${BACKUP_TMPDIR}/export")
|
||||
@@ -308,7 +308,7 @@ service_backup() {
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
docker run --rm $BACKUP_PARAMETERS "$PLUGIN_S3BACKUP_IMAGE"
|
||||
"$DOCKER_BIN" container run --rm $BACKUP_PARAMETERS "$PLUGIN_S3BACKUP_IMAGE"
|
||||
}
|
||||
|
||||
service_commit_config() {
|
||||
@@ -443,16 +443,16 @@ service_container_rm() {
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
local ID
|
||||
|
||||
service_stop "$SERVICE"
|
||||
ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
service_pause "$SERVICE"
|
||||
ID=$("$DOCKER_BIN" container ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
# this may be 'true' in tests...
|
||||
if [[ -z "$ID" ]] || [[ "$ID" == "true" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
dokku_log_verbose_quiet "Removing container"
|
||||
docker update --restart=no "$SERVICE_NAME" >/dev/null 2>&1
|
||||
if ! docker rm "$SERVICE_NAME" >/dev/null 2>&1; then
|
||||
"$DOCKER_BIN" container update --restart=no "$SERVICE_NAME" >/dev/null 2>&1
|
||||
if ! "$DOCKER_BIN" container rm "$SERVICE_NAME" >/dev/null 2>&1; then
|
||||
dokku_log_fail "Unable to remove container for service $SERVICE"
|
||||
fi
|
||||
}
|
||||
@@ -470,13 +470,13 @@ service_enter() {
|
||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||
local ID="$(cat "$SERVICE_ROOT/ID")"
|
||||
|
||||
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
"$DOCKER_BIN" container inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
|
||||
|
||||
local EXEC_CMD=""
|
||||
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
|
||||
# shellcheck disable=SC2086
|
||||
docker exec $DOKKU_RUN_OPTS $ID $EXEC_CMD "${@:-/bin/bash}"
|
||||
"$DOCKER_BIN" container exec $DOKKU_RUN_OPTS $ID $EXEC_CMD "${@:-/bin/bash}"
|
||||
}
|
||||
|
||||
service_exists() {
|
||||
@@ -501,15 +501,21 @@ service_exposed_ports() {
|
||||
|
||||
service_image_exists() {
|
||||
declare desc="check if the current image exists"
|
||||
declare SERVICE="$1"
|
||||
declare SERVICE="$1" PLUGIN_IMAGE="${2:-$PLUGIN_IMAGE}" PLUGIN_IMAGE_VERSION="${3:-$PLUGIN_IMAGE_VERSION}"
|
||||
local plugin_image="$PLUGIN_IMAGE"
|
||||
local plugin_image_version="$PLUGIN_IMAGE_VERSION"
|
||||
|
||||
[[ -f "$SERVICE_ROOT/IMAGE" ]] && plugin_image="$(cat "$SERVICE_ROOT/IMAGE")"
|
||||
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && plugin_image_version="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||
if [[ -z "$PLUGIN_IMAGE" ]] && [[ -f "$SERVICE_ROOT/IMAGE" ]]; then
|
||||
plugin_image="$(cat "$SERVICE_ROOT/IMAGE")"
|
||||
fi
|
||||
|
||||
if [[ -z "$PLUGIN_IMAGE_VERSION" ]] && [[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]]; then
|
||||
plugin_image_version="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||
fi
|
||||
|
||||
local IMAGE="$plugin_image:$plugin_image_version"
|
||||
|
||||
if [[ "$(docker images -q "$IMAGE" 2>/dev/null)" == "" ]]; then
|
||||
if [[ "$("$DOCKER_BIN" image ls -q "$IMAGE" 2>/dev/null)" == "" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -668,11 +674,11 @@ service_logs() {
|
||||
DOKKU_LOGS_ARGS+=" --follow"
|
||||
fi
|
||||
|
||||
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
"$DOCKER_BIN" container inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
|
||||
is_container_status "$ID" "Running" || dokku_log_warn "Service logs may not be output as service is not running"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
docker logs $DOKKU_LOGS_ARGS "$ID" 2>&1
|
||||
"$DOCKER_BIN" container logs $DOKKU_LOGS_ARGS "$ID" 2>&1
|
||||
}
|
||||
|
||||
service_parse_args() {
|
||||
@@ -790,7 +796,7 @@ service_port_pause() {
|
||||
fi
|
||||
|
||||
local GREP_NAME="^/${EXPOSED_NAME}$"
|
||||
local CONTAINER_NAME="$(docker ps -f name="$GREP_NAME" --format "{{.Names}}")"
|
||||
local CONTAINER_NAME="$("$DOCKER_BIN" container ps -f name="$GREP_NAME" --format "{{.Names}}")"
|
||||
if [[ -z "$CONTAINER_NAME" ]]; then
|
||||
if [[ "$LOG_FAIL" == "true" ]]; then
|
||||
dokku_log_info1 "Service $SERVICE unexposed"
|
||||
@@ -799,8 +805,8 @@ service_port_pause() {
|
||||
return
|
||||
fi
|
||||
|
||||
docker stop "$EXPOSED_NAME" >/dev/null 2>&1 || true
|
||||
docker rm "$EXPOSED_NAME" >/dev/null 2>&1 || true
|
||||
"$DOCKER_BIN" container stop "$EXPOSED_NAME" >/dev/null 2>&1 || true
|
||||
"$DOCKER_BIN" container rm "$EXPOSED_NAME" >/dev/null 2>&1 || true
|
||||
if [[ "$LOG_FAIL" == "true" ]]; then
|
||||
dokku_log_info1 "Service $SERVICE unexposed"
|
||||
fi
|
||||
@@ -840,7 +846,7 @@ service_port_unpause() {
|
||||
echo "${PORTS[@]}" >"$PORT_FILE"
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
docker run -d --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" --name "$EXPOSED_NAME" $(docker_ports_options "${PORTS[@]}") --restart always --label dokku=ambassador --label "dokku.ambassador=$PLUGIN_COMMAND_PREFIX" "$PLUGIN_AMBASSADOR_IMAGE" >/dev/null
|
||||
"$DOCKER_BIN" container run -d --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" --name "$EXPOSED_NAME" $(docker_ports_options "${PORTS[@]}") --restart always --label dokku=ambassador --label "dokku.ambassador=$PLUGIN_COMMAND_PREFIX" "$PLUGIN_AMBASSADOR_IMAGE" >/dev/null
|
||||
if [[ "$LOG_FAIL" == "true" ]]; then
|
||||
dokku_log_info1 "Service $SERVICE exposed on port(s) [container->host]: $(service_exposed_ports "$SERVICE")"
|
||||
fi
|
||||
@@ -891,24 +897,24 @@ service_status() {
|
||||
local ID="$(cat "$SERVICE_ROOT/ID")"
|
||||
local CONTAINER_STATUS
|
||||
|
||||
CONTAINER_STATUS=$(docker inspect -f "{{.State.Status}}" "$ID" 2>/dev/null || true)
|
||||
CONTAINER_STATUS=$("$DOCKER_BIN" container inspect -f "{{.State.Status}}" "$ID" 2>/dev/null || true)
|
||||
[[ -n "$CONTAINER_STATUS" ]] && echo "$CONTAINER_STATUS" && return 0
|
||||
echo "missing" && return 0
|
||||
}
|
||||
|
||||
service_stop() {
|
||||
declare desc="stop a running service"
|
||||
service_pause() {
|
||||
declare desc="pause a running service"
|
||||
declare SERVICE="$1"
|
||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
local ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
[[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0
|
||||
local ID=$("$DOCKER_BIN" container ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
[[ -z $ID ]] && dokku_log_warn "Service is already paused" && return 0
|
||||
|
||||
if [[ -n $ID ]]; then
|
||||
dokku_log_info2_quiet "Stopping container"
|
||||
docker stop "$SERVICE_NAME" >/dev/null
|
||||
dokku_log_info2_quiet "Pausing container"
|
||||
"$DOCKER_BIN" container stop "$SERVICE_NAME" >/dev/null
|
||||
service_port_pause "$SERVICE"
|
||||
dokku_log_verbose_quiet "Container stopped"
|
||||
dokku_log_verbose_quiet "Container paused"
|
||||
else
|
||||
dokku_log_verbose_quiet "No container exists for $SERVICE"
|
||||
fi
|
||||
@@ -949,7 +955,7 @@ service_version() {
|
||||
declare desc="display the running version for an image"
|
||||
declare SERVICE="$1"
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
docker inspect -f '{{.Config.Image}}' "$SERVICE_NAME" 2>/dev/null || true
|
||||
"$DOCKER_BIN" container inspect -f '{{.Config.Image}}' "$SERVICE_NAME" 2>/dev/null || true
|
||||
}
|
||||
|
||||
update_plugin_scheme_for_app() {
|
||||
|
||||
3
config
3
config
@@ -3,7 +3,8 @@ _DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
export POSTGRES_IMAGE=${POSTGRES_IMAGE:="$(awk -F '[ :]' '{print $2}' "${_DIR}/Dockerfile")"}
|
||||
export POSTGRES_IMAGE_VERSION=${POSTGRES_IMAGE_VERSION:="$(awk -F '[ :]' '{print $3}' "${_DIR}/Dockerfile")"}
|
||||
export POSTGRES_ROOT=${POSTGRES_ROOT:="$DOKKU_LIB_ROOT/services/postgres"}
|
||||
export POSTGRES_HOST_ROOT=${POSTGRES_HOST_ROOT:=$POSTGRES_ROOT}
|
||||
export DOKKU_LIB_HOST_ROOT=${DOKKU_LIB_HOST_ROOT:=$DOKKU_LIB_ROOT}
|
||||
export POSTGRES_HOST_ROOT=${POSTGRES_HOST_ROOT:="$DOKKU_LIB_HOST_ROOT/services/postgres"}
|
||||
|
||||
export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
|
||||
export PLUGIN_COMMAND_PREFIX="postgres"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Official Postgres docker images does not include postgis extension (amongst others). The following example creates a new postgres service using `postgis/postgis:13-3.1` image, which includes the `postgis` extension.
|
||||
Official Postgres "$DOCKER_BIN" image ls does not include postgis extension (amongst others). The following example creates a new postgres service using `postgis/postgis:13-3.1` image, which includes the `postgis` extension.
|
||||
|
||||
```shell
|
||||
dokku postgres:create postgis-database --image "postgis/postgis" --image-version "13-3.1"
|
||||
|
||||
30
functions
30
functions
@@ -17,7 +17,7 @@ service_connect() {
|
||||
local SERVICE_TTY_OPTS
|
||||
has_tty && SERVICE_TTY_OPTS="-t"
|
||||
|
||||
docker exec --env=LANG=C.UTF-8 --env=LC_ALL=C.UTF-8 -i $SERVICE_TTY_OPTS "$SERVICE_NAME" psql -h localhost -U postgres "$DATABASE_NAME"
|
||||
"$DOCKER_BIN" container exec --env=LANG=C.UTF-8 --env=LC_ALL=C.UTF-8 -i $SERVICE_TTY_OPTS "$SERVICE_NAME" psql -h localhost -U postgres "$DATABASE_NAME"
|
||||
}
|
||||
|
||||
service_create() {
|
||||
@@ -33,11 +33,11 @@ service_create() {
|
||||
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
|
||||
dokku_log_warn " docker image pull ${IMAGE}" 1>&2
|
||||
dokku_log_warn "$PLUGIN_SERVICE service creation failed"
|
||||
exit 1
|
||||
fi
|
||||
docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
|
||||
"$DOCKER_BIN" image pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
|
||||
fi
|
||||
|
||||
plugn trigger service-action pre-create "$PLUGIN_COMMAND_PREFIX" "$SERVICE"
|
||||
@@ -87,21 +87,21 @@ service_create_container() {
|
||||
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
|
||||
ID=$("$DOCKER_BIN" container run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
|
||||
echo "$ID" >"$SERVICE_ROOT/ID"
|
||||
|
||||
dokku_log_verbose_quiet "Waiting for container to be ready"
|
||||
docker run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" "$PLUGIN_WAIT_IMAGE" -p "$PLUGIN_DATASTORE_WAIT_PORT" >/dev/null
|
||||
"$DOCKER_BIN" container run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" "$PLUGIN_WAIT_IMAGE" -p "$PLUGIN_DATASTORE_WAIT_PORT" >/dev/null
|
||||
|
||||
dokku_log_verbose_quiet "Creating container database"
|
||||
docker exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists'
|
||||
"$DOCKER_BIN" container exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists'
|
||||
|
||||
dokku_log_verbose_quiet "Securing connection to database"
|
||||
service_stop "$SERVICE" >/dev/null
|
||||
docker run --rm -i -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" bash -s <"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts/enable_ssl.sh" &>/dev/null
|
||||
service_pause "$SERVICE" >/dev/null
|
||||
"$DOCKER_BIN" container run --rm -i -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" bash -s <"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts/enable_ssl.sh" &>/dev/null
|
||||
|
||||
PREVIOUS_ID=$(docker ps -aq --no-trunc --filter "status=exited" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
docker start "$PREVIOUS_ID" >/dev/null
|
||||
PREVIOUS_ID=$("$DOCKER_BIN" container ps -aq --no-trunc --filter "status=exited" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
"$DOCKER_BIN" container start "$PREVIOUS_ID" >/dev/null
|
||||
service_port_unpause "$SERVICE"
|
||||
|
||||
dokku_log_info2 "$PLUGIN_SERVICE container created: $SERVICE"
|
||||
@@ -116,7 +116,7 @@ service_export() {
|
||||
local PASSWORD="$(service_password "$SERVICE")"
|
||||
|
||||
[[ -n $SSH_TTY ]] && stty -opost
|
||||
docker exec "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_dump -Fc --no-acl --no-owner -h localhost -U postgres -w "$DATABASE_NAME"
|
||||
"$DOCKER_BIN" container exec "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_dump -Fc --no-acl --no-owner -h localhost -U postgres -w "$DATABASE_NAME"
|
||||
status=$?
|
||||
[[ -n $SSH_TTY ]] && stty opost
|
||||
exit $status
|
||||
@@ -133,7 +133,7 @@ service_import() {
|
||||
if [[ -t 0 ]]; then
|
||||
dokku_log_fail "No data provided on stdin."
|
||||
fi
|
||||
docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO --if-exists -d "$DATABASE_NAME" -U postgres -w
|
||||
"$DOCKER_BIN" container exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO --if-exists -d "$DATABASE_NAME" -U postgres -w
|
||||
}
|
||||
|
||||
service_start() {
|
||||
@@ -141,7 +141,7 @@ service_start() {
|
||||
local QUIET="$2"
|
||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
local ID=$(docker ps -aq --no-trunc --filter "status=running" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
local ID=$("$DOCKER_BIN" container ps -aq --no-trunc --filter "status=running" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
if [[ -n $ID ]]; then
|
||||
[[ -z $QUIET ]] && dokku_log_warn "Service is already started"
|
||||
if [[ ! -f "$SERVICE_ROOT/ID" ]] || [[ "$(cat "$SERVICE_ROOT/ID")" != "$ID" ]]; then
|
||||
@@ -152,11 +152,11 @@ service_start() {
|
||||
fi
|
||||
|
||||
dokku_log_info2_quiet "Starting container"
|
||||
local PREVIOUS_ID=$(docker ps -aq --no-trunc --filter "status=exited" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
local PREVIOUS_ID=$("$DOCKER_BIN" container ps -aq --no-trunc --filter "status=exited" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||
local PASSWORD="$(service_password "$SERVICE")"
|
||||
|
||||
if [[ -n $PREVIOUS_ID ]]; then
|
||||
docker start "$PREVIOUS_ID" >/dev/null
|
||||
"$DOCKER_BIN" container start "$PREVIOUS_ID" >/dev/null
|
||||
service_port_unpause "$SERVICE"
|
||||
dokku_log_info2 "Container started"
|
||||
elif service_image_exists "$SERVICE" && [[ -n "$PASSWORD" ]]; then
|
||||
|
||||
6
install
6
install
@@ -9,11 +9,11 @@ plugin-install() {
|
||||
declare IMAGE="$1"
|
||||
if [[ "$PLUGIN_DISABLE_PULL" == "true" ]]; then
|
||||
echo " ! ${PLUGIN_DISABLE_PULL_VARIABLE} environment variable detected. Not running pull command." 1>&2
|
||||
echo " ! docker pull ${IMAGE}" 1>&2
|
||||
echo " ! docker image pull ${IMAGE}" 1>&2
|
||||
return
|
||||
fi
|
||||
if [[ "$(docker images -q "${IMAGE}" 2>/dev/null)" == "" ]]; then
|
||||
docker pull "${IMAGE}"
|
||||
if [[ "$("$DOCKER_BIN" image ls -q "${IMAGE}" 2>/dev/null)" == "" ]]; then
|
||||
"$DOCKER_BIN" image pull "${IMAGE}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku postgres service plugin"
|
||||
version = "1.25.0"
|
||||
version = "1.27.0"
|
||||
[plugin.config]
|
||||
|
||||
@@ -46,7 +46,7 @@ service-destroy-cmd() {
|
||||
service_container_rm "$SERVICE"
|
||||
|
||||
dokku_log_verbose_quiet "Removing data"
|
||||
docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/config" "$PLUGIN_BUSYBOX_IMAGE" chmod 777 -R /config /data
|
||||
"$DOCKER_BIN" container run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/config" "$PLUGIN_BUSYBOX_IMAGE" chmod 777 -R /config /data
|
||||
rm -rf "$SERVICE_ROOT"
|
||||
|
||||
plugn trigger service-action post-delete "$PLUGIN_COMMAND_PREFIX" "$SERVICE"
|
||||
|
||||
22
subcommands/pause
Executable file
22
subcommands/pause
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/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-pause-cmd() {
|
||||
#E pause the running container for the service
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:pause lollipop
|
||||
#A service, service to run command against
|
||||
declare desc="pause a running $PLUGIN_SERVICE service"
|
||||
local cmd="$PLUGIN_COMMAND_PREFIX:pause" argv=("$@")
|
||||
[[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||
declare SERVICE="$1"
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
service_pause "$SERVICE"
|
||||
}
|
||||
|
||||
service-pause-cmd "$@"
|
||||
@@ -16,7 +16,7 @@ service-restart-cmd() {
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
service_stop "$SERVICE"
|
||||
service_pause "$SERVICE"
|
||||
service_start "$SERVICE"
|
||||
dokku_log_info1 "Please call dokku ps:restart on all linked apps"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ source "$PLUGIN_BASE_PATH/common/functions"
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||
|
||||
service-stop-cmd() {
|
||||
#E stop the service and the running container
|
||||
#E stop the service and removes the running container
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:stop lollipop
|
||||
#A service, service to run command against
|
||||
declare desc="stop a running $PLUGIN_SERVICE service"
|
||||
@@ -16,7 +16,7 @@ service-stop-cmd() {
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
service_stop "$SERVICE"
|
||||
service_container_rm "$SERVICE"
|
||||
}
|
||||
|
||||
service-stop-cmd "$@"
|
||||
|
||||
@@ -28,8 +28,14 @@ service-upgrade-cmd() {
|
||||
|
||||
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"
|
||||
if ! service_image_exists "$SERVICE" "$PLUGIN_IMAGE" "$PLUGIN_IMAGE_VERSION"; 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 image pull ${IMAGE}" 1>&2
|
||||
dokku_log_warn "$PLUGIN_SERVICE service $SERVICE upgrade failed"
|
||||
exit 1
|
||||
fi
|
||||
"$DOCKER_BIN" image pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
|
||||
fi
|
||||
|
||||
local NEW_PLUGIN_IMAGE_TAG="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||
|
||||
25
tests/service_pause.bats
Executable file
25
tests/service_pause.bats
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bats
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
dokku "$PLUGIN_COMMAND_PREFIX:create" l
|
||||
}
|
||||
|
||||
teardown() {
|
||||
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:pause) error when there are no arguments" {
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:pause"
|
||||
assert_contains "${lines[*]}" "Please specify a valid name for the service"
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:pause) error when service does not exist" {
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:pause" not_existing_service
|
||||
assert_contains "${lines[*]}" "service not_existing_service does not exist"
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:pause) success" {
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:pause" l
|
||||
assert_success
|
||||
}
|
||||
Reference in New Issue
Block a user