Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dependency installation via vcstools #13

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitlab-ci/docker-ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ variables:
ENABLE_RECURSIVE_ADDITIONAL_PIP: 'false' # Enable recursive discovery of files named `additional-pip-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`
ADDITIONAL_REPOS_FILE: .repos # Relative filepath to script containing custom installation commands
jpbusch marked this conversation as resolved.
Show resolved Hide resolved
ENABLE_RECURSIVE_VCS_IMPORT: 'true' # Enable recursive discovery of files named `additional-repos-file`
# -----
DOCKER_ROS_GIT_REF: main

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ Create a folder `additional-files` in your `docker` folder (or configure a diffe
*default:* `docker/additional-files`
- **`additional-pip-file` | `ADDITIONAL_PIP_FILE`**
Relative filepath to file containing additional pip packages to install
*default:* `docker/additional-pip-requirements.txt`
*default:* `docker/additional-pip-requirements.txt`
- **`additional-repos-file` | `ADDITIONAL_REPOS_FILE`**
Relative filepath to file containing additional repos to install via vcstools
*default:* `.repos`
- **`base-image` | `BASE_IMAGE`**
Base image `name:tag`
*required*
Expand Down Expand Up @@ -373,6 +376,9 @@ Create a folder `additional-files` in your `docker` folder (or configure a diffe
- **`enable-recursive-custom-script` | `ENABLE_RECURSIVE_CUSTOM_SCRIPT`**
Enable recursive discovery of files named `custom-script-file`
*default:* `false`
- **`enable-recursive-vcs-import` | `ENABLE_RECURSIVE_VCS_IMPORT`**
Enable recursive discovery of files named `additional-repo-file`
*default:* `true`
- **`git-ssh-known-host-keys` | `GIT_SSH_KNOWN_HOST_KEYS`**
Known SSH host keys for cloning private Git repositories via SSH (may be obtained using `ssh-keyscan`)
- **`git-ssh-private-key` | `GIT_SSH_PRIVATE_KEY`**
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ runs:
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}
ADDITIONAL_REPOS_FILE: ${{ inputs.additional-repos-file }}
ENABLE_RECURSIVE_VCS_IMPORT: ${{ inputs.enable-recursive-vcs-import }}

- name: Set up industrial_ci
if: ${{ inputs.enable-industrial-ci == 'true' }}
Expand Down Expand Up @@ -227,6 +229,8 @@ runs:
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}
ADDITIONAL_REPOS_FILE: ${{ inputs.additional-repos-file }}
ENABLE_RECURSIVE_VCS_IMPORT: ${{ inputs.enable-recursive-vcs-import }}
_ENABLE_IMAGE_PUSH: true
_IMAGE_POSTFIX: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) && format('_{0}_ci', steps.slugify-ref-name.outputs.slug) || '' }}

Expand Down Expand Up @@ -258,5 +262,7 @@ runs:
ENABLE_RECURSIVE_ADDITIONAL_PIP: ${{ inputs.enable-recursive-additional-pip }}
CUSTOM_SCRIPT_FILE: ${{ inputs.custom-script-file }}
ENABLE_RECURSIVE_CUSTOM_SCRIPT: ${{ inputs.enable-recursive-custom-script }}
ADDITIONAL_REPOS_FILE: ${{ inputs.additional-repos-file }}
ENABLE_RECURSIVE_VCS_IMPORT: ${{ inputs.enable-recursive-vcs-import }}
_ENABLE_IMAGE_PUSH: true
_IMAGE_POSTFIX: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) && format('_{0}_ci', steps.slugify-ref-name.outputs.slug) || '' }}
11 changes: 9 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ COPY docker/docker-ros/docker/recursive_vcs_import.py /usr/local/bin
RUN apt-get update && \
apt-get install -y python-is-python3 && \
rm -rf /var/lib/apt/lists/*
RUN /usr/local/bin/recursive_vcs_import.py src src/upstream

ARG ADDITIONAL_REPOS_FILE=".repos"
jpbusch marked this conversation as resolved.
Show resolved Hide resolved
ARG ENABLE_RECURSIVE_VCS_IMPORT="true"
RUN if [[ $ENABLE_RECURSIVE_ADDITIONAL_DEBS == 'true' ]]; then \
/usr/local/bin/recursive_vcs_import.py src/target src/upstream ${ADDITIONAL_REPOS_FILE}; \
jpbusch marked this conversation as resolved.
Show resolved Hide resolved
else \
vcs import src/upstream < src/target/${ADDITIONAL_REPOS_FILE} ; \
fi

# create install script with list of rosdep dependencies
RUN echo "set -e" >> $WORKSPACE/.install-dependencies.sh && \
Expand All @@ -81,7 +88,7 @@ ARG ENABLE_RECURSIVE_ADDITIONAL_DEBS="false"
RUN echo "apt-get install -y \\" >> $WORKSPACE/.install-dependencies.sh && \
set -o pipefail && \
if [[ $ENABLE_RECURSIVE_ADDITIONAL_DEBS == 'true' ]]; then \
find . -type f -name $(basename {ADDITIONAL_DEBS_FILE}) -exec sed '$a\' {} \; | awk '{print " " $0 " \\"}' >> $WORKSPACE/.install-dependencies.sh ; \
find . -type f -name $(basename ${ADDITIONAL_DEBS_FILE}) -exec sed '$a\' {} \; | awk '{print " " $0 " \\"}' >> $WORKSPACE/.install-dependencies.sh ; \
elif [[ -f src/target/${ADDITIONAL_DEBS_FILE} ]]; then \
cat src/target/${ADDITIONAL_DEBS_FILE} | awk '{print " " $0 " \\"}' >> $WORKSPACE/.install-dependencies.sh ; \
fi && \
Expand Down
9 changes: 6 additions & 3 deletions docker/recursive_vcs_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
from typing import List, Optional


def findDotRepos(search_path: str, clone_path: Optional[str] = None) -> List[pathlib.Path]:
def findDotRepos(search_path: str, clone_path: Optional[str] = None, repos_file: str = ".repos") -> List[pathlib.Path]:

repos = list(pathlib.Path(search_path).glob("**/*.repos"))
if clone_path is not None:
repos.extend(list(pathlib.Path(clone_path).glob("**/*.repos")))
repos.extend(list(pathlib.Path(clone_path).glob("**/*.repos"))) # find .repos in upstream dependencies
else:
repos = list(pathlib.Path(search_path).glob(f"**/*{repos_file}")) # find .repos in target repo
jpbusch marked this conversation as resolved.
Show resolved Hide resolved
return repos

