Skip to content

Commit

Permalink
fix race condition when updating registry settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell committed Sep 12, 2023
1 parent 91d014e commit 004d72d
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions pkg/handlers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,31 @@ func (h *Handler) UpdateAppRegistry(w http.ResponseWriter, r *http.Request) {
return
}

skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}

// set task status before starting the goroutine so that the UI can show the status
if err := store.GetStore().SetTaskStatus("image-rewrite", "Updating registry settings", "running"); err != nil {
logger.Error(errors.Wrap(err, "failed to set task status"))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}

// in a goroutine, start pushing the images to the remote registry
// we will let this function return while this happens
go func() {
skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
return
}

appDir, err := registry.RewriteImages(
foundApp.ID, latestSequence, updateAppRegistryRequest.Hostname,
updateAppRegistryRequest.Username, registryPassword,
Expand Down

0 comments on commit 004d72d

Please sign in to comment.