Skip to content

Commit

Permalink
Merge pull request #90 from xfiderek/feat/refspec-match
Browse files Browse the repository at this point in the history
Add ref-spec matching of spaceros repository (#91).
  • Loading branch information
Bckempa authored Jan 11, 2024
2 parents 3e87f73 + 3790bdc commit 5c0c061
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
36 changes: 33 additions & 3 deletions spaceros/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ earthfile:
setup:
# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive

# The following commands are based on the source install for ROS 2 Rolling Ridley.
# See: https://docs.ros.org/en/ros2_documentation/rolling/Installation/Ubuntu-Development-Setup.html
# The main variation is getting Space ROS sources instead of the Rolling sources.
Expand Down Expand Up @@ -74,7 +74,6 @@ setup:
ENV HOME_DIR=/home/${USERNAME}
ENV SPACEROS_DIR=${HOME_DIR}/spaceros
ARG IKOS_DIR=${HOME_DIR}/ikos
ARG REPOS_FILE_URL="https://raw.githubusercontent.com/space-ros/space-ros/main/ros2.repos"
ENV ROSDISTRO=humble

# Create a spaceros user
Expand All @@ -92,9 +91,40 @@ setup:
RUN sudo add-apt-repository ppa:kisak/kisak-mesa
RUN sudo apt update && sudo apt upgrade -y

spaceros-artifacts:
# we must run it in a separate container, so that downstream tasks can be cached if vcs file does not change
FROM ubuntu:jammy
RUN apt-get update && apt-get install -y git wget

# main purpose of this command is to make sure that the git ls-remote results are not cached
RUN --no-cache echo "Cloning spaceros repo artifacts"

# current git branch, prefilled by earthly: https://docs.earthly.dev/docs/earthfile/builtin-args
ARG EARTHLY_GIT_BRANCH

ARG SPACEROS_REPO_URL="https://github.com/space-ros/space-ros.git"
# if current local branch does not exist in target repo then use main. note that branch supplied from CLI overrides this behavior.
ARG SPACEROS_GIT_REF="$( [ -n \"$(git ls-remote $SPACEROS_REPO_URL $EARTHLY_GIT_BRANCH)\" ] && echo $EARTHLY_GIT_BRANCH || echo 'main' )"
# get exact commit hash. this makes sure that build will be re-triggered when new commit is pushed
ARG _GIT_COMMIT_HASH = "$(git ls-remote $SPACEROS_REPO_URL $SPACEROS_GIT_REF | cut -f 1)"

# this means that branch specified by user from CLI does not exist
IF [ -z ${_GIT_COMMIT_HASH} ]
RUN echo "Specified branch ${SPACEROS_GIT_REF} does not exist" && exit 1
END

IF [ $SPACEROS_REPO_URL = "https://github.com/space-ros/space-ros.git" ]
# run wget because main repo's host is known + it is public
RUN wget https://raw.githubusercontent.com/space-ros/space-ros/${_GIT_COMMIT_HASH}/ros2.repos
ELSE
GIT CLONE --branch ${_GIT_COMMIT_HASH} ${SPACEROS_REPO_URL} .
END
SAVE ARTIFACT ros2.repos

sources:
FROM +setup
COPY github.com/space-ros/space-ros:earthly-wrapper+repos-file/ros2.repos ros2.repos
COPY +spaceros-artifacts/ros2.repos ros2.repos

RUN mkdir src
RUN vcs import src < ros2.repos
SAVE ARTIFACT src AS LOCAL src
Expand Down
6 changes: 6 additions & 0 deletions spaceros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ $ ./build.sh

The build process will take about 20 or 30 minutes, depending on the host computer.

The build process defaults to cloning the `ros2.repos` file from [spaceros](https://github.com/space-ros/space-ros) repository. It looks for a branch with the same name as the current local branch; if it doesn't find one, it falls back to cloning from the main branch. For testing purposes, you can customize both the spaceros repository URL and the branch name by modifying arguments defined in the [Earthfile](./Earthfile).
Example:
```bash
earthly +image --SPACEROS_REPO_URL="https://github.com/my-org/my-spaceros-fork.git" --SPACEROS_GIT_REF="my-branch-name"
```

## Running the Space ROS Docker Image in a Container

After building the image, you can see the newly-built image by running:
Expand Down

0 comments on commit 5c0c061

Please sign in to comment.