Last active
December 14, 2017 13:45
-
-
Save radu-matei/e886f85fcb4dd316f3016aa9a60210a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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