Skip to content

Commit

Permalink
Merge pull request allenh1#7 from tiiuae/new_build_scripts
Browse files Browse the repository at this point in the history
New build scripts
  • Loading branch information
mehmetkillioglu authored Jan 4, 2022
2 parents cc550b5 + 3a3b3ec commit 0219771
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 19 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ on:
jobs:
tii-deb-build:
runs-on: ubuntu-latest
strategy:
matrix:
ros2_distro: [foxy, galactic]
steps:

- name: Checkout rplidar_ros2
uses: actions/checkout@v2
with:
path: rplidar_ros2

- name: Checkout ci-scripts
uses: actions/checkout@v2
with:
repository: tiiuae/fogsw-ci-scripts
path: fogsw-ci-scripts

# Run docker build
- name: Run rplidar_ros2 docker build
env:
ROS: 1
ROS_DISTRO: ${{ matrix.ros2_distro }}
PACKAGE_NAME: rplidar_ros2
run: |
set -eux
mkdir bin
pushd fogsw-ci-scripts
export ROS=1
./generate_deb.sh ../rplidar_ros2 ../bin/
pushd rplidar_ros2
./build.sh ../bin/
popd
- name: Install jfrog CLI tool
env:
JFROG_CLI_URL: https://artifactory.ssrc.fi/artifactory/gen-public-local/tools/jfrog/jfrog-1.45.2.tar.gz
JFROG_CLI_URL: https://ssrc.jfrog.io/artifactory/ssrc-gen-public-remote-cache/tools/jfrog/jfrog-1.45.2.tar.gz
if: github.event_name == 'push'
run: |
set -exu
Expand All @@ -58,7 +58,7 @@ jobs:
set -exu
jfrog rt c import "$ARTIFACTORY_TOKEN"
jfrog rt ping
pkg=$(find bin -name 'ros-foxy-rplidar-ros2*.deb')
pkg=$(find bin -name 'ros-${{ matrix.ros2_distro }}-rplidar-ros2*.deb')
jfrog rt u --deb "$DISTRIBUTION/$COMPONENT/$ARCHITECTURE" \
--target-props COMMIT="$GITHUB_SHA" \
--build-name "$BUILD_NAME" \
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/tii-rplidar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: tii-rplidar

on:
push:
branches: new_ros2
tags:
- 'v*'
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+
pull_request:
branches: [ new_ros2 ]

jobs:
tii-rplidar:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:

- uses: actions/checkout@v2

- uses: docker/setup-buildx-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host

- name: Build the builder container image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.build_env
push: true
tags: localhost:5000/tiiuae/rplidar:build_env
build-args: |
PACKAGE_NAME=rplidar
ROS_DISTRO=foxy
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/tiiuae/tii-rplidar
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
if: github.event_name == 'push'
with:
registry: ghcr.io
username: ${{ secrets.GCR_PACKAGES_USER }}
password: ${{ secrets.GCR_PACKAGES_TOKEN }}

- name: Build tii-rplidar image and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
PACKAGE_NAME=rplidar
ROS_DISTRO=foxy
FROM_IMAGE=localhost:5000/tiiuae/rplidar:build_env
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
# clion
.idea

# ignore build directories
*build*

# ignore install directory from colcon
*install*

# ros2 log
log/

debian/
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# fog-sw BUILDER
ARG FROM_IMAGE
FROM $FROM_IMAGE as fog-sw-builder
ARG ROS_DISTRO="galactic"
ARG UID=1000
ARG GID=1000
ARG PACKAGE_NAME

WORKDIR /$PACKAGE_NAME/main_ws
USER root
ADD . /$PACKAGE_NAME/main_ws/src
RUN chown -R builder:builder /$PACKAGE_NAME/main_ws

USER builder

RUN if [ -e /$PACKAGE_NAME/deps_ws ]; then \
. /$PACKAGE_NAME/deps_ws/install/setup.sh && \
colcon build; \
elif [ -e /opt/ros/${ROS_DISTRO}/setup.sh ]; then \
. /opt/ros/${ROS_DISTRO}/setup.sh && \
colcon build; \
fi

RUN sed --in-place \
's|^source .*|source "/'$PACKAGE_NAME'/main_ws/install/setup.bash"|' \
/$PACKAGE_NAME/entrypoint.sh && \
chmod +x /$PACKAGE_NAME/entrypoint.sh

ENV PACKAGE_NAME $PACKAGE_NAME
WORKDIR /$PACKAGE_NAME
ENTRYPOINT "/"$PACKAGE_NAME"/entrypoint.sh"
44 changes: 44 additions & 0 deletions Dockerfile.build_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# fog-sw BUILDER
ARG ROS_DISTRO="galactic"
FROM ros:${ROS_DISTRO}-ros-base as fog-sw-builder

ARG UID=1000
ARG GID=1000
ARG BUILD_NUMBER
ARG COMMIT_ID
ARG GIT_VER
ARG PACKAGE_NAME
# Install build dependencies
RUN apt-get update -y && apt-get install -y --no-install-recommends \
curl \
python3-bloom \
fakeroot \
dh-make \
libboost-dev \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd -g $GID builder && \
useradd -m -u $UID -g $GID -g builder builder && \
usermod -aG sudo builder && \
echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

RUN echo "deb [trusted=yes] https://ssrc.jfrog.io/artifactory/ssrc-debian-public-remote focal fog-sw" >> /etc/apt/sources.list

RUN mkdir -p /$PACKAGE_NAME/packaging

