Trigger a Github deploy action after dockerhub automated build

Hi,

I have a question regarding triggering a GitHub workflow action after Docker Hub automated build is finished.

Before we had a Github workflow which would build a docker image à push to Docker hub à Pull the image à deploy/release to our environment.

Which works very well but we decided to test with building with Docker hub automated build instead.

Only problem is that we are unable to trigger a workflow deploy action after Docker hub is finished building the image. We already looked at the webhook part but it’s not clear to me how this part works.

So, in short what we would like to do is:

  • Commit code to branch develop → docker hub builds image with tag:develop → docker hub triggers Github action Deploy to development.
  • Commit code to branch test → docker hub builds image with tag:test → docker hub triggers Github action Deploy to test.

To trigger a GitHub workflow action after a Docker Hub automated build is finished, you can use webhooks.

Here are the steps you can follow:

  1. In your GitHub repository, go to “Settings” and select “Webhooks.”
  2. Click “Add webhook” and enter the following information:
  • Payload URL: The URL of the GitHub workflow action you want to trigger.
  • Content type: Select “application/json.”
  • Secret: A secret string that you will use to authenticate requests from Docker Hub.
  • Events: Select “Push.”
  1. Save the webhook.

Next, you will need to configure Docker Hub to send a webhook request to your GitHub repository when the automated build is finished.

Here are the steps you can follow:

  1. In Docker Hub, go to your repository and select “Build Settings.”
  2. Under “Build Triggers,” select “Configure Automated Builds.”
  3. Under “Build Triggers,” select “Create Build Trigger.”
  4. Select “GitHub” as the trigger type and enter your GitHub repository URL.
  5. Under “Webhooks,” enter the following information:
  • Payload URL: The URL of the GitHub webhook you created earlier.
  • Content type: Select “application/json.”
  • Secret: The secret string you entered earlier.
  • Events: Select “Push.”
  1. Save the build trigger.

Now, when you push code to a branch, Docker Hub will build the image and send a webhook request to your GitHub repository. GitHub will then trigger the workflow action you specified in the webhook settings.

Hi Landon12,

First of all thanks for your response.

Here are the steps I have taken,

Actions taken in GITHUB
Github → repostitory settings → Webhooks → Add Webhook

Payload URL: https://api.github.com/repos/{CompanyName}/{RepostitoryName}/actions/workflows/{ActionName.yml}/dispatches
Secret: A secret string
Events: Push

When I save it shows:
Last delivery was not succesfull, invalid HTTP response 403

I tested the same url with postman and that works well.


Actions taken in POSTMAN

POST
Payload URL

HEADERS
Accept: application/vnd.github.everest-preview+json
Content-Type: application/json

BODY
{
“ref”: “develop”
}

AUTHENTICATION

I created a Github PAT for authentication


Actions taken in DOCKER HUB

Organizations → Namespace → Repostitories → {{Repository Name} → Builds → Configure Automated Builds

Source Repostory: {CompanyName} {RepositoryName}
AUTOTEST: Off
REPOSITORY LINKS: Off

BUILD RULES:

Source Type: Branch
Source: Develop
Docker Tag: latest
Dockerfile location: Dockerfile
Build Context: /
Autobuild: on
Build Caching: on

Pushing code to develop branch triggers a build as expected.

From here on I have 2 options, “BUILD ENVIRONMENT VARIABLES” and “BUILD TRIGGERS”

When adding a build trigger I have an option to give it a name for example GithubAction and thats it.

Name
Trigger Url
GithubAction
https://hub.docker.com/api/build/v1/source/241e1a20-5a65-4777-a81d-3a9584dbf32f/trigger/a4dc2a7f-0901-4547-97c3-55bf29ba6b72/call/

When I add a Webhook my only option is to give it a name and a Webhook url
Name: GithubAction
URL: Payload URL

I have no other configuration options.

It looks like dome steps don’t match with, like for example step 4 “Select Github as the trigger”

Am I missing something?

1 Like