0

I am trying to read the sent notifications from Google Cloud Container Registry after an image has been altered using the Pub/Sub service but I am unable to make it work. I have followed the steps described here: https://cloud.google.com/container-registry/docs/configuring-notifications

  • I created the subscription foo for the topic projects/[PROJECT-ID]/topics/gcr (this topic already existed) and gave the permissions to the service account
  • I created the following script in ruby taken from the doc to test the subscription:

    require 'google/cloud/pubsub'
    
    pubsub = Google::Cloud::Pubsub.new(
      project_id:  '[PROJECT-ID]',
      credentials: 'my-credentials.json'
    )
    
    sub = pubsub.subscription 'foo'
    
    subscriber = sub.listen do |received_message|
      puts received_message.message.data
      received_message.acknowledge!
    end
    
    subscriber.start
    sleep
    

After that, I published a message within in the Google Cloud Console and the content is actually printed, so, the subscription seems to work fine.

The problem is that if I a push an image to the Google Cloud Container Registry, the image is available in the console as well, but I did not receive any message.

The only thing that might be slightly different is that I am pushing the the image using the regular docker command instead of gcloud docker (I previously logged in into the registry using the credentials), but I assume that's not the problem.

Borja Martín
  • 111
  • 2
  • 2
  • Weird. Just to figure out if this is a Pub/Sub issue or a GCR issue, could you try creating a Google Cloud Function, choosing Pub/Sub, and selecting the gcr topic? Then try pushing a new image. This will let us know if the issue is the sender or the receiver :) – Justin Beckwith Feb 06 '18 at 17:13

1 Answers1

0

Do you never receive a message? Running your code, I receive an {"action":"INSERT","digest":... message exactly once. This is as intended, since you have this line right after printing:

  received_message.acknowledge!

If you then kill the process and re-run without having made any changes to any image in the registry, you should not expect to see any messages. If you leave the subscriber listening, you will see notifications for any subsequent changes made to the registry.

Now, if you actually want to see the whole list of image actions (push, delete, tag, etc) every time you run your code, you could stop acknowledging the messages you pull.

Lefteris S
  • 1,614
  • 1
  • 7
  • 14