COPY packaging/rosdep.yaml* packaging/rosdep.sh packaging/build_deps.sh /$PACKAGE_NAME/packaging/
COPY underlay.repos package.xml /$PACKAGE_NAME/packaging/
COPY entrypoint.sh* /$PACKAGE_NAME/

RUN /$PACKAGE_NAME/packaging/rosdep.sh /$PACKAGE_NAME

RUN chown -R builder:builder /$PACKAGE_NAME

USER builder

RUN rosdep update

RUN /$PACKAGE_NAME/packaging/build_deps.sh /$PACKAGE_NAME

VOLUME /$PACKAGE_NAME/sources
WORKDIR /$PACKAGE_NAME/sources
40 changes: 40 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -euxo pipefail

output_dir=$1

git_commit_hash=${2:-$(git rev-parse HEAD)}

git_version_string=${3:-$(git log --date=format:%Y%m%d --pretty=~git%cd.%h -n 1)}

build_number=${GITHUB_RUN_NUMBER:=0}

ros_distro=${ROS_DISTRO:=foxy}

iname=${PACKAGE_NAME:=rplidar_ros2}

iversion=${PACKAGE_VERSION:=latest}

docker build \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
--build-arg ROS_DISTRO=${ros_distro} \
--build-arg PACKAGE_NAME=${iname} \
--pull \
-f Dockerfile.build_env -t "${iname}_build:${iversion}" .

docker run \
--rm \
-v $(pwd):/${iname}/sources \
${iname}_build:${iversion} \
./packaging/package.sh \
-b ${build_number} \
-g ${git_commit_hash} \
-v ${git_version_string}

mkdir -p ${output_dir}
cp *.deb *.ddeb ${output_dir}
rm -Rf *.deb *.ddeb

exit 0
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

source /opt/ros/foxy/setup.bash
ros2 launch rplidar_ros2 sensors_launch.py
6 changes: 5 additions & 1 deletion launch/sensors_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from launch.substitutions import LaunchConfiguration
from launch.substitutions import PythonExpression
from launch.substitutions import ThisLaunchFileDir
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
import os
Expand All @@ -16,6 +17,8 @@ def generate_launch_description():

# environment variables
DRONE_DEVICE_ID = os.getenv('DRONE_DEVICE_ID')
# If the SIMULATION environment variable is set to 1, then only static tf publisher will start.
SIMULATION = os.getenv('SIMULATION')

# arguments
ld.add_action(DeclareLaunchArgument("rplidar_mode", default_value="outdoor"))
Expand All @@ -27,7 +30,7 @@ def generate_launch_description():
# Boost: optimized for sample rate
# Stability: for light elimination performance, but shorter range and lower sample rate
rplidar_mode = PythonExpression(['"Stability" if "outdoor" == "', LaunchConfiguration("rplidar_mode"), '" else "Sensitivity"'])

simulation_mode = (SIMULATION == "1")
#namespace declarations
namespace = DRONE_DEVICE_ID

Expand All @@ -41,6 +44,7 @@ def generate_launch_description():
namespace = namespace,
package = 'rplidar_ros2',
executable = 'rplidar',
condition=IfCondition(PythonExpression(['not ', str(simulation_mode)])),
name = 'rplidar',
parameters = [{
'serial_port': LaunchConfiguration("serial_port"),
Expand Down
51 changes: 51 additions & 0 deletions packaging/build_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

set -eo pipefail

mod_dir=${1}

# Extract not satisfied dependencies from output, check if they are exist in ../underlay.repos
if rosdep check --from-paths ${mod_dir} 1> /dev/null 2>&1; then
echo "[INFO] Dependencies are satisfied."
else
echo "[INFO] Building dependencies using underlay.repos."
cd ${mod_dir}

echo "[INFO] Get package dependencies."
# Dependencies from fog-sw repo
if [ -e ${mod_dir}/ros2_ws/src ]; then
echo "[INFO] Use dependencies from fog_sw."
pushd ${mod_dir}/ros2_ws > /dev/null
source /opt/ros/${ROS_DISTRO}/setup.bash
else
echo "[INFO] Use dependencies from local repository."
mkdir -p ${mod_dir}/deps_ws/src
pushd ${mod_dir}/deps_ws > /dev/null
vcs import src < ${mod_dir}/packaging/underlay.repos
rosdep install --from-paths src --ignore-src -r -y --rosdistro ${ROS_DISTRO}
source /opt/ros/${ROS_DISTRO}/setup.bash
fi

rosdep_out=$(rosdep check -v --from-paths src 2>&1 | grep "resolving for resources" )
ALL_PKGS=$(echo $rosdep_out | sed 's/.*\[\(.*\)\].*/\1/' | tr ',' '\n' | tr -d ' ')
echo "[INFO] All packages: $(echo $ALL_PKGS|tr '\n' ' ')"
PKGS_TO_BUILD=""
pushd src > /dev/null

for pkg_name in ${ALL_PKGS}; do
echo "[INFO] Check if package ${pkg_name} is in the list of packages to build."
pkg_name=$(echo ${pkg_name} | sed 's/\/$//')
if ! ros2 pkg list | grep ${pkg_name} 1> /dev/null 2>&1; then
PKGS_TO_BUILD="${PKGS_TO_BUILD} ${pkg_name}"
fi
done

echo "[INFO] Packages to build: $PKGS_TO_BUILD"
popd > /dev/null

echo "[INFO] Build package dependencies."
colcon build --packages-select ${PKGS_TO_BUILD}
popd > /dev/null
fi


Loading

0 comments on commit 0219771

Please sign in to comment.