Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
name: Build and Push Docker Image (native amd64 & arm64)
name: Template - Build and Push Docker Image

on:
push:
branches: ["main", "workflow"]
pull_request:
workflow_call:
inputs:
image_name:
description: 'The name of the image (e.g., high-flyers/ros-core)'
required: true
type: string
dockerfile_path:
description: 'Path to the Dockerfile'
required: true
type: string
base_tag:
description: 'The base tag for the image (e.g., latest)'
required: false
type: string
default: latest

env:
REGISTRY: ghcr.io
IMAGE_NAME: high-flyers/ros-core

jobs:
build:
strategy:
matrix:
ros_distro: [humble, jazzy]
arch: [amd64, arm64]
include:
- arch: amd64
runner: ubuntu-latest
Expand All @@ -37,31 +46,28 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set image tags
- name: Set PR Tag Suffix
id: vars
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BRANCH_NAME="${{ github.head_ref }}"
SAFE_BRANCH=$(echo "$BRANCH_NAME" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
echo "TAG=-$SAFE_BRANCH" >> $GITHUB_OUTPUT
echo "SUFFIX=-$SAFE_BRANCH" >> $GITHUB_OUTPUT
else
echo "TAG=" >> $GITHUB_OUTPUT
echo "SUFFIX=" >> $GITHUB_OUTPUT
fi

- name: Build and push image (${{ matrix.ros_distro }} - ${{ matrix.platform }})
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
file: ./images/ros-core-${{ matrix.ros_distro }}.Dockerfile
file: ${{ inputs.dockerfile_path }}
push: true
platforms: ${{ matrix.platform }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-${{ matrix.arch }}${{ steps.vars.outputs.TAG }}
${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.base_tag }}-${{ matrix.arch }}${{ steps.vars.outputs.SUFFIX }}

manifest:
strategy:
matrix:
ros_distro: [humble, jazzy]
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
Expand All @@ -75,9 +81,9 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create and push multi-arch manifest for ${{ matrix.ros_distro }}
- name: Create and push multi-arch manifest
run: |
docker buildx imagetools create \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-amd64 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-arm64
-t ${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.base_tag }} \
${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.base_tag }}-amd64 \
${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.base_tag }}-arm64
26 changes: 26 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Push Docker Image (native amd64 & arm64)

on:
push:
branches: ["main", "workflow"]
pull_request:

jobs:
docker-distros:
strategy:
matrix:
ros_distro: [humble, jazzy]
uses: ./.github/workflows/docker-template.yaml
with:
image_name: high-flyers/ros-core
dockerfile_path: ./images/ros-core-${{ matrix.ros_distro }}.Dockerfile
base_tag: ${{ matrix.ros_distro }}
secrets: inherit

docker-latest:
uses: ./.github/workflows/docker-template.yaml
with:
image_name: high-flyers/ros-core
dockerfile_path: ./images/ros-core-humble.Dockerfile
base_tag: latest
secrets: inherit
Loading