Skip to content

Commit fa0c724

Browse files
ckadnerrafvasq
andauthored
chore: Reuse existing developer image (#66)
#### Motivation Each time running lint using the developer image, i.e. `make run fmt`, the `build.develop` Make target is executed, calling `scripts/build_docker.sh` which (re)builds the developer image each time, which despite using cached image layers takes extra time and clutters the terminal with Docker build output that is not relevant with respect to the actual make goal having been invoked. ``` [modelmesh-runtime-adapter] (main=)$ make run fmt Makefile:74: warning: overriding commands for target `fmt' Makefile:60: warning: ignoring old commands for target `fmt' ./scripts/build_docker.sh --target develop [+] Building 1.1s (15/15) FINISHED docker:colima => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 7.60kB 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 93B 0.0s => [internal] load metadata for registry.access.redhat.com/ubi8/go-toolset:1.17 1.0s => [develop 1/10] FROM registry.access.redhat.com/ubi8/go-toolset:1.17@sha256:db868166dd2ea38bdb8507e0cb1c9a295622fb6d8bdd70718af1405679ca0a19 0.0s => [internal] load build context 0.0s => => transferring context: 98B 0.0s => CACHED [develop 2/10] RUN --mount=type=cache,target=/root/.cache/dnf:rw dnf install --setopt=cachedir=/root/.cache/dnf -y --nodocs python3 p 0.0s => CACHED [develop 3/10] RUN --mount=type=cache,target=/root/.cache/pip pip3 install pre-commit 0.0s => CACHED [develop 4/10] RUN set -eux; amd64=x86_64; arm64=aarch_64; ppc64le=ppcle_64; s390x=s390_64; wget -qO protoc.zip "https://github.com/p 0.0s => CACHED [develop 5/10] WORKDIR /opt/app 0.0s => CACHED [develop 6/10] COPY go.mod go.sum ./ 0.0s => CACHED [develop 7/10] RUN true && go get google.golang.org/grpc/cmd/protoc-gen-go-grpc && go install google.golang.org/protobuf/cmd/protoc-gen-go 0.0s => CACHED [develop 8/10] COPY .pre-commit-config.yaml ./ 0.0s => CACHED [develop 9/10] RUN git init && pre-commit install-hooks && rm -rf .git 0.0s => CACHED [develop 10/10] RUN go mod download 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:feb1d14c1a753a7e4494b9b53f8132fec927c39e565eacede9ea2a460a78ebec 0.0s => => naming to docker.io/kserve/modelmesh-runtime-adapter-develop:reuse_existing_dev_image-20231027T220733PDT 0.0s => => naming to docker.io/kserve/modelmesh-runtime-adapter-develop:latest 0.0s ./scripts/develop.sh make fmt ./scripts/fmt.sh golangci-lint............................................................Passed prettier.................................................................Passed ``` #### Modifications - Add flag `--use-existing` to `scripts/build_docker.sh` to skip the Docker build it the image exists - Add internal Make target `use.develop` which call `scripts/build_docker.sh` with the new flag `--use-existing` - Add env vars `DOCKER_USER` and `IMAGE_TAG` to `scripts/develop.sh` to be consistent with `scripts/build_docker.sh` #### Result ``` [modelmesh-runtime-adapter_ckadner] (reuse_existing_dev_image=)$ make run fmt Makefile:74: warning: overriding commands for target `fmt' Makefile:60: warning: ignoring old commands for target `fmt' ./scripts/build_docker.sh --target develop --use-existing ./scripts/develop.sh make fmt ./scripts/fmt.sh golangci-lint............................................................Passed prettier.................................................................Passed ``` Signed-off-by: Christian Kadner <[email protected]> Signed-off-by: Rafael Vasquez <[email protected]> Co-authored-by: Rafael Vasquez <[email protected]>
1 parent 2eeb488 commit fa0c724

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ build:
3434
build.develop:
3535
./scripts/build_docker.sh --target develop
3636

37+
.PHONY: use.develop
38+
## Check if developer image exists, build it if it doesn't
39+
use.develop:
40+
./scripts/build_docker.sh --target develop --use-existing
41+
3742
.PHONY: develop
3843
## Run interactive shell inside developer container
39-
develop: build.develop
44+
develop: use.develop
4045
./scripts/develop.sh
4146

4247
.PHONY: run
4348
## Run make target inside developer container (e.g. `make run fmt`)
44-
run: build.develop
49+
run: use.develop
4550
./scripts/develop.sh make $(RUN_ARGS)
4651

4752
.PHONY: test

scripts/build_docker.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
14-
# limitations under the License.#
14+
# limitations under the License.
1515

1616
USAGE="$(
1717
cat <<EOF
@@ -40,6 +40,10 @@ while (("$#")); do
4040
-h | --help)
4141
usage
4242
;;
43+
--use-existing)
44+
use_existing=true
45+
shift 1
46+
;;
4347
-t | --target)
4448
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
4549
DOCKER_TARGET=$2
@@ -67,14 +71,22 @@ done
6771

6872
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6973

70-
cd "$DIR/.." ||
74+
cd "$DIR/.."
7175

7276
IMAGE_SUFFIX=""
7377

7478
if [ "${DOCKER_TARGET}" != "runtime" ]; then
7579
IMAGE_SUFFIX="-${DOCKER_TARGET}"
7680
fi
7781

82+
if [[ $use_existing == "true" ]]; then
83+
DOCKER_IMAGE="${DOCKER_USER}/modelmesh-runtime-adapter${IMAGE_SUFFIX}:${IMAGE_TAG}"
84+
if docker image inspect "${DOCKER_IMAGE}" >/dev/null 2>&1; then
85+
echo "Using existing image: ${DOCKER_IMAGE}"
86+
exit 0
87+
fi
88+
fi
89+
7890
declare -a docker_args=(
7991
--target "${DOCKER_TARGET}"
8092
-t "${DOCKER_USER}/modelmesh-runtime-adapter${IMAGE_SUFFIX}:${DOCKER_TAG}"

scripts/develop.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
14-
# limitations under the License.#
14+
# limitations under the License.
1515

1616
USAGE="$(
1717
cat <<EOF
@@ -22,11 +22,15 @@ usage: $0 [optional command]
2222
[-h | --help] Display this help
2323
EOF
2424
)"
25+
2526
usage() {
2627
echo "$USAGE" >&2
2728
exit 1
2829
}
2930

31+
DOCKER_USER=${DOCKER_USER:-"kserve"}
32+
IMAGE_TAG=${IMAGE_TAG:-"latest"}
33+
3034
# PARAMS=""
3135

3236
# while (("$#")); do
@@ -50,7 +54,7 @@ usage() {
5054
# eval set -- "$PARAMS"
5155

5256
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
53-
cd "${DIR}/.." ||
57+
cd "${DIR}/.."
5458

5559
# Make sure .bash_history exists and is a file
5660
touch .bash_history
@@ -73,4 +77,4 @@ fi
7377
# Run the develop container with local source mounted in
7478
docker run --rm \
7579
"${docker_run_args[@]}" \
76-
kserve/modelmesh-runtime-adapter-develop:latest "$@"
80+
"${DOCKER_USER}/modelmesh-runtime-adapter-develop:${IMAGE_TAG}" "$@"

0 commit comments

Comments
 (0)