Sync docker images across repos

Hi all,
I am struggling with the approach to synchronising docker image versions published using GitHub actions. Here is my setup:

Repo 1 (ui app)
Repo 2 (e2e tests)

I’ve got actions setup in both repos that create a release (using rymndhng/release-on-push-action) with a minor version bump and then build//publish the respective docker image (using the latest version) to Github package registry.

What I would like to achieve is a way to keep the release versions in sync so I don’t have to keep track of which e2e image to run against a particular ui app image. In essence, when a new e2e image is published (say v2) it should cut a v2 release in ui app and publish it. Conversely when ui v3 is published it should bump e2e to v3 but avoid any race conditions.

I’m reading up on webhook events and will give them a shot but in the meantime if you can share your thoughts, I’d really appreciate it.

@r-s-sandbox,

You can try like as this:

  1. On Repo 1 (ui app), set the workflow like as below.
# .github/workflows/ci.yml
name: CI

on: 
  workflow_dispatch:
    inputs:
      version:
        description: 'Version of image.'
        required: true
  push:
    branches: 
      - main

jobs:
  get_version:
    name: Get version of image
    outputs:
      image_version: ${{ steps.get_ver.outputs.image_version }}
    runs-on: ubuntu-latest
    steps:
      - name: Generate version
        id: get_ver
        run: |
          if [[ ${{ github.event_name }} == push ]]; then
            echo "::set-output name=image_version::IMAGE_VERSION"
          else
            echo "::set-output name=image_version::${{ github.event.inputs.version }}"
          fi

  publish_image:
    name: Publish imgae to GitHub Packages Registry
    needs: [get_version]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build image
        run: |
          docker build -f Dockerfile . \
            -t docker.pkg.github.com/owner/repo1/image-1:${{ needs.get_version.outputs.image_version }} \
            -t docker.pkg.github.com/owner/repo1/image-1:latest

      - name: Login to GitHub Packages Registry
        run: docker login docker.pkg.github.com -u $GITHUB_ACTOR -p ${{ github.token }}

      - name: Publish image
        run: |
          docker push docker.pkg.github.com/owner/repo1/image-1:${{ needs.get_version.outputs.image_version }}
          docker push docker.pkg.github.com/owner/repo1/image-1:latest

  create_workflow_dispatch:
    if: ${{ github.event_name == 'push' }}
    needs: [get_version]
    runs-on: ubuntu-latest
    steps:
      - name: Create a workflow dispatch event
        run: |
          curl \
            -X POST \
            -H "Authorization: token ${{ secrets.API_AUTH_PAT }}" \
            -H "Accept: application/vnd.github.v3+json" \
            https://api.github.com/repos/owner/repo2/actions/workflows/ci.yml/dispatches \
            -d '{
              "ref": "main",
              "inputs": {
                "version": "${{ needs.get_version.outputs.image_version }}"
              }
            }'
  1. On Repo 2 (e2e tests), set the workflow like as below.
# .github/workflows/ci.yml
name: CI

on: 
  workflow_dispatch:
    inputs:
      version:
        description: 'Version of image.'
        required: true
  push:
    branches: 
      - main

jobs:
  get_version:
    . . .

  publish_image:
    name: Publish imgae to GitHub Packages Registry
    needs: [get_version]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build image
        run: |
          docker build -f Dockerfile . \
            -t docker.pkg.github.com/owner/repo2/image-2:${{ needs.get_version.outputs.image_version }} \
            -t docker.pkg.github.com/owner/repo2/image-2:latest

      - name: Login to GitHub Packages Registry
        run: docker login docker.pkg.github.com -u $GITHUB_ACTOR -p ${{ github.token }}

      - name: Publish image
        run: |
          docker push docker.pkg.github.com/owner/repo2/image-2:${{ needs.get_version.outputs.image_version }}
          docker push docker.pkg.github.com/owner/repo2/image-2:latest

  create_workflow_dispatch:
    if: ${{ github.event_name == 'push' }}
    needs: [get_version]
    runs-on: ubuntu-latest
    steps:
      - name: Create a workflow dispatch event
        run: |
          curl \
            -X POST \
            -H "Authorization: token ${{ secrets.API_AUTH_PAT }}" \
            -H "Accept: application/vnd.github.v3+json" \
            https://api.github.com/repos/owner/repo1/actions/workflows/ci.yml/dispatches \
            -d '{
              "ref": "main",
              "inputs": {
                "version": "${{ needs.get_version.outputs.image_version }}"
              }
            }'