Skip to content

Commit

Permalink
add first version of blacklisting packages in docker-ros workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbusch committed Sep 19, 2023
1 parent 77705e3 commit c2a7ae2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci/docker-ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ variables:
ADDITIONAL_FILES_DIR: docker/additional-files # Relative path to directory containing additional files to copy into image"
ADDITIONAL_PIP_FILE: docker/additional-pip-requirements.txt # Relative filepath to file containing additional pip packages to install
ENABLE_RECURSIVE_ADDITIONAL_PIP: 'false' # Enable recursive discovery of files named `additional-pip-file`
BLACKLISTED_PACKAGES_FILE: docker/blacklisted-packages.txt # Relative filepath to file containing the blacklisted packages
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES: 'false' # Enable recursive discovery of files named `blacklisted-packages-file`
CUSTOM_SCRIPT_FILE: docker/custom.sh # Relative filepath to script containing custom installation commands
ENABLE_RECURSIVE_CUSTOM_SCRIPT: 'false' # Enable recursive discovery of files named `custom-script-file`
# -----
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ If your ROS-based repository requires Python dependencies that cannot be install

Create a file `additional-pip-requirements.txt` in your `docker` folder (or configure a different `ADDITIONAL_PIP_FILE`) and list any other Python dependencies that need to be installed via *pip*.

### TODO: Blacklist/Whitelist packages

### Custom Installation Script

