From 100e8d4606c36ec6ec4715b7ed335e8d8a7a7810 Mon Sep 17 00:00:00 2001 From: vinny Date: Tue, 8 Jun 2021 14:36:51 -0400 Subject: [PATCH 1/2] HARMONY-388: Docker build consistency --- Dockerfile | 9 ++++++++ Dockerfile.local-service-lib | 6 ------ bin/build-image | 41 ++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 Dockerfile.local-service-lib diff --git a/Dockerfile b/Dockerfile index 6ff53bb..614f3a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,15 @@ RUN apt-get update && apt-get install -y build-essential git COPY requirements/core.txt requirements/core.txt RUN pip3 install -r requirements/core.txt +# This is below the preceding layer to prevent Docker from rebuilding the +# previous layer (forcing a reload of dependencies) whenever the +# status of a local service library changes +ARG service_lib_dir=NO_SUCH_DIR + +# Install a local harmony-service-lib-py if we have one +COPY deps ./deps/ +RUN if [ -d deps/${service_lib_dir} ]; then echo "OK"; pip install -e deps/${service_lib_dir}; fi + COPY . . ENTRYPOINT ["python3", "-m", "harmony_netcdf_to_zarr"] diff --git a/Dockerfile.local-service-lib b/Dockerfile.local-service-lib deleted file mode 100644 index a4b5c93..0000000 --- a/Dockerfile.local-service-lib +++ /dev/null @@ -1,6 +0,0 @@ -FROM harmonyservices/netcdf-to-zarr:latest - -ARG LOCAL_SVCLIB - -ADD ${LOCAL_SVCLIB} /opt/harmony-service-lib-py -RUN pip install --user /opt/harmony-service-lib-py/*.whl diff --git a/bin/build-image b/bin/build-image index cc1e7dc..609487e 100755 --- a/bin/build-image +++ b/bin/build-image @@ -1,33 +1,28 @@ -#!/bin/bash +#!/usr/bin/env bash set -e +# source the .env file if it exists +[[ -f .env ]] && source .env + image="harmonyservices/netcdf-to-zarr" tag=${1:-latest} -# source the .env file if it exists -[[ -f .env ]] && source .env -DOCKER_ARGS="" -if [ -n "$DIND" ]; then - DOCKER_ARGS="-H ${DOCKER_DAEMON_ADDR}" +if [ -d "deps" ]; then + rm -rf deps fi +mkdir deps -# NOTE: We use the `host` network mode so we can have access to the -# host VPN connection used for Nexus access. - -docker $DOCKER_ARGS build --network host -t ${image}:${tag} . +SERVICE_LIB_DIR="NO_SUCH_DIR" +if [ -d "$LOCAL_SVCLIB_DIR" ]; then + echo "Using local copy of harmony-service-lib" + SERVICE_LIB_DIR=$(basename $LOCAL_SVCLIB_DIR) + cp -R $LOCAL_SVCLIB_DIR deps/ +fi -if [[ ! -z "${LOCAL_SVCLIB_DIR}" ]] -then - LOCAL_SVCLIB=deps/harmony-service-lib - mkdir -p "${LOCAL_SVCLIB}" - pushd "${LOCAL_SVCLIB_DIR}" - make build - popd - mv "${LOCAL_SVCLIB_DIR}"/dist/* "${LOCAL_SVCLIB}" - docker $DOCKER_ARGS build -f Dockerfile.local-service-lib \ - --build-arg LOCAL_SVCLIB=${LOCAL_SVCLIB} \ - --network host \ - -t ${image}:${tag} . - rm -r ${LOCAL_SVCLIB} +# If we're running Docker in Docker (DIND) then the docker daemon is on the host +if [ -n "$DIND" ]; then + docker -H $DOCKER_DAEMON_ADDR build --build-arg service_lib_dir="$SERVICE_LIB_DIR" -t ${image}:${ag} . +else + docker build --build-arg service_lib_dir="$SERVICE_LIB_DIR" --network host -t ${image}:${tag} . fi From 711493d356e74a80e3c491cffa4a342b96097ab2 Mon Sep 17 00:00:00 2001 From: vinny Date: Wed, 9 Jun 2021 10:42:24 -0400 Subject: [PATCH 2/2] HARMONY-388: More informative message when installing local harmony-service-lib-py --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 614f3a8..d2c5f68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ ARG service_lib_dir=NO_SUCH_DIR # Install a local harmony-service-lib-py if we have one COPY deps ./deps/ -RUN if [ -d deps/${service_lib_dir} ]; then echo "OK"; pip install -e deps/${service_lib_dir}; fi +RUN if [ -d deps/${service_lib_dir} ]; then echo "Installing from local copy of harmony-service-lib"; pip install -e deps/${service_lib_dir}; fi COPY . .