Skip to content

Instantly share code, notes, and snippets.

@radu-matei
Last active December 14, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radu-matei/e886f85fcb4dd316f3016aa9a60210a2 to your computer and use it in GitHub Desktop.
Save radu-matei/e886f85fcb4dd316f3016aa9a60210a2 to your computer and use it in GitHub Desktop.
func updateAzureContainer(resourceGroupName, containerGroupName string, webhookData WebhookData) error {
containerGroupsClient, err := getContainerGroupsClient()
if err != nil {
return fmt.Errorf("cannot get container groups client: %v", err)
}
containerGroup, err := containerGroupsClient.Get(resourceGroupName, containerGroupName)
if err != nil {
return fmt.Errorf("cannot get container group: %v", err)
}
containers := *containerGroup.Containers
for index, container := range containers {
image := *container.Image
newVersion := fmt.Sprintf("%s/%s:%s",
webhookData.Repository.Namespace,
webhookData.Repository.Name,
webhookData.PushData.Tag)
if image == fmt.Sprintf("%s/%s", webhookData.Repository.Namespace, webhookData.Repository.Name) {
updatedContainer := (*containerGroup.Containers)[index]
*updatedContainer.Image = newVersion
_, err := containerGroupsClient.CreateOrUpdate(resourceGroupName, containerGroupName, containerGroup)
if err != nil {
return fmt.Errorf("cannot update container: %v", err)
}
fmt.Printf("updated container image to new version: %s", newVersion)
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment