Skip to content

Commit

Permalink
Merge pull request #11 from OUXT-Polaris/feature/cache
Browse files Browse the repository at this point in the history
Feature/cache
  • Loading branch information
hakuturu583 authored Aug 29, 2023
2 parents baed54b + 5b2380e commit cb8414a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 11 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
types: [published]

jobs:
bake:
bake_no_cache:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -34,6 +34,28 @@ jobs:
workdir: ros2_pkg_builder/docker
files: |
./docker-bake.hcl
targets: |
builder
bake_cache_for_robotx_buildfarm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/bake-action@v3
with:
push: true
workdir: ros2_pkg_builder/docker
files: |
./docker-bake.hcl
targets: |
cache
build_python_packages:
strategy:
fail-fast: false
Expand Down
25 changes: 25 additions & 0 deletions ros2_pkg_builder/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def build_deb_packages(
build_builder_image: bool,
packages_above: str,
apt_server: str,
cache_image: str,
) -> None:
logger = get_logger(__name__)
logger.info("Start building debian packages.")
Expand All @@ -45,6 +46,19 @@ def build_deb_packages(
.joinpath("docker")
.joinpath("workspace.repos"),
)
if cache_image == "":
logger.info(
"Cache image was not specified, using ros:" + rosdistro + " as base image."
)
cache_image = "ros"
else:
logger.info(
"Cache image was specified, using "
+ cache_image
+ ":"
+ rosdistro
+ " as base image."
)
if build_builder_image:
logger.info("Building builder image for " + architecture + "/" + rosdistro)
docker.buildx.bake(
Expand All @@ -53,13 +67,15 @@ def build_deb_packages(
set={
"*.platform": "linux/" + architecture,
"*.context": Path(ros2_pkg_builder.__path__[0]).joinpath("docker"),
"*.args.IMAGE_NAME": cache_image,
},
files=[
Path(ros2_pkg_builder.__path__[0])
.joinpath("docker")
.joinpath("docker-bake.hcl")
],
)

docker.run(
image="wamvtan/ros2_pkg_builder:" + rosdistro,
volumes=[
Expand Down Expand Up @@ -105,6 +121,14 @@ def main():
default="",
help="List of build target packages.",
)
parser.add_argument(
"--cache-image",
type=str,
default="",
help="Docker image for caching rosdep dependency. \
This image is used for base image of builder image. \
If this value is empty, it means use no cache.",
)
parser.add_argument("--apt-server", type=str, default="ftp.jaist.ac.jp/pub/Linux")
args = parser.parse_args()
build_deb_packages(
Expand All @@ -114,6 +138,7 @@ def main():
args.build_builder_image,
args.packages_above,
args.apt_server,
args.cache_image,
)


Expand Down
3 changes: 2 additions & 1 deletion ros2_pkg_builder/docker/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG ROS_DISTRO=humble
FROM ros:${ROS_DISTRO} as build-base-stage
ARG IMAGE_NAME=ros
FROM ${IMAGE_NAME}:${ROS_DISTRO} as build-stage
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y \
Expand Down
16 changes: 16 additions & 0 deletions ros2_pkg_builder/docker/Dockerfile.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG ROS_DISTRO=humble
ARG IMAGE_NAME=ros
FROM ${IMAGE_NAME}:${ROS_DISTRO} as cache-stage

WORKDIR /workspace
RUN echo "repositories:" >> workspace.repos

ARG REPOS_FILE=workspace.repos
ADD ${REPOS_FILE} workspace.repos

ARG APT_SERVER=ftp.jaist.ac.jp/pub/Linux
RUN sed -i "[email protected]@$APT_SERVER@g" /etc/apt/sources.list
RUN vcs import . < workspace.repos
RUN apt update && rosdep install -iy --from-paths . --skip-keys $(colcon list -n | tr '\n' ',') && \
apt-get clean \
&& rm -rf /var/lib/apt/lists/*
44 changes: 42 additions & 2 deletions ros2_pkg_builder/docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
group "default" {
group "builder" {
targets = ["latest", "iron", "humble", "rolling"]
}

target "latest" {
target = "build-base-stage"
target = "build-stage"
dockerfile = "Dockerfile.builder"
tags = ["docker.io/wamvtan/ros2_pkg_builder:latest"]
args = {
Expand Down Expand Up @@ -35,3 +35,43 @@ target "humble" {
"ROS_DISTRO" : "humble"
}
}

// Grid map does not released in comment outed distribution
group "cache" {
targets = ["cache-latest", "cache-humble"] # "cache-iron", "cache-rolling" ]
}

target "cache-latest" {
target = "cache-stage"
dockerfile = "Dockerfile.cache"
tags = ["docker.io/wamvtan/robotx_buildfarm:latest"]
args = {
"ROS_DISTRO" : "latest",
"REPOS_FILE" : "https://raw.githubusercontent.com/OUXT-Polaris/ros2_pkg_builder/ouxt/repos/workspace.repos"
}
platforms = ["linux/amd64", "linux/arm64/v8"]
}

target "cache-rolling" {
inherits = ["cache-latest"]
tags = ["docker.io/wamvtan/robotx_buildfarm:rolling"]
args = {
"ROS_DISTRO" : "rolling"
}
}

target "cache-iron" {
inherits = ["cache-latest"]
tags = ["docker.io/wamvtan/robotx_buildfarm:iron"]
args = {
"ROS_DISTRO" : "iron"
}
}

target "cache-humble" {
inherits = ["cache-latest"]
tags = ["docker.io/wamvtan/robotx_buildfarm:humble"]
args = {
"ROS_DISTRO" : "humble"
}
}
15 changes: 8 additions & 7 deletions ros2_pkg_builder/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/bin/bash

# Building packages
echo "Changing apt server to $APT_SERVER"
sed -i "[email protected]@$APT_SERVER@g" /etc/apt/sources.list

vcs import . < workspace.repos
cd /artifacts
sh update_apt_repo.sh

apt update
rosdep install -iy -t buildtool_export -t build -t buildtool -t build_export -t test --from-paths . --skip-keys $(colcon list -n | tr '\n' ',')
cd /workspace

vcs import . < workspace.repos

colcon list -t -p | xargs -L 1 bash -c \
'cd "$1"; pkg=$(colcon list -n);pkg_with_prefix=$(echo $pkg|echo "ros-humble-"$(sed -e 's/_/-/g')); \
yq eval -i ".\"$pkg\".ubuntu=[\"$pkg_with_prefix\"]" /artifacts/rosdep/${ROS_DISTRO}.yaml' _
rosdep update

cd /artifacts && sh update_apt_repo.sh
apt update
rosdep install -iy --from-paths . --skip-keys $(colcon list -n | tr '\n' ',')

cd /workspace && colcon list -t -p --packages-above $PACKAGES_ABOVE | xargs -I{} bash -c \
'echo {} && cd {} && \
rosdep install -iy -t buildtool_export -t build -t buildtool -t build_export -t test --from-paths . && \
rosdep install -iy --from-paths . && \
bloom-generate rosdebian --os-name ubuntu --os-version $DEB_DISTRO --ros-distro $ROS_DISTRO && \
fakeroot debian/rules binary && cd /artifacts && sh update_apt_repo.sh && \
dpkg -i /artifacts/dists/$DEB_DISTRO/universe/binary-$ARCHITECTURE/ros-$ROS_DISTRO-*.deb'
Expand Down

0 comments on commit cb8414a

Please sign in to comment.