If your ROS-based repository requires to execute any other installation or pre-/post-installation steps, you can use a special `custom.sh` script.
Expand Down Expand Up @@ -325,6 +327,9 @@ Create a folder `additional-files` in your `docker` folder (or configure a diffe
- **`additional-pip-file` | `ADDITIONAL_PIP_FILE`**
Relative filepath to file containing additional pip packages to install
*default:* `docker/additional-pip-requirements.txt`
- **`blacklisted-packages-file` | `BLACKLISTED_PACKAGES_FILE`**
Relative filepath to file containing blacklisted packages
*default:* `docker/blacklisted-packages.txt`
- **`base-image` | `BASE_IMAGE`**
Base image `name:tag`
*required*
Expand Down Expand Up @@ -370,6 +375,9 @@ Create a folder `additional-files` in your `docker` folder (or configure a diffe
- **`enable-recursive-additional-pip` | `ENABLE_RECURSIVE_ADDITIONAL_PIP`**
Enable recursive discovery of files named `additional-pip-file`
*default:* `false`
- **`enable-recursive-blacklisted-packages` | `ENABLE_RECURSIVE_BLACKLISTED_PACKAGES`**
Enable recursive discovery of files named `blacklisted-packages-file`
*default:* `false`
- **`enable-recursive-custom-script` | `ENABLE_RECURSIVE_CUSTOM_SCRIPT`**
Enable recursive discovery of files named `custom-script-file`
*default:* `false`
Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ inputs:
description: "Enable recursive discovery of files named `additional-pip-file`"
default: false

blacklisted-packages-file:
description: "Relative filepath to file containing blacklisted packages to remove from workspace"
default: docker/blacklisted-packages.txt

enable-recursive-blacklisted-packages:
description: "Enable recursive discovery of files named `blacklisted-packages-file`"
default: false

custom-script-file:
description: "Relative filepath to script containing custom installation commands"
default: docker/custom.sh
Expand Down Expand Up @@ -172,6 +180,8 @@ runs:
ADDITIONAL_FILES_DIR: ${{ inputs.additional-files-dir }}
ADDITIONAL_PIP_FILE: ${{ inputs.additional-pip-file }}
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
BLACKLISTED_PACKAGES_FILE: ${{ inputs.blacklisted-packages-file }}
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES: ${{ inputs.enable-recursive-blacklisted-packages }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}

Expand Down Expand Up @@ -225,6 +235,8 @@ runs:
ADDITIONAL_FILES_DIR: ${{ inputs.additional-files-dir }}
ADDITIONAL_PIP_FILE: ${{ inputs.additional-pip-file }}
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
BLACKLISTED_PACKAGES_FILE: ${{ inputs.blacklisted-packages-file }}
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES: ${{ inputs.enable-recursive-blacklisted-packages }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}
_ENABLE_IMAGE_PUSH: true
Expand Down Expand Up @@ -256,6 +268,8 @@ runs:
ADDITIONAL_FILES_DIR: ${{ inputs.additional-files-dir }}
ADDITIONAL_PIP_FILE: ${{ inputs.additional-pip-file }}
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
BLACKLISTED_PACKAGES_FILE: ${{ inputs.blacklisted-packages-file }}
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES: ${{ inputs.enable-recursive-blacklisted-packages }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}
_ENABLE_IMAGE_PUSH: true
Expand Down
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
RUN /usr/local/bin/recursive_vcs_import.py src src/upstream

# remove blacklisted packages from workspace
ARG BLACKLISTED_PACKAGES_FILE="docker/blacklisted-packages.txt"
ARG ENABLE_RECURSIVE_BLACKLISTED_PACKAGES="false"
RUN echo "colcon list -p --base-paths src/ --packages-select \\" >> $WORKSPACE/.remove-packages.sh && \
if [[ $ENABLE_RECURSIVE_BLACKLISTED_PACKAGES == 'true' ]]; then \
find . -type f -name $(basename ${BLACKLISTED_PACKAGES_FILE}) -exec sed '$a\' {} \; | awk '{print " " $0 " \\"}' >> $WORKSPACE/.remove-packages.sh ; \
elif [[ -f src/target/${BLACKLISTED_PACKAGES_FILE} ]]; then \
cat src/target/${BLACKLISTED_PACKAGES_FILE} | awk '{print " " $0 " \\"}' >> $WORKSPACE/.remove-packages.sh ; \
fi && \
echo ";" >> $WORKSPACE/.remove-packages.sh && \
chmod +x $WORKSPACE/.remove-packages.sh && \
$WORKSPACE/.remove-packages.sh | xargs rm -rf
# TODO: only keep whitelist packages in workspace
# create install script with list of rosdep dependencies
RUN echo "set -e" >> $WORKSPACE/.install-dependencies.sh && \
source /opt/ros/$ROS_DISTRO/setup.bash && \
Expand Down
2 changes: 2 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ build_image() {
$(if [[ -n "${ADDITIONAL_FILES_DIR}" ]]; then echo "--build-arg ADDITIONAL_FILES_DIR=${ADDITIONAL_FILES_DIR}"; fi) \
$(if [[ -n "${ADDITIONAL_PIP_FILE}" ]]; then echo "--build-arg ADDITIONAL_PIP_FILE=${ADDITIONAL_PIP_FILE}"; fi) \
$(if [[ -n "${ENABLE_RECURSIVE_ADDITIONAL_PIP}" ]]; then echo "--build-arg ENABLE_RECURSIVE_ADDITIONAL_PIP=${ENABLE_RECURSIVE_ADDITIONAL_PIP}"; fi) \
$(if [[ -n "${BLACKLISTED_PACKAGES_FILE}" ]]; then echo "--build-arg BLACKLISTED_PACKAGES_FILE=${BLACKLISTED_PACKAGES_FILE}"; fi) \
$(if [[ -n "${ENABLE_RECURSIVE_BLACKLISTED_PACKAGES}" ]]; then echo "--build-arg ENABLE_RECURSIVE_BLACKLISTED_PACKAGES=${ENABLE_RECURSIVE_BLACKLISTED_PACKAGES}"; fi) \
$(if [[ -n "${CUSTOM_SCRIPT_FILE}" ]]; then echo "--build-arg CUSTOM_SCRIPT_FILE=${CUSTOM_SCRIPT_FILE}"; fi) \
$(if [[ -n "${ENABLE_RECURSIVE_CUSTOM_SCRIPT}" ]]; then echo "--build-arg ENABLE_RECURSIVE_CUSTOM_SCRIPT=${ENABLE_RECURSIVE_CUSTOM_SCRIPT}"; fi) \
.
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ENABLE_RECURSIVE_ADDITIONAL_DEBS="${ENABLE_RECURSIVE_ADDITIONAL_DEBS:-}"
ADDITIONAL_FILES_DIR="${ADDITIONAL_FILES_DIR:-}"
ADDITIONAL_PIP_FILE="${ADDITIONAL_PIP_FILE:-}"
ENABLE_RECURSIVE_ADDITIONAL_PIP="${ENABLE_RECURSIVE_ADDITIONAL_PIP:-}"
BLACKLISTED_PACKAGES_FILE="${BLACKLISTED_PACKAGES_FILE:-}"
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES="${ENABLE_RECURSIVE_BLACKLISTED_PACKAGES:-}"
CUSTOM_SCRIPT_FILE="${CUSTOM_SCRIPT_FILE:-}"
ENABLE_RECURSIVE_CUSTOM_SCRIPT="${ENABLE_RECURSIVE_CUSTOM_SCRIPT:-}"
_ENABLE_IMAGE_PUSH="${_ENABLE_IMAGE_PUSH:-false}"
Expand Down
2 changes: 2 additions & 0 deletions templates/docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ x-build: &build
ADDITIONAL_DEBS_FILE: $ADDITIONAL_DEBS_FILE
ADDITIONAL_FILES_DIR: $ADDITIONAL_FILES_DIR
ADDITIONAL_PIP_FILE: $ADDITIONAL_PIP_FILE
BLACKLISTED_PACKAGES_FILE: $BLACKLISTED_PACKAGES_FILE
CUSTOM_SCRIPT_FILE: $CUSTOM_SCRIPT_FILE
ENABLE_RECURSIVE_ADDITIONAL_DEBS: $ENABLE_RECURSIVE_ADDITIONAL_DEBS
ENABLE_RECURSIVE_ADDITIONAL_PIP: $ENABLE_RECURSIVE_ADDITIONAL_PIP
ENABLE_RECURSIVE_BLACKLISTED_PACKAGES: $ENABLE_RECURSIVE_BLACKLISTED_PACKAGES
ENABLE_RECURSIVE_CUSTOM_SCRIPT: $ENABLE_RECURSIVE_CUSTOM_SCRIPT
GIT_HTTPS_PASSWORD: $GIT_HTTPS_PASSWORD
GIT_HTTPS_SERVER: $GIT_HTTPS_SERVER
Expand Down

0 comments on commit c2a7ae2

Please sign in to comment.