From 0c04ad8dcbd89f492df32f4d0c40b483dc6493df Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 7 Feb 2023 03:39:42 -0500 Subject: [PATCH] refactor: use namespaced docker commands for interacting with the docker binary --- README.md | 8 ++++---- bin/generate | 6 +++--- docs/create.md | 2 +- functions | 28 ++++++++++++++-------------- install | 6 +++--- subcommands/destroy | 2 +- subcommands/upgrade | 4 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index fac4cce..7eeef3a 100644 --- a/README.md +++ b/README.md @@ -96,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 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" @@ -736,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. diff --git a/bin/generate b/bin/generate index 3f65afc..c5aa616 100755 --- a/bin/generate +++ b/bin/generate @@ -223,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.", ] ) diff --git a/docs/create.md b/docs/create.md index fecb7a5..0097076 100644 --- a/docs/create.md +++ b/docs/create.md @@ -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 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" diff --git a/functions b/functions index 045f304..0464882 100755 --- a/functions +++ b/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 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 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 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 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 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_pause "$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 + docker 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 container ps -aq --no-trunc --filter "status=exited" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true + docker 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 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 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 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 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 container start "$PREVIOUS_ID" >/dev/null service_port_unpause "$SERVICE" dokku_log_info2 "Container started" elif service_image_exists "$SERVICE" && [[ -n "$PASSWORD" ]]; then diff --git a/install b/install index d1ef8e3..5a569da 100755 --- a/install +++ b/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 image ls -q "${IMAGE}" 2>/dev/null)" == "" ]]; then + docker image pull "${IMAGE}" fi } diff --git a/subcommands/destroy b/subcommands/destroy index c8534c4..11bf607 100755 --- a/subcommands/destroy +++ b/subcommands/destroy @@ -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 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" diff --git a/subcommands/upgrade b/subcommands/upgrade index 39110e7..717d525 100755 --- a/subcommands/upgrade +++ b/subcommands/upgrade @@ -41,11 +41,11 @@ service-upgrade-cmd() { 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 $SERVICE upgrade 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 image pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed" fi service_commit_config "$SERVICE"