Solved! Go to Solution.
The Google Cloud Pub/Sub topic gcr
will receive events from the Artifact Registry for all image-related events, including pushing, deleting, or adding a tag. You can't limit the events sent to the Pub/Sub topic to only include push events for a specific image.
However, you can control this in your Google Cloud Function. When your Cloud Function receives a message from the Pub/Sub topic, it will include details about the event that triggered it. You can use this information to filter out events you're not interested in.
Here is an example of how you can handle this in your Google Cloud Function (Using Node.js):
exports.helloPubSub = (event, context) => {
const message = event.data
? Buffer.from(event.data, 'base64').toString()
: "No data!";
// Parse the message to a JSON object
const artifactData = JSON.parse(message);
// Check if the action is a PUSH action
if (artifactData.action !== "INSERT") {
console.log(`Skipping non-push event: ${artifactData.action}`);
return;
}
// Check if the event is for the specific image you're interested in
if (artifactData.resource.name !== "projects/_/locations/_/repositories/_/images/_") {
console.log(`Skipping event for different image: ${artifactData.resource.name}`);
return;
}
// TODO: Your code here...
};
In this code, artifactData.action
will contain the type of action that occurred (INSERT
, DELETE
, or TAG_INSERT
). artifactData.resource.name
will contain the name of the image that the event is for. You should replace "projects/_/locations/_/repositories/_/images/_"
with the name of the image you're interested in.
In this code, artifactData.action
will contain the type of action that occurred (INSERT
, DELETE
, or TAG_INSERT
). artifactData.resource.name
will contain the name of the image that the event is for. You should replace "projects/_/locations/_/repositories/_/images/_"
with the name of the image you're interested in.
This way, your Cloud Function will only execute its main logic when a push event occurs for the specific image you're interested in, and it will ignore all other events.
Please note that this will still result in your Cloud Function being triggered for all events, which could have cost implications depending on the number of events. However, the function will exit early and not perform any significant processing for events you're not interested in, which should limit the impact on cost and performance.
The Google Cloud Pub/Sub topic gcr
will receive events from the Artifact Registry for all image-related events, including pushing, deleting, or adding a tag. You can't limit the events sent to the Pub/Sub topic to only include push events for a specific image.
However, you can control this in your Google Cloud Function. When your Cloud Function receives a message from the Pub/Sub topic, it will include details about the event that triggered it. You can use this information to filter out events you're not interested in.
Here is an example of how you can handle this in your Google Cloud Function (Using Node.js):
exports.helloPubSub = (event, context) => {
const message = event.data
? Buffer.from(event.data, 'base64').toString()
: "No data!";
// Parse the message to a JSON object
const artifactData = JSON.parse(message);
// Check if the action is a PUSH action
if (artifactData.action !== "INSERT") {
console.log(`Skipping non-push event: ${artifactData.action}`);
return;
}
// Check if the event is for the specific image you're interested in
if (artifactData.resource.name !== "projects/_/locations/_/repositories/_/images/_") {
console.log(`Skipping event for different image: ${artifactData.resource.name}`);
return;
}
// TODO: Your code here...
};
In this code, artifactData.action
will contain the type of action that occurred (INSERT
, DELETE
, or TAG_INSERT
). artifactData.resource.name
will contain the name of the image that the event is for. You should replace "projects/_/locations/_/repositories/_/images/_"
with the name of the image you're interested in.
In this code, artifactData.action
will contain the type of action that occurred (INSERT
, DELETE
, or TAG_INSERT
). artifactData.resource.name
will contain the name of the image that the event is for. You should replace "projects/_/locations/_/repositories/_/images/_"
with the name of the image you're interested in.
This way, your Cloud Function will only execute its main logic when a push event occurs for the specific image you're interested in, and it will ignore all other events.
Please note that this will still result in your Cloud Function being triggered for all events, which could have cost implications depending on the number of events. However, the function will exit early and not perform any significant processing for events you're not interested in, which should limit the impact on cost and performance.