Skip to content

Build and Release Docker Image #90

Build and Release Docker Image

Build and Release Docker Image #90

Workflow file for this run

---
name: Build and Release Docker Image
on:
schedule:
# 7am UTC, 12am PST
- cron: '0 7 * * *'
push:
# For developer updates to trigger
branches:
- main
jobs:
nightly_docker:
name: Build and Release Nightly Docker Images From Current Source
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ros_distro: [humble, iron, jazzy, rolling]
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
pull: true
tags: ghcr.io/${{ github.repository }}:${{ matrix.ros_distro }}-nightly
platforms: linux/amd64,linux/arm64
build-args: |
ROS_DISTRO=${{ matrix.ros_distro }}
BUILD=true
release_docker:
name: Build and Release Current Nav2 Relased Version of Docker Images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version:
- { ros_distro: 'humble', main_version: '1', distro_version: '1' }
- { ros_distro: 'iron', main_version: '1', distro_version: '2' }
- { ros_distro: 'jazzy', main_version: '1', distro_version: '3' }
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Latest Tag to Build
id: get_tag
run: |
# Fetch tags from the repository
tags=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/ros-navigation/navigation2/tags | \
jq -r '.[].name')
# Get the filtered set from the release
filtered_tags=$(echo "$tags" | grep '^${{ matrix.version.main_version }}\.${{ matrix.version.distro_version }}\.[0-9]*$')
# Find the highest tag
highest_tag=$(echo "$filtered_tags" | sort -V | tail -n 1)
# Output the highest tag
echo "Highest tag: $highest_tag"
echo "highest_tag=$highest_tag" >> $GITHUB_OUTPUT
- name: Get Latest Package Version Already Built
id: latest_released_package
run: |
page=1
per_page=100
all_tags=""
while true; do
echo "Fetching page $page"
response=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/orgs/ros-navigation/packages/container/nav2_docker/versions?per_page=$per_page&page=$page")
# echo "Response from API (Page $page):"
# echo "$response"
# Check if the response is empty
if [ "$(echo "$response" | jq length)" -eq 0 ]; then
echo "No more versions found, stopping pagination."
break
fi
# Extract tags from the response
ros_distro="${{ matrix.version.ros_distro }}"
main_version="${{ matrix.version.main_version }}"
distro_version="${{ matrix.version.distro_version }}"
echo "ROS_DISTRO: $ros_distro"
echo "MAIN_VERSION: $main_version"
echo "DISTRO_VERSION: $distro_version"
extracted_tags=$(echo "$response" | jq -r '.[] | .metadata.container.tags[]')
echo "Extracted tags: $extracted_tags"
matching_tags=$(echo "$extracted_tags" | grep -E "^${ros_distro}-${main_version}\.${distro_version}\." || true)
echo "Matching Tags: $matching_tags"
# Break if the response is empty (no more pages)
# if [ -z "$extracted_tags" ]; then
# echo "No more tags found, breaking loop."
# break
# fi
all_tags="$all_tags"$'\n'"$matching_tags"
echo "All tags found: $all_tags"
page=$((page + 1))
echo "new page: $page"
done
echo "All collected tags:"
echo "$all_tags"
# Sort and find the latest version
latest_version=$(echo "$all_tags" | sort -V | tail -n 1)
# Check if we successfully found the latest version
if [ -z "$latest_version" ]; then
echo "Error: No matching package versions found."
exit 1
fi
echo "Latest version found: $latest_version"
stripped_version=$(echo "$latest_version" | cut -d '-' -f 2-)
echo "Latest version found: $stripped_version"
echo "version=$stripped_version" >> $GITHUB_OUTPUT
- name: Build and Push if New
if: steps.latest_released_package.outputs.version != steps.get_tag.outputs.highest_tag
uses: docker/build-push-action@v6
with:
push: true
pull: true
tags: ghcr.io/${{ github.repository }}:${{ matrix.version.ros_distro }}-${{ steps.get_tag.outputs.highest_tag }}
platforms: linux/amd64,linux/arm64
build-args: |
ROS_DISTRO=${{ matrix.version.ros_distro }}
BUILD=true
VERSION=${{ steps.get_tag.outputs.highest_tag }}