Skip to content

Commit

Permalink
Also catch ignored file presence
Browse files Browse the repository at this point in the history
Was finding that extraneous image rebuilds were happening because
ignored files were slipping into the source tree via use in container.
This adds extra protections to catch files modified that would impact
builds including `./docker/` and poetry files.
  • Loading branch information
Purg committed Mar 7, 2022
1 parent b4b3f1b commit 9ea24b3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.git
/.workspace-shell-dev
/docker/.container_xauth
/.container_xauth
/HoloLens2-ResearchMode-Unity
/unity
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Project Ignores
#
/.workspace-shell-dev/
/docker/.container_xauth
/.container_xauth

# This .gitignore file should be placed at the root of your Unity project directory
#
Expand Down
39 changes: 32 additions & 7 deletions angel-docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Options:
"
}

function log()
{
>&2 echo "$@"
}

# Option parsing
dc_forward_params=()
while [[ $# -gt 0 ]]
Expand All @@ -29,7 +34,7 @@ do
exit 0
;;
--force)
echo "Forcing build regardless of workspace hygiene."
log "Forcing build regardless of workspace hygiene."
shift
FORCE_BUILD=1
;;
Expand All @@ -39,23 +44,43 @@ do
esac
done

git_status="$(git status --porcelain "${SCRIPT_DIR}/ros")"
if [[ -n "$git_status" ]]
# Check if there are modified or "new" files in the workspace.
# NODE: `warn_build_spaces` should be expanded if more things start to become
# part of docker builds. Maybe read this in from somewhere else instead
# of encoding here?
warn_build_spaces=(
"${SCRIPT_DIR}/ros"
"${SCRIPT_DIR}/docker"
"${SCRIPT_DIR}/pyproject.toml"
"${SCRIPT_DIR}/poetry.lock"
)
git_status="$(git status --porcelain "${warn_build_spaces[@]}")"
# Check if there are ignored files in the workspace that should not be there.
git_clean_dr="$(git clean "${warn_build_spaces[@]}" -xdn)"
if [[ -n "${git_status}" ]] || [[ -n "${git_clean_dr}" ]]
then
echo "WARNING: ROS workspace subtree is not clean."
log "WARNING: ROS workspace subtree is modified and/or un-clean."
if [[ -n "${git_status}" ]]
then
log "WARNING: -- There are modified / new files."
fi
if [[ -n "${git_clean_dr}" ]]
then
log "WARNING: -- There are unexpected ignored files (check git clean -xdn)."
fi
if [[ -n "$FORCE_BUILD" ]]
then
echo "WARNING: Force enabled, building anyway."
log "WARNING: Force enabled, building anyway."
else
echo "ERROR: Refusing to build images."
log "ERROR: Refusing to build images."
exit 1
fi
fi

if [[ "${#dc_forward_params[@]}" -gt 0 ]]
then
# shellcheck disable=SC2145
echo "Forwarding to docker-compose: ${dc_forward_params[@]}"
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
fi

docker-compose \
Expand Down
2 changes: 1 addition & 1 deletion angel-workspace-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ done
SERVICE_NAME="${ARG_SERVICE_NAME:-${DEFAULT_SERVICE_NAME}}"

# Create a permissions file for xauthority.
XAUTH_DIR="${SCRIPT_DIR}/docker/.container_xauth"
XAUTH_DIR="${SCRIPT_DIR}/.container_xauth"
# Exporting to be used in replacement in docker-compose file.
XAUTH_FILEPATH="$(mktemp "${XAUTH_DIR}/local-XXXXXX.xauth")"
export XAUTH_FILEPATH
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
context: .. # repo root
dockerfile: docker/workspace-base-dev/Dockerfile
cache_from:
- ${PTG_REGISTRY}/workspace-base-dev:latest
- ${PTG_REGISTRY}/workspace-base-dev:${PTG_TAG}
profiles:
- build-only
Expand All @@ -29,6 +30,7 @@ services:
PTG_REGISTRY: # from .env file
PTG_TAG: # from .env file
cache_from:
- ${PTG_REGISTRY}/workspace-build-dev:latest
- ${PTG_REGISTRY}/workspace-build-dev:${PTG_TAG}
profiles:
- build-only
Expand All @@ -47,6 +49,7 @@ services:
tty: true
volumes:
- /dev/shm:/dev/shm
# Host sharing
- ../poetry.lock:/angel_workspace/poetry.lock
- ../pyproject.toml:/angel_workspace/pyproject.toml
- ../ros:/angel_workspace/src
Expand All @@ -63,6 +66,7 @@ services:
# assume this file exists, should be created before running.
- ${XAUTH_FILEPATH}:/tmp/.docker.xauth
environment:
PYTHONDONTWRITEBYTECODE: "true"
HISTFILE: /angel_workspace/stuff/bash_history
CYCLONE_DDS_INTERFACE: # from .env file or parent environment
SETUP_WORKSPACE_INSTALL: # from .env file or parent environment
Expand Down

0 comments on commit 9ea24b3

Please sign in to comment.