Reputation: 16780
I have a instance on GCP running a docker-compose file with many containers. The images are hosted on GCR.
I just want to "refresh" the running instance, pulling the new image, when some new image is available on GCR.
I'm using GitHub Actions to build and push the image to GCP.
I try the gcloud beta compute instances update-container
command but it expect to have just one image per instance.
I don't want to use Kubernetes for this.
What should be the best approach to that instance pull again the image when a new version is available?
Upvotes: 1
Views: 1556
Reputation: 889
TL;DR: use PUB/SUB to trigger the update of the image (docker pull) and the update of the running container.
When changes are made to your Container Registry repository, such as when images are pushed, tagged, or deleted, you can receive notifications using Pub/Sub. Pub/Sub publishes messages about your repository to named resources called topics. These messages are received by applications subscribed to Pub/Sub topics. Subscriber applications send notifications when your repository's state changes.
You can use Pub/Sub messages to execute commands inside your GCE instance. Google created an example named “Reliable Task Scheduling on Google Compute Engine with Cloud Scheduler” where they outline the process on how a GCE instance can execute a command when a certain message from certain topic is being published in Pub/Sub.
I know that the document talks about Cloud Scheduler, but Cloud Scheduler works by publishing messages to Pub/Sub topics. Since GCR can publish messages on actions, instead of using the Pub/Sub messages from Cloud Scheduler, you can trigger some updates inside your GCE instance by using the messages published by GCR.
Upvotes: 2