Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 8 additions & 4 deletions internal/helpers/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -48,17 +48,21 @@ 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)
if err != nil {
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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers/tag_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading