Skip to content

Commit 00d9600

Browse files
Enable caching and dont replace default tags on PRs
1 parent 157ba91 commit 00d9600

7 files changed

+121
-10
lines changed

.github/workflows/build_and_publish_debian_docker.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Build and publish debian docker images
33

44
on:
55
workflow_dispatch:
6+
push:
7+
paths:
8+
- '.github/workflows/build_and_publish_debian_docker.yaml'
9+
- 'ros2_debian/**'
610
pull_request:
711
paths:
812
- '.github/workflows/build_and_publish_debian_docker.yaml'
@@ -41,17 +45,28 @@ jobs:
4145
steps:
4246
- uses: actions/checkout@v6
4347
- uses: docker/setup-buildx-action@v3
48+
- name: Set image tag
49+
id: image_meta
50+
run: |
51+
tag_suffix=""
52+
if [ "${{ github.event_name }}" = "pull_request" ]; then
53+
tag_suffix="-pr-${{ github.event.pull_request.number }}"
54+
fi
55+
echo "image_tag=${{ matrix.ros_distro }}-debian${tag_suffix}" >> "$GITHUB_OUTPUT"
4456
- uses: docker/login-action@v3
4557
with:
4658
registry: ghcr.io
4759
username: ${{ github.repository_owner }}
4860
password: ${{ secrets.GITHUB_TOKEN }}
49-
- uses: docker/build-push-action@v6
61+
- name: Build and push image
62+
uses: docker/build-push-action@v6
5063
with:
5164
context: ros2_debian
5265
push: true
5366
file: ros2_debian/Dockerfile.${{ matrix.debian_version }}
54-
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ matrix.ros_distro }}-debian
67+
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ steps.image_meta.outputs.image_tag }}
68+
cache-from: type=gha,scope=debian-${{ matrix.ros_distro }}
69+
cache-to: type=gha,scope=debian-${{ matrix.ros_distro }},mode=max
5570
build-args: |
5671
ROS_DISTRO=${{ matrix.ros_distro }}
5772
SOURCE_PACKAGES=${{ matrix.source_packages }}
@@ -68,3 +83,4 @@ jobs:
6883
target_workspace: ros_controls.${{ matrix.ROS_DISTRO }}.repos
6984
skip_packages_regex: '^mujoco_ros2_control.*$|^gz_ros2_control.*$|^ros2_control_demo_example_9$|^ros2_control_demos$'
7085
ref_for_scheduled_build: master
86+
docker_image_tag_suffix: ${{ github.event_name == 'pull_request' && format('-pr-{0}', github.event.pull_request.number) || '' }}

.github/workflows/build_and_publish_rhel_docker.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Build and publish RHEL docker images
33

44
on:
55
workflow_dispatch:
6+
push:
7+
paths:
8+
- '.github/workflows/build_and_publish_rhel_docker.yaml'
9+
- 'ros2_rhel/**'
610
pull_request:
711
paths:
812
- '.github/workflows/build_and_publish_rhel_docker.yaml'
@@ -40,17 +44,28 @@ jobs:
4044
steps:
4145
- uses: actions/checkout@v6
4246
- uses: docker/setup-buildx-action@v3
47+
- name: Set image tag
48+
id: image_meta
49+
run: |
50+
tag_suffix=""
51+
if [ "${{ github.event_name }}" = "pull_request" ]; then
52+
tag_suffix="-pr-${{ github.event.pull_request.number }}"
53+
fi
54+
echo "image_tag=${{ matrix.ros_distro }}-rhel${tag_suffix}" >> "$GITHUB_OUTPUT"
4355
- uses: docker/login-action@v3
4456
with:
4557
registry: ghcr.io
4658
username: ${{ github.repository_owner }}
4759
password: ${{ secrets.GITHUB_TOKEN }}
48-
- uses: docker/build-push-action@v6
60+
- name: Build and push image
61+
uses: docker/build-push-action@v6
4962
with:
5063
context: ros2_rhel
5164
push: true
5265
file: ros2_rhel/Dockerfile.${{ matrix.rhel_version }}
53-
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ matrix.ros_distro }}-rhel
66+
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ steps.image_meta.outputs.image_tag }}
67+
cache-from: type=gha,scope=rhel-${{ matrix.ros_distro }}
68+
cache-to: type=gha,scope=rhel-${{ matrix.ros_distro }},mode=max
5469
build-args: |
5570
ROS_DISTRO=${{ matrix.ros_distro }}
5671
SOURCE_PACKAGES=${{ matrix.source_packages }}
@@ -67,3 +82,4 @@ jobs:
6782
target_workspace: ros_controls.${{ matrix.ROS_DISTRO }}.repos
6883
skip_packages_regex: '^mujoco_ros2_control.*$|^gz_ros2_control.*$|^ros2_control_demo_example_9$|^ros2_control_demos$'
6984
ref_for_scheduled_build: master
85+
docker_image_tag_suffix: ${{ github.event_name == 'pull_request' && format('-pr-{0}', github.event.pull_request.number) || '' }}

.github/workflows/build_and_publish_ubuntu_docker.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Build and publish Ubuntu docker images
33

44
on:
55
workflow_dispatch:
6+
push:
7+
paths:
8+
- '.github/workflows/build_and_publish_ubuntu_docker.yaml'
9+
- 'ros2_ubuntu/**'
610
pull_request:
711
paths:
812
- '.github/workflows/build_and_publish_ubuntu_docker.yaml'
@@ -52,17 +56,32 @@ jobs:
5256
steps:
5357
- uses: actions/checkout@v6
5458
- uses: docker/setup-buildx-action@v3
59+
- name: Set image tag
60+
id: image_meta
61+
run: |
62+
tag_suffix=""
63+
if [ "${{ github.event_name }}" = "pull_request" ]; then
64+
tag_suffix="-pr-${{ github.event.pull_request.number }}"
65+
fi
66+
if [ "${{ matrix.ros-repo-packages }}" = "-testing" ]; then
67+
echo "image_tag=${{ matrix.ros_distro }}-ubuntu-testing${tag_suffix}" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "image_tag=${{ matrix.ros_distro }}-ubuntu${tag_suffix}" >> "$GITHUB_OUTPUT"
70+
fi
5571
- uses: docker/login-action@v3
5672
with:
5773
registry: ghcr.io
5874
username: ${{ github.repository_owner }}
5975
password: ${{ secrets.GITHUB_TOKEN }}
60-
- uses: docker/build-push-action@v6
76+
- name: Build and push image
77+
uses: docker/build-push-action@v6
6178
with:
6279
context: ros2_ubuntu
6380
push: true
6481
file: ros2_ubuntu/Dockerfile
65-
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ matrix.ros_distro }}-ubuntu${{ matrix.ros-repo-packages }}
82+
tags: ghcr.io/${{ github.repository_owner }}/ros:${{ steps.image_meta.outputs.image_tag }}
83+
cache-from: type=gha,scope=ubuntu-${{ matrix.ros_distro }}${{ matrix.ros-repo-packages }}
84+
cache-to: type=gha,scope=ubuntu-${{ matrix.ros_distro }}${{ matrix.ros-repo-packages }},mode=max
6685
build-args: |
6786
FROM=${{ matrix.base_image }}
6887
ROS_DISTRO=${{ matrix.ros_distro }}
@@ -81,6 +100,7 @@ jobs:
81100
ros_repo: ${{ matrix.ROS_REPO }}
82101
target_workspace: ros_controls.${{ matrix.ROS_DISTRO }}.repos
83102
ref_for_scheduled_build: master
103+
docker_image_tag_suffix: ${{ github.event_name == 'pull_request' && format('-pr-{0}', github.event.pull_request.number) || '' }}
84104

