From d5dabf4674b7bc109d76fdece0cebb1bc8760f58 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 8 Feb 2023 10:27:58 -0600 Subject: [PATCH] fixes docker-dev-shell not using the cache due to wrong tag (#6614) --- bin/docker-dev-shell | 24 ++++++++---------------- script/_common | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/bin/docker-dev-shell b/bin/docker-dev-shell index 69c516f1b9..dd78951bf2 100755 --- a/bin/docker-dev-shell +++ b/bin/docker-dev-shell @@ -1,6 +1,8 @@ #!/bin/bash set -e +cd "$(dirname "$0")/.." +source script/_common HELP=false REBUILD=false @@ -43,26 +45,16 @@ build_image() { export BUILT_IMAGE=true echo "$(tput setaf 2)=> building image from Dockerfile$(tput sgr0)" - docker build \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - --build-arg "USER_UID=$(id -u)" \ - --build-arg "USER_GID=$(id -g)" \ - --cache-from "ghcr.io/dependabot/dependabot-updater-core" \ - -t "ghcr.io/dependabot/dependabot-updater-core" \ - -f Dockerfile.updater-core \ - . - - docker build \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - --cache-from "ghcr.io/dependabot/dependabot-updater-$ECOSYSTEM" \ - -t "dependabot/dependabot-updater-$ECOSYSTEM" \ - -f "$ECOSYSTEM"/Dockerfile \ - . + DEPENDABOT_USER_UID=$(id -u) + DEPENDABOT_USER_GID=$(id -g) + export DEPENDABOT_USER_UID + export DEPENDABOT_USER_GID + docker_build "$ECOSYSTEM" echo "$(tput setaf 2)=> building image from $DOCKERFILE$(tput sgr0)" docker build \ --build-arg BUILDKIT_INLINE_CACHE=1 \ - --build-arg "FROM_IMAGE=dependabot/dependabot-updater-$ECOSYSTEM" \ + --build-arg "FROM_IMAGE=$UPDATER_IMAGE_NAME" \ -t "$IMAGE_NAME" \ -f "$DOCKERFILE" \ . diff --git a/script/_common b/script/_common index 8f0cbdb3a9..e4cf21e978 100755 --- a/script/_common +++ b/script/_common @@ -34,27 +34,38 @@ function docker_build() { ECOSYSTEM="$1" set_tag + if [ -z "$DEPENDABOT_USER_UID" ]; then + export DEPENDABOT_USER_UID=1000 + fi + if [ -z "$DEPENDABOT_USER_GID" ]; then + export DEPENDABOT_USER_GID=1000 + fi + # shellcheck disable=SC2086 # as $DOCKER_BUILD_ARGS relies on word-splitting docker build \ $DOCKER_BUILD_ARGS \ --build-arg BUILDKIT_INLINE_CACHE=1 \ + --build-arg USER_UID=$DEPENDABOT_USER_UID \ + --build-arg USER_GID=$DEPENDABOT_USER_GID \ --cache-from "$UPDATER_CORE_IMAGE" \ -t "$UPDATER_CORE_IMAGE" \ -f Dockerfile.updater-core \ . + export UPDATER_IMAGE_NAME="$UPDATER_IMAGE$TAG" + # shellcheck disable=SC2086 # as $DOCKER_BUILD_ARGS relies on word-splitting docker build \ $DOCKER_BUILD_ARGS \ --build-arg BUILDKIT_INLINE_CACHE=1 \ - --cache-from "$UPDATER_IMAGE$TAG" \ - -t "$UPDATER_IMAGE$TAG" \ + --cache-from "$UPDATER_IMAGE_NAME" \ + -t "$UPDATER_IMAGE_NAME" \ -f $ECOSYSTEM/Dockerfile \ . # Verify max layers; an AUFS limit that was _crucial_ on Heroku (but not now) - IMAGE_LAYERS=$(docker history -q "$UPDATER_IMAGE$TAG" | wc -l | sed -e 's/ //g') - echo "$UPDATER_IMAGE$TAG contains $IMAGE_LAYERS layers" + IMAGE_LAYERS=$(docker history -q "$UPDATER_IMAGE_NAME" | wc -l | sed -e 's/ //g') + echo "$UPDATER_IMAGE_NAME contains $IMAGE_LAYERS layers" [[ $IMAGE_LAYERS -lt 126 ]] }