diff --git a/Dockerfile b/Dockerfile index 6ff53bb..d2c5f68 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 "Installing from local copy of harmony-service-lib"; 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