85105
compatibility-stack-build:
86106
needs: build_images
@@ -95,3 +115,4 @@ jobs:
95115
ros_repo: ${{ matrix.ROS_REPO }}
96116
target_workspace: ros_controls.rolling-on-${{ matrix.ROS_DISTRO }}.repos
97117
ref_for_scheduled_build: master
118+
docker_image_tag_suffix: ${{ github.event_name == 'pull_request' && format('-pr-{0}', github.event.pull_request.number) || '' }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: Cleanup PR-tagged docker images
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
workflow_dispatch:
8+
inputs:
9+
pr_number:
10+
description: 'PR number to clean up (required for manual runs)'
11+
required: false
12+
type: string
13+
14+
concurrency:
15+
group: cleanup-pr-images-${{ github.event.pull_request.number || inputs.pr_number || github.run_id }}
16+
cancel-in-progress: false
17+
18+
jobs:
19+
cleanup-pr-images:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
steps:
25+
- name: Resolve PR number
26+
id: resolve_pr
27+
shell: bash
28+
run: |
29+
PR_NUMBER="${{ github.event.pull_request.number || inputs.pr_number }}"
30+
if [[ -z "$PR_NUMBER" ]]; then
31+
echo "No PR number provided. Set workflow_dispatch input 'pr_number' or run on pull_request.closed."
32+
exit 1
33+
fi
34+
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
35+
- name: Delete PR-tagged GHCR versions
36+
uses: dataaxiom/ghcr-cleanup-action@v1
37+
with:
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
owner: ${{ github.repository_owner }}
40+
repository: ${{ github.event.repository.name }}
41+
packages: ros
42+
delete-tags: '*-pr-${{ steps.resolve_pr.outputs.pr_number }}'
43+
delete-untagged: false

.github/workflows/reusable-debian-build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ on:
4949
default: ""
5050
required: false
5151
type: string
52+
docker_image_tag_suffix:
53+
description: 'Optional suffix appended to the docker tag, e.g. -pr-123'
54+
default: ''
55+
required: false
56+
type: string
5257

5358

5459
jobs:
@@ -63,7 +68,7 @@ jobs:
6368
target_path: target_ws/src/${{ github.repository }}
6469
CCACHE_DIR: ${{ github.workspace }}/${{ inputs.ccache_dir }}
6570
CACHE_PREFIX: ${{ inputs.ros_distro }}-${{ inputs.upstream_workspace }}-${{ inputs.target_workspace }}-${{ github.job }}
66-
container: ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-debian
71+
container: ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-debian${{ inputs.docker_image_tag_suffix }}
6772
steps:
6873
- name: Checkout default ref when build is not scheduled
6974
if: ${{ github.event_name != 'schedule' }}

.github/workflows/reusable-industrial-ci-with-cache.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ on:
8282
default: 'rmw_cyclonedds_cpp'
8383
required: false
8484
type: string
85+
docker_image_tag_suffix:
86+
description: 'Optional suffix appended to the docker tag, e.g. -pr-123'
87+
default: ''
88+
required: false
89+
type: string
8590

8691

8792
jobs:
@@ -114,9 +119,9 @@ jobs:
114119
id: docker_image
115120
run: |
116121
if [ "${{ inputs.ros_repo }}" = "main" ]; then
117-
echo "DOCKER_IMAGE=ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-ubuntu" >> $GITHUB_OUTPUT
122+
echo "DOCKER_IMAGE=ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-ubuntu${{ inputs.docker_image_tag_suffix }}" >> $GITHUB_OUTPUT
118123
else
119-
echo "DOCKER_IMAGE=ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-ubuntu-testing" >> $GITHUB_OUTPUT
124+
echo "DOCKER_IMAGE=ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-ubuntu-testing${{ inputs.docker_image_tag_suffix }}" >> $GITHUB_OUTPUT
120125
fi
121126
- uses: 'ros-industrial/industrial_ci@master'
122127
env:

.github/workflows/reusable-rhel-binary-build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ on:
5252
default: ""
5353
required: false
5454
type: string
55+
docker_image_tag_suffix:
56+
description: 'Optional suffix appended to the docker tag, e.g. -pr-123'
57+
default: ''
58+
required: false
59+
type: string
5560

5661
jobs:
5762
rhel_binary:
5863
name: ${{ inputs.ros_distro }} RHEL build
5964
if: ${{ !(github.event_name == 'pull_request' && contains(join(github.event.pull_request.labels.*.name, ','), 'conflicts')) }}
6065
runs-on: ubuntu-latest
61-
container: ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-rhel
66+
container: ghcr.io/ros-controls/ros:${{ inputs.ros_distro }}-rhel${{ inputs.docker_image_tag_suffix }}
6267
env:
6368
target_ws: target_ws
6469
upstream_ws: upstream_ws

0 commit comments

Comments
 (0)