Skip to content

Commit

Permalink
Merge pull request #6 from nasa/HARMONY-388
Browse files Browse the repository at this point in the history
HARMONY-388: Docker build consistency
  • Loading branch information
vinnyinverso authored Jun 9, 2021
2 parents 90fdb97 + 711493d commit cc3ba95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 0 additions & 6 deletions Dockerfile.local-service-lib

This file was deleted.

41 changes: 18 additions & 23 deletions bin/build-image
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cc3ba95

Please sign in to comment.