From 654939afa7e0422f86f12e8766525e0cdec066f3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 18 Dec 2022 17:52:32 -0500 Subject: [PATCH] refactor: do not pull image if it already exists --- docs/deployment/methods/git.md | 2 ++ plugins/git/git-from-image | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index ad34a5098..444b181e6 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -136,6 +136,8 @@ In the above example, Dokku will build the app as if the repository contained _o FROM dokku/node-js-getting-started:latest ``` +If the specified image already exists on the Dokku host, it will not be pulled again, though this behavior may be changed using [build phase docker-options](/docs/advanced-usage/docker-options.md). + Triggering a build with the same arguments multiple times will result in Dokku exiting `0` early as there will be no changes detected. If the image tag is reused but the underlying image is different, it is recommended to use the image digest instead of the tag. This can be retrieved via the following command: ```shell diff --git a/plugins/git/git-from-image b/plugins/git/git-from-image index 6300ee02d..009f3feec 100755 --- a/plugins/git/git-from-image +++ b/plugins/git/git-from-image @@ -26,8 +26,12 @@ trigger-git-git-from-image() { echo "FROM $DOCKER_IMAGE" >>"$TMP_WORK_DIR/Dockerfile" echo "LABEL com.dokku.docker-image-labeler/alternate-tags=[\\\"$DOCKER_IMAGE\\\"]" >>"$TMP_WORK_DIR/Dockerfile" - dokku_log_info1 "Pulling image" - "$DOCKER_BIN" image pull "$DOCKER_IMAGE" + if [[ "$(docker images -q "$DOCKER_IMAGE" 2>/dev/null)" == "" ]]; then + dokku_log_info1 "Pulling image" + "$DOCKER_BIN" image pull "$DOCKER_IMAGE" + else + dokku_log_info1 "Image exists on host, skipping pull" + fi export DOKKU_BUILDING_FROM_IMAGE="$DOCKER_IMAGE" plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"