diff --git a/cmd/deploy.go b/cmd/deploy.go index 4089b128..f5bd9449 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -259,7 +259,7 @@ func runDeploy(cmd *cobra.Command, args []string) error { if deploySettings.Roxie.Version != "" { log.Dimf("Using main image tag %s", deploySettings.Roxie.Version) } else { - mainImageTag, err := helpers.LookupMainImageTag(ctx) + mainImageTag, err := helpers.LookupMainImageTag(ctx, deploySettings.Roxie.ImageRegistry) if err != nil { return fmt.Errorf("looking up main image tag: %w", err) } diff --git a/internal/helpers/tag.go b/internal/helpers/tag.go index 2c5e7302..72ac0bb3 100644 --- a/internal/helpers/tag.go +++ b/internal/helpers/tag.go @@ -16,7 +16,7 @@ import ( "github.com/stackrox/roxie/internal/stackroxversions" ) -func LookupMainImageTag(ctx context.Context) (string, error) { +func LookupMainImageTag(ctx context.Context, imageRegistry string) (string, error) { log.Dim("Checking if main image tag is defined in the environment") if tag := os.Getenv("MAIN_IMAGE_TAG"); tag != "" { log.Infof("Using MAIN_IMAGE_TAG from environment: %s", tag) @@ -38,7 +38,7 @@ func LookupMainImageTag(ctx context.Context) (string, error) { log.Warning("Alternatively, execute roxie from within the stackrox repository, in which case the currently checked out stackrox tag will be used") log.Dim("Checking what the latest released version tag is") - latestTag, err := LookupLatestTag(ctx) + latestTag, err := LookupLatestTag(ctx, imageRegistry) if err != nil { return "", fmt.Errorf("looking up latest release tag: %w", err) } @@ -48,7 +48,7 @@ func LookupMainImageTag(ctx context.Context) (string, error) { } // Computes the latest image tag for a pullable, released main image. -func LookupLatestTag(ctx context.Context) (string, error) { +func LookupLatestTag(ctx context.Context, imageRegistry string) (string, error) { const atMost = 5 tags, err := stackroxversions.LookupLatestReleaseTagsViaGitHub(ctx, atMost) @@ -56,9 +56,13 @@ func LookupLatestTag(ctx context.Context) (string, error) { return "", fmt.Errorf("looking up latest release tags: %w", err) } + if imageRegistry == "" { + imageRegistry = constants.DefaultRegistry + } + // Verify we have a pullable main image. for _, tag := range tags { - mainImage := fmt.Sprintf("%s/main:%s", constants.DefaultRegistry, tag) + mainImage := fmt.Sprintf("%s/main:%s", imageRegistry, tag) if err := ocihelper.VerifyImageExistence(ctx, mainImage); err != nil { var te *transport.Error if errors.As(err, &te) && te.StatusCode == http.StatusNotFound { diff --git a/internal/helpers/tag_integration_test.go b/internal/helpers/tag_integration_test.go index 5384d8cf..d2ad40be 100644 --- a/internal/helpers/tag_integration_test.go +++ b/internal/helpers/tag_integration_test.go @@ -23,7 +23,7 @@ func TestLookupLatestTag_Integration(t *testing.T) { ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute) defer cancel() - tag, err := LookupLatestTag(ctx) + tag, err := LookupLatestTag(ctx, "") require.NoError(t, err) require.NotEmpty(t, tag) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 75c39a9d..38469c31 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -50,7 +50,7 @@ func TestMain(m *testing.M) { func lookupLatestTag() (string, error) { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() - tag, err := helpers.LookupLatestTag(ctx) + tag, err := helpers.LookupLatestTag(ctx, "") if err != nil { return "", err }