Skip to content

Commit

Permalink
ci: Reuse docker cache
Browse files Browse the repository at this point in the history
  • Loading branch information
j3soon committed Dec 13, 2024
1 parent 0bba42e commit 2cdb988
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 183 deletions.
76 changes: 64 additions & 12 deletions .github/workflows/build-gazebo-world-ws.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
name: Build Docker Image for gazebo-world-ws

on:
push:
branches:
- "main"
tags:
- v*
paths:
- .github/workflows/build-gazebo-world-ws.yaml
- gazebo_world_ws/docker/Dockerfile
- gazebo_world_ws/docker/.dockerignore
- gazebo_world_ws/docker/.bashrc
workflow_run:
workflows: ["Build Docker Image for template-ws"]
types: [completed]

jobs:
paths-filter:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
results: ${{ steps.filter.outputs.results }}
steps:
# Ref: https://github.com/dorny/paths-filter/issues/147#issuecomment-1287800590
- name: Download a single artifact
uses: dawidd6/action-download-artifact@v7
with:
workflow: build-template-ws.yaml
name: original-refs
workflow_conclusion: success
- name: set REF_BASE to env
run: |
echo "BASE=$(cat base.txt)" >> $GITHUB_ENV
echo "CURRENT_BRANCH=$(cat current-branch.txt)" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ env.BASE }}
ref: ${{ env.CURRENT_BRANCH }}
filters: |
results:
- .github/workflows/build-gazebo-world-ws.yaml
- gazebo_world_ws/docker/Dockerfile
- gazebo_world_ws/docker/.dockerignore
- gazebo_world_ws/docker/.bashrc
- name: Changes matched
if: steps.filter.outputs.results == 'true'
run: echo "Changes matched, will build image"
- name: Changes didn't match
if: steps.filter.outputs.results != 'true'
run: echo "Changes didn't match, will NOT build image"
docker:
if: github.repository == 'j3soon/ros2-essentials'
needs: paths-filter
if: ${{ needs.paths-filter.outputs.results == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Maximize build space
Expand Down Expand Up @@ -42,6 +71,8 @@ jobs:
# Output the environment variable
# Ref: https://stackoverflow.com/a/57989070
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Print for debugging purpose
echo "VERSION=$VERSION"
- name: Docker meta
id: meta
# Ref: https://github.com/docker/metadata-action
Expand All @@ -57,9 +88,30 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull j3soon/ros2-template-ws (amd64)
run: docker pull --platform linux/amd64 j3soon/ros2-template-ws
- name: Pull j3soon/ros2-template-ws (arm64)
run: docker pull --platform linux/arm64 j3soon/ros2-template-ws
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: gazebo_world_ws/docker
cache-from: |
${{ secrets.DOCKERHUB_USERNAME }}/ros2-template-ws:buildcache-amd64
${{ secrets.DOCKERHUB_USERNAME }}/ros2-template-ws:buildcache-arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
- name: Push amd64 cache
uses: docker/build-push-action@v6
with:
context: template_ws/docker
cache-to: ${{ secrets.DOCKERHUB_USERNAME }}/ros2-gazebo-world-ws:buildcache-amd64
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
- name: Push arm64 cache
uses: docker/build-push-action@v6
with:
context: template_ws/docker
cache-to: ${{ secrets.DOCKERHUB_USERNAME }}/ros2-gazebo-world-ws:buildcache-arm64
platforms: linux/arm64
tags: ${{ steps.meta.outputs.tags }}
62 changes: 55 additions & 7 deletions .github/workflows/build-template-ws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,49 @@ on:
- "main"
tags:
- v*
paths:
- .github/workflows/build-template-ws.yaml
- template_ws/docker/Dockerfile
- template_ws/docker/.dockerignore
- template_ws/docker/.bashrc

jobs:
docker:
paths-filter:
if: github.repository == 'j3soon/ros2-essentials'
runs-on: ubuntu-latest
outputs:
results: ${{ steps.filter.outputs.results }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
results:
- .github/workflows/build-template-ws.yaml
- template_ws/docker/Dockerfile
- template_ws/docker/.dockerignore
- template_ws/docker/.bashrc
- name: Changes matched
if: steps.filter.outputs.results == 'true'
run: echo "Changes matched, will build image"
- name: Changes didn't match
if: steps.filter.outputs.results != 'true'
run: echo "Changes didn't match, will NOT build image"
# Ref: https://github.com/dorny/paths-filter/issues/147#issuecomment-1287800590
- name: Save base ref info
run: |
BASE=${{ github.event.before }}
CURRENT_BRANCH=${{ github.ref }}
echo $BASE > base.txt
echo $CURRENT_BRANCH > current-branch.txt
- name: Upload base ref info
uses: actions/upload-artifact@v4
with:
name: original-refs
path: |
base.txt
current-branch.txt
retention-days: 1
docker:
needs: paths-filter
if: ${{ needs.paths-filter.outputs.results == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
Expand Down Expand Up @@ -62,9 +95,24 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: template_ws/docker
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
# Ref: https://github.com/docker/buildx/discussions/1382#discussioncomment-6252049
- name: Push amd64 cache
uses: docker/build-push-action@v6
with:
context: template_ws/docker
cache-to: ${{ secrets.DOCKERHUB_USERNAME }}/ros2-template-ws:buildcache-amd64
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
- name: Push arm64 cache
uses: docker/build-push-action@v6
with:
context: template_ws/docker
cache-to: ${{ secrets.DOCKERHUB_USERNAME }}/ros2-template-ws:buildcache-arm64
platforms: linux/arm64
tags: ${{ steps.meta.outputs.tags }}
164 changes: 82 additions & 82 deletions gazebo_world_ws/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,85 +53,85 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
zip \
&& rm -rf /var/lib/apt/lists/*

# Install Python pip
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && apt-get install -y \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Install GUI debugging tools
# - `x11-apps` and `x11-utils` for `xeyes` and `xdpyinfo`
# Ref: https://packages.debian.org/sid/x11-apps
# Ref: https://packages.debian.org/sid/x11-utils
# - `mesa-utils` for `glxgears` and `glxinfo`
# Ref: https://wiki.debian.org/Mesa
# - `vulkan-tools` for `vkcube` and `vulkaninfo`
# Ref: https://docs.vulkan.org/tutorial/latest/02_Development_environment.html#_vulkan_packages
# Ref: https://gitlab.com/nvidia/container-images/vulkan/-/blob/master/docker/Dockerfile.ubuntu
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && apt-get install -y \
x11-apps x11-utils \
mesa-utils \
libgl1 vulkan-tools \
&& rm -rf /var/lib/apt/lists/*

# Setup the required capabilities for the container runtime
# Ref: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/docker-specialized.html#driver-capabilities
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=all

# Install Vulkan config files
# Ref: https://gitlab.com/nvidia/container-images/vulkan
RUN cat > /etc/vulkan/icd.d/nvidia_icd.json <<EOF
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "libGLX_nvidia.so.0",
"api_version" : "1.3.194"
}
}
EOF

# Install ROS2 Gazebo packages for amd64
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
if [ "$TARGETARCH" = "amd64" ]; then \
apt-get update && apt-get install -y \
ros-$ROS_DISTRO-gazebo-ros-pkgs \
ros-$ROS_DISTRO-gazebo-ros2-control \
&& rm -rf /var/lib/apt/lists/*; \
fi

# Install ROS2 RVIZ and other custom ROS2 packages
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && apt-get install -y \
ros-$ROS_DISTRO-rviz2 \
&& rm -rf /var/lib/apt/lists/*

USER $USERNAME

# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount
RUN mkdir /home/$USERNAME/.gazebo

# Install Isaac Sim (requires Python 3.10)
# Note that installing Isaac Sim with pip is experimental, keep this in mind when unexpected error occurs
# TODO: Remove the note above when it is no longer experimental
# Ref: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_python.html#installation-using-pip
RUN --mount=type=cache,target=/home/$USERNAME/.cache/pip,sharing=private \
if [ "$TARGETARCH" = "amd64" ]; then \
python3 -V | grep "Python 3.10" \
&& pip install isaacsim==4.2.0.2 --extra-index-url https://pypi.nvidia.com \
&& pip install isaacsim-extscache-physics==4.2.0.2 isaacsim-extscache-kit==4.2.0.2 isaacsim-extscache-kit-sdk==4.2.0.2 --extra-index-url https://pypi.nvidia.com; \
fi

# Install custom tools
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
sudo apt-get update && sudo apt-get install -y \
git-extras \
&& sudo rm -rf /var/lib/apt/lists/*

# TODO: Add more commands here
COPY --chown=$USERNAME:$USERNAME \
.bashrc /home/$USERNAME/.bashrc
# TODO: Copy additional files here
ENTRYPOINT []
CMD ["/bin/bash"]
# # Install Python pip
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
# apt-get update && apt-get install -y \
# python3-pip \
# && rm -rf /var/lib/apt/lists/*
#
# # Install GUI debugging tools
# # - `x11-apps` and `x11-utils` for `xeyes` and `xdpyinfo`
# # Ref: https://packages.debian.org/sid/x11-apps
# # Ref: https://packages.debian.org/sid/x11-utils
# # - `mesa-utils` for `glxgears` and `glxinfo`
# # Ref: https://wiki.debian.org/Mesa
# # - `vulkan-tools` for `vkcube` and `vulkaninfo`
# # Ref: https://docs.vulkan.org/tutorial/latest/02_Development_environment.html#_vulkan_packages
# # Ref: https://gitlab.com/nvidia/container-images/vulkan/-/blob/master/docker/Dockerfile.ubuntu
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
# apt-get update && apt-get install -y \
# x11-apps x11-utils \
# mesa-utils \
# libgl1 vulkan-tools \
# && rm -rf /var/lib/apt/lists/*
#
# # Setup the required capabilities for the container runtime
# # Ref: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/docker-specialized.html#driver-capabilities
# ENV NVIDIA_VISIBLE_DEVICES=all
# ENV NVIDIA_DRIVER_CAPABILITIES=all
#
# # Install Vulkan config files
# # Ref: https://gitlab.com/nvidia/container-images/vulkan
# RUN cat > /etc/vulkan/icd.d/nvidia_icd.json <<EOF
# {
# "file_format_version" : "1.0.0",
# "ICD": {
# "library_path": "libGLX_nvidia.so.0",
# "api_version" : "1.3.194"
# }
# }
# EOF
#
# # Install ROS2 Gazebo packages for amd64
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
# if [ "$TARGETARCH" = "amd64" ]; then \
# apt-get update && apt-get install -y \
# ros-$ROS_DISTRO-gazebo-ros-pkgs \
# ros-$ROS_DISTRO-gazebo-ros2-control \
# && rm -rf /var/lib/apt/lists/*; \
# fi
#
# # Install ROS2 RVIZ and other custom ROS2 packages
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
# apt-get update && apt-get install -y \
# ros-$ROS_DISTRO-rviz2 \
# && rm -rf /var/lib/apt/lists/*
#
# USER $USERNAME
#
# # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount
# RUN mkdir /home/$USERNAME/.gazebo
#
# # Install Isaac Sim (requires Python 3.10)
# # Note that installing Isaac Sim with pip is experimental, keep this in mind when unexpected error occurs
# # TODO: Remove the note above when it is no longer experimental
# # Ref: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_python.html#installation-using-pip
# RUN --mount=type=cache,target=/home/$USERNAME/.cache/pip,sharing=private \
# if [ "$TARGETARCH" = "amd64" ]; then \
# python3 -V | grep "Python 3.10" \
# && pip install isaacsim==4.2.0.2 --extra-index-url https://pypi.nvidia.com \
# && pip install isaacsim-extscache-physics==4.2.0.2 isaacsim-extscache-kit==4.2.0.2 isaacsim-extscache-kit-sdk==4.2.0.2 --extra-index-url https://pypi.nvidia.com; \
# fi
#
# # Install custom tools
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
# sudo apt-get update && sudo apt-get install -y \
# git-extras \
# && sudo rm -rf /var/lib/apt/lists/*
#
# # TODO: Add more commands here
# COPY --chown=$USERNAME:$USERNAME \
# .bashrc /home/$USERNAME/.bashrc
# # TODO: Copy additional files here
# ENTRYPOINT []
# CMD ["/bin/bash"]
Loading

0 comments on commit 2cdb988

Please sign in to comment.