Skip to content

Commit

Permalink
install: Only remove .dockerignore if it wasn't present
Browse files Browse the repository at this point in the history
If there is already a top-level .dockerignore, don't remove it.
A .dockerignore should only be ignored if it was copied from
a BEAVER_DOCKER_CONTEXT.
  • Loading branch information
leandro-lucarella-sociomantic committed Jun 19, 2018
1 parent 0990d54 commit e3b3351
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
19 changes: 16 additions & 3 deletions bin/beaver-install
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ d="$(dirname "$0")"
# Copy a file only if it exist
maybe_cp()
{
if test -f "$1"
# Don't do anything if both src and dst are the same, or if src doesn't
# exist
if test "$(readlink -m "$1")" != "$(readlink -m "$2")" -a test -f "$1"
then
cp -v "$1" "$2"
fi
}

# Store if a .dockerignore existed already
dockerignore=false
if test -f ".dockerignore"
then
dockerignore=true
fi

# Look if a particular context was given and copy the .dockerfile from it
if test -n "${BEAVER_DOCKER_CONTEXT:-}"
then
trap 'r=$?; if test $r -eq 0 -a "${BEAVER_DEBUG:-0}" -ne 1; \
then rm -f .dockerignore; fi; exit $r' EXIT
# Only remove .dockerignore if none existed
if ! $dockerignore
then
trap 'r=$?; if test $r -eq 0 -a "${BEAVER_DEBUG:-0}" -ne 1; \
then rm -f .dockerignore; fi; exit $r' EXIT
fi
maybe_cp "$BEAVER_DOCKER_CONTEXT/.dockerignore" .dockerignore
maybe_cp "$BEAVER_DOCKER_CONTEXT/dockerignore" .dockerignore
docker_dir="-d $BEAVER_DOCKER_CONTEXT"
Expand Down
18 changes: 14 additions & 4 deletions bin/dlang/install
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ esac
# Copy a file only if it exist
maybe_cp()
{
if test -f "$1"
if test "$(readlink -m "$1")" != "$(readlink -m "$2")" -a test -f "$1"
then
cp -v "$1" "$2"
fi
}
# Store if a .dockerignore existed already
dockerignore=false
if test -f ".dockerignore"
then
dockerignore=true
fi
# Look if a particular context was given and copy the .dockerfile from it
if test -n "${BEAVER_DOCKER_CONTEXT:-}"
then
trap 'r=$?; if test $r -eq 0 -a "${BEAVER_DEBUG:-0}" -ne 1; \
then rm -f .dockerignore; fi; exit $r' EXIT
# Only remove .dockerignore if none existed
if ! $dockerignore
then
trap 'r=$?; if test $r -eq 0 -a "${BEAVER_DEBUG:-0}" -ne 1; \
then rm -f .dockerignore; fi; exit $r' EXIT
fi
maybe_cp "$BEAVER_DOCKER_CONTEXT/.dockerignore" .dockerignore
maybe_cp "$BEAVER_DOCKER_CONTEXT/dockerignore" .dockerignore
docker_dir="-d $BEAVER_DOCKER_CONTEXT"
Expand All @@ -58,5 +68,5 @@ fi

if test "${BEAVER_DEBUG:-0}" -ne 1
then
rm -f beaver.Dockerfile.generated .dockerignore
rm -f beaver.Dockerfile.generated
fi

0 comments on commit e3b3351

Please sign in to comment.