Skip to content

Commit

Permalink
Add new build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
maseabunikie committed Jan 19, 2022
1 parent cc31857 commit ddeedcb
Show file tree
Hide file tree
Showing 15 changed files with 567 additions and 17 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ on:
jobs:
tii-deb-build:
runs-on: ubuntu-latest
strategy:
matrix:
ros2_distro: [galactic]
steps:

- name: Checkout mocap_pose
- name: Checkout moca_pose
uses: actions/checkout@v2
with:
path: mocap_pose
submodules: recursive

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

# Run docker build
- name: Run fog-sw docker build
- name: Run mocap_pose docker build
env:
ROS: 1
ROS_DISTRO: ${{ matrix.ros2_distro }}
PACKAGE_NAME: mocap_pose
run: |
set -eux
mkdir bin
pushd fogsw-ci-scripts
./generate_deb.sh ../mocap_pose ../bin/
pushd mocap_pose
./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
if: github.event_name == 'push'
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' || github.event.action == 'rebuild'
run: |
set -exu
mkdir -p "$GITHUB_WORKSPACE/.jfrog/bin"
Expand All @@ -53,12 +53,12 @@ jobs:
ARCHITECTURE: amd64
BUILD_NAME: mocap-pose
CI: true
if: github.event_name == 'push'
if: github.event_name == 'push' || github.event.action == 'rebuild'
run: |
set -exu
jfrog rt c import "$ARTIFACTORY_TOKEN"
jfrog rt ping
pkg=$(find bin -name 'ros-foxy-mocap-pose*.deb')
pkg=$(find bin -name 'ros-${{ matrix.ros2_distro }}-mocap-pose*.deb')
jfrog rt u --deb "$DISTRIBUTION/$COMPONENT/$ARCHITECTURE" \
--target-props COMMIT="$GITHUB_SHA" \
--build-name "$BUILD_NAME" \
Expand All @@ -68,4 +68,4 @@ jobs:
jfrog rt build-publish "$BUILD_NAME" "$GITHUB_SHA"
jfrog rt bpr "$BUILD_NAME" "$GITHUB_SHA" "$ARTIFACTORY_REPO" \
--status dev \
--comment "development build"
--comment "development build"
72 changes: 72 additions & 0 deletions .github/workflows/tii-mocap-pose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: tii-mocap-pose

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

jobs:
tii-mocap-pose:
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/mocap_pose:build_env
build-args: |
PACKAGE_NAME=mocap_pose
ROS_DISTRO=galactic
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/tiiuae/tii-mocap-pose
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: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build tii-mocap-pose 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=mocap_pose
ROS_DISTRO=galactic
FROM_IMAGE=localhost:5000/tiiuae/mocap_pose:build_env
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:=galactic}

iname=${PACKAGE_NAME:=mocap_pose}

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
2 changes: 2 additions & 0 deletions debian/postinst → debian/postinst.em
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="2357", ATTRS{idProduct}=="011e", MODE="0666"
EOF

chmod 644 /etc/udev/rules.d/81-tplink.rules

exit 0
2 changes: 2 additions & 0 deletions debian/prerm → debian/prerm.em
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
if [ -e /etc/udev/rules.d/81-tplink.rules ]; then
rm /etc/udev/rules.d/81-tplink.rules
fi

exit 0
1 change: 0 additions & 1 deletion debian/shlibs.local

This file was deleted.

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/galactic/setup.bash

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 ddeedcb

Please sign in to comment.