cloud-pipeline
cloud-pipeline copied to clipboard
[GCP Artifact Registry] Support notifications for GCP Artifact Registry
Background
For local docker registry new tools are automatically registered using DockerRegistryController.notifyDockerRegistryEvents API method (it is possible to configure a hook that will be called on any docker registry event. GCP Artifactory also provides a was to receive notifications from push events: https://cloud.google.com/artifact-registry/docs/configure-notifications
Approach Check notification approach suggested by GCP https://cloud.google.com/artifact-registry/docs/configure-notifications and investigate if it is possible to used it for platform deployed in GCP.
Any change in artifact registry will be put in topic named "gcr".
source: https://cloud.google.com/run/docs/tutorials/pubsub
- gcloud config set project PROJECT_ID
- gcloud config set run/region REGION
- gcloud artifacts repositories create REPOSITORY --repository-format=docker --location=REGION
- gcloud pubsub topics create myRunTopic
- git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
- cd java-docs-samples/run/pubsub/
- gcloud auth configure-docker
- mvn compile jib:build -D image=REGION-docker.pkg.dev/PROJECT_ID/REPOSITORY/pubsub
- gcloud run deploy pubsub-tutorial --image REGION-docker.pkg.dev/PROJECT_ID/REPOSITORY/pubsub --no-allow-unauthenticated
- gcloud iam service-accounts create cloud-run-pubsub-invoker \ --display-name "Cloud Run Pub/Sub Invoker"
- gcloud run services add-iam-policy-binding pubsub-tutorial \ --member=serviceAccount:cloud-run-pubsub-invoker@PROJECT_ID.iam.gserviceaccount.com \ --role=roles/run.invoker
- gcloud projects add-iam-policy-binding PROJECT_ID \ --member=serviceAccount:[email protected] \ --role=roles/iam.serviceAccountTokenCreator
- gcloud pubsub subscriptions create myRunSubscription --topic myRunTopic \ --ack-deadline=600 \ --push-endpoint=SERVICE-URL/ \ --push-auth-service-account=cloud-run-pubsub-invoker@PROJECT_ID.iam.gserviceaccount.com
- gcloud pubsub topics publish myRunTopic --message "Runner"
message formats: 1. When tag is removed for an image: { "action": "DELETE", "tag": "europe-west3-docker.pkg.dev/project/docker-repository/postgres:9.6" }
2. When image is removed: { "action": "DELETE", "digest": "europe-west3-docker.pkg.dev/project/docker-repository/postgres@sha256:decbf20be3383f2ba0cfcf67addd5b635d442b4739132e666ed407b6f98abfc6" }
3. When image is added : { "action": "INSERT", "digest": "europe-west3-docker.pkg.dev/project/docker-repository/cellprofile-web-api@sha256:806e5058a24278842880f47e73adb35673cad7e1c1bfa2c1192fa9e20fa99978", "tag": "europe-west3-docker.pkg.dev/project/docker-repository/cellprofile-web-api:bkp3" }
This is the raw format of a message from pub/sub:
{ "message": { "data": "base64-encoded-data", "messageId": "13603399295873681", "message_id": "13603399295873681", "publishTime": "2025-03-12T07:55:12.681Z", "publish_time": "2025-03-12T07:55:12.681Z" }, "subscription": "projects/hl2-epm-gnai10-t1iylu/subscriptions/myRunSubscription" }
in "message" -> "data" could be one of the 3 options of messages described previously