From 049a02465909ae60998b69a05948e18fe7712675 Mon Sep 17 00:00:00 2001 From: Christian Kadner Date: Fri, 27 Oct 2023 22:08:26 -0700 Subject: [PATCH] chore: Reuse existing developer image Signed-off-by: Christian Kadner --- Makefile | 9 +++++++-- scripts/build_docker.sh | 16 ++++++++++++++-- scripts/develop.sh | 10 +++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9dea9a4d..eff2176f 100644 --- a/Makefile +++ b/Makefile @@ -34,14 +34,19 @@ build: build.develop: ./scripts/build_docker.sh --target develop +.PHONY: use.develop +## Check if developer image exists, build it if it doesn't +use.develop: + ./scripts/build_docker.sh --target develop --use-existing + .PHONY: develop ## Run interactive shell inside developer container -develop: build.develop +develop: use.develop ./scripts/develop.sh .PHONY: run ## Run make target inside developer container (e.g. `make run fmt`) -run: build.develop +run: use.develop ./scripts/develop.sh make $(RUN_ARGS) .PHONY: test diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh index 8c7d0473..56d18240 100755 --- a/scripts/build_docker.sh +++ b/scripts/build_docker.sh @@ -11,7 +11,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License.# +# limitations under the License. USAGE="$( cat </dev/null 2>&1 && pwd)" -cd "$DIR/.." || +cd "$DIR/.." IMAGE_SUFFIX="" @@ -75,6 +79,14 @@ if [ "${DOCKER_TARGET}" != "runtime" ]; then IMAGE_SUFFIX="-${DOCKER_TARGET}" fi +if [[ $use_existing == "true" ]]; then + DOCKER_IMAGE="${DOCKER_USER}/modelmesh-runtime-adapter${IMAGE_SUFFIX}:${IMAGE_TAG}" + if docker image inspect "${DOCKER_IMAGE}" >/dev/null 2>&1; then + echo "Using existing image: ${DOCKER_IMAGE}" + exit 0 + fi +fi + declare -a docker_args=( --target "${DOCKER_TARGET}" -t "${DOCKER_USER}/modelmesh-runtime-adapter${IMAGE_SUFFIX}:${DOCKER_TAG}" diff --git a/scripts/develop.sh b/scripts/develop.sh index 65bb646b..54559765 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -11,7 +11,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License.# +# limitations under the License. USAGE="$( cat <&2 exit 1 } +DOCKER_USER=${DOCKER_USER:-"kserve"} +IMAGE_TAG=${IMAGE_TAG:-"latest"} + # PARAMS="" # while (("$#")); do @@ -50,7 +54,7 @@ usage() { # eval set -- "$PARAMS" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "${DIR}/.." || +cd "${DIR}/.." # Make sure .bash_history exists and is a file touch .bash_history @@ -73,4 +77,4 @@ fi # Run the develop container with local source mounted in docker run --rm \ "${docker_run_args[@]}" \ - kserve/modelmesh-runtime-adapter-develop:latest "$@" + "${DOCKER_USER}/modelmesh-runtime-adapter-develop:${IMAGE_TAG}" "$@"