diff --git a/.github/workflows/docker-build-push.yaml b/.github/workflows/docker-template.yaml similarity index 57% rename from .github/workflows/docker-build-push.yaml rename to .github/workflows/docker-template.yaml index dd33ddb..48af60f 100644 --- a/.github/workflows/docker-build-push.yaml +++ b/.github/workflows/docker-template.yaml @@ -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 @@ -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' @@ -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 \ No newline at end of file diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..3ced894 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -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