def main():

search_path = sys.argv[1] if len(sys.argv) > 1 else "."
clone_path = sys.argv[2] if len(sys.argv) > 2 else "."
repos_file = sys.argv[3] if len(sys.argv) > 3 else ".repos"
cloned_repos = []

while True:

found_repos = findDotRepos(search_path, clone_path)
found_repos = findDotRepos(search_path, clone_path, repos_file)
remaining_repos = set(found_repos) - set(cloned_repos)

if not remaining_repos:
Expand Down
2 changes: 2 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ build_image() {
$(if [[ -n "${ENABLE_RECURSIVE_ADDITIONAL_PIP}" ]]; then echo "--build-arg ENABLE_RECURSIVE_ADDITIONAL_PIP=${ENABLE_RECURSIVE_ADDITIONAL_PIP}"; 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) \
$(if [[ -n "${ADDITIONAL_REPOS_FILE}" ]]; then echo "--build-arg ADDITIONAL_REPOS_FILE=${ADDITIONAL_REPOS_FILE}"; fi) \
$(if [[ -n "${ENABLE_RECURSIVE_VCS_IMPORT}" ]]; then echo "--build-arg ENABLE_RECURSIVE_VCS_IMPORT=${ENABLE_RECURSIVE_VCS_IMPORT}"; fi) \
.
echo "Successfully built stage '${TARGET}' for platform '${PLATFORM}' as '${IMAGE}'"
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ADDITIONAL_PIP_FILE="${ADDITIONAL_PIP_FILE:-}"
ENABLE_RECURSIVE_ADDITIONAL_PIP="${ENABLE_RECURSIVE_ADDITIONAL_PIP:-}"
CUSTOM_SCRIPT_FILE="${CUSTOM_SCRIPT_FILE:-}"
ENABLE_RECURSIVE_CUSTOM_SCRIPT="${ENABLE_RECURSIVE_CUSTOM_SCRIPT:-}"
ADDITIONAL_REPOS_FILE="${ADDITIONAL_REPOS_FILE:-}"
ENABLE_RECURSIVE_VCS_IMPORT="${ENABLE_RECURSIVE_VCS_IMPORT:-}"
_ENABLE_IMAGE_PUSH="${_ENABLE_IMAGE_PUSH:-false}"
_IMAGE_POSTFIX="${_IMAGE_POSTFIX:-""}"

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,10 +14,12 @@ x-build: &build
ADDITIONAL_DEBS_FILE: $ADDITIONAL_DEBS_FILE
ADDITIONAL_FILES_DIR: $ADDITIONAL_FILES_DIR
ADDITIONAL_PIP_FILE: $ADDITIONAL_PIP_FILE
ADDITIONAL_REPOS_FILE: $ADDITIONAL_REPOS_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_CUSTOM_SCRIPT: $ENABLE_RECURSIVE_CUSTOM_SCRIPT
ENABLE_RECURSIVE_VCS_IMPORT: $ENABLE_RECURSIVE_VCS_IMPORT
GIT_HTTPS_PASSWORD: $GIT_HTTPS_PASSWORD
GIT_HTTPS_SERVER: $GIT_HTTPS_SERVER
GIT_HTTPS_USER: $GIT_HTTPS_USER
Expand Down