Skip to content

Commit

Permalink
--release mirror from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
d2285 committed Feb 2, 2025
1 parent d5ddccc commit 3c41b83
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
35 changes: 26 additions & 9 deletions internal/mirror/cmd/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/md5"
"fmt"
"github.com/deckhouse/deckhouse-cli/internal/mirror/releases"
"io"
"log/slog"
"os"
Expand All @@ -35,7 +36,6 @@ import (

"github.com/deckhouse/deckhouse-cli/internal/mirror/gostsums"
"github.com/deckhouse/deckhouse-cli/internal/mirror/manifests"
"github.com/deckhouse/deckhouse-cli/internal/mirror/releases"
"github.com/deckhouse/deckhouse-cli/pkg/libmirror/bundle"
"github.com/deckhouse/deckhouse-cli/pkg/libmirror/contexts"
"github.com/deckhouse/deckhouse-cli/pkg/libmirror/images"
Expand Down Expand Up @@ -119,6 +119,11 @@ func buildPullContext() *contexts.PullContext {
}
logger := log.NewSLogger(logLevel)

//if SpecificVersion.Prerelease() != "" {
// pr := mirrorCtx.SpecificVersion.Prerelease()
// accessValidationTag = fmt.Sprintf("%s", pr)
//}

mirrorCtx := &contexts.PullContext{
BaseContext: contexts.BaseContext{
Logger: logger,
Expand Down Expand Up @@ -153,13 +158,17 @@ func pull(_ *cobra.Command, _ []string) error {
return fmt.Errorf("Cleanup last unfinished pull data: %w", err)
}
}

accessValidationTag := "alpha"
if mirrorCtx.SpecificVersion != nil {
major := mirrorCtx.SpecificVersion.Major()
minor := mirrorCtx.SpecificVersion.Minor()
patch := mirrorCtx.SpecificVersion.Patch()
accessValidationTag = fmt.Sprintf("v%d.%d.%d", major, minor, patch)
if mirrorCtx.SpecificVersion.Prerelease() != "" {
pr := mirrorCtx.SpecificVersion.Prerelease()
accessValidationTag = fmt.Sprintf("%s", pr)
} else {
major := mirrorCtx.SpecificVersion.Major()
minor := mirrorCtx.SpecificVersion.Minor()
patch := mirrorCtx.SpecificVersion.Patch()
accessValidationTag = fmt.Sprintf("v%d.%d.%d", major, minor, patch)
}
}
readAccessTimeoutCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
if err := auth.ValidateReadAccessForImageContext(
Expand All @@ -176,13 +185,21 @@ func pull(_ *cobra.Command, _ []string) error {
}
cancel()

//var versionsToMirror []semver.Version
var versionsToMirror []semver.Version
var err error
err = logger.Process("Looking for required Deckhouse releases", func() error {

if mirrorCtx.SpecificVersion != nil {
versionsToMirror = append(versionsToMirror, *mirrorCtx.SpecificVersion)
logger.InfoF("Skipped releases lookup as release %v is specifically requested with --release", mirrorCtx.SpecificVersion)
return nil
if mirrorCtx.SpecificVersion.Prerelease() != "" {
versionsToMirror = append(versionsToMirror, *mirrorCtx.SpecificVersion)
logger.InfoF("Skipped releases lookup as release %v is specifically requested with --release", mirrorCtx.SpecificVersion.Prerelease())
return nil
} else {
versionsToMirror = append(versionsToMirror, *mirrorCtx.SpecificVersion)
logger.InfoF("Skipped releases lookup as release %v is specifically requested with --release", mirrorCtx.SpecificVersion)
return nil
}
}

versionsToMirror, err = releases.VersionsToMirror(mirrorCtx)
Expand Down
6 changes: 6 additions & 0 deletions internal/mirror/cmd/pull/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -85,6 +86,11 @@ func parseAndValidateVersionFlags() error {
if specificReleaseString != "" {
SpecificRelease, err = semver.NewVersion(specificReleaseString)
if err != nil {
if strings.HasPrefix(specificReleaseString, "pr") {
prTag := fmt.Sprintf("0.0.0-%s", specificReleaseString)
SpecificRelease, err = semver.NewVersion(prTag)
return nil
}
return fmt.Errorf("Parse required deckhouse version: %w", err)
}
}
Expand Down
22 changes: 17 additions & 5 deletions pkg/libmirror/layouts/layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ type ociLayout struct {
func FillLayoutsWithBasicDeckhouseImages(
mirrorCtx *contexts.PullContext,
layouts *ImageLayouts,
//deckhouseVersions []semver.Version,
deckhouseVersions []semver.Version,

) {
layouts.DeckhouseImages = map[string]struct{}{}
layouts.InstallImages = map[string]struct{}{}
Expand All @@ -207,11 +209,21 @@ func FillLayoutsWithBasicDeckhouseImages(
mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-checks:0": {},
}

for _, version := range deckhouseVersions {
layouts.DeckhouseImages[fmt.Sprintf("%s:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.InstallImages[fmt.Sprintf("%s/install:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.InstallStandaloneImages[fmt.Sprintf("%s/install-standalone:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.ReleaseChannelImages[fmt.Sprintf("%s/release-channel:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
if mirrorCtx.SpecificVersion.Prerelease() != "" {
for _, version := range deckhouseVersions {
layouts.DeckhouseImages[fmt.Sprintf("%s:%s", mirrorCtx.DeckhouseRegistryRepo, version.Prerelease())] = struct{}{}
layouts.InstallImages[fmt.Sprintf("%s/install:%s", mirrorCtx.DeckhouseRegistryRepo, version.Prerelease())] = struct{}{}
layouts.InstallStandaloneImages[fmt.Sprintf("%s/install-standalone:%s", mirrorCtx.DeckhouseRegistryRepo, version.Prerelease())] = struct{}{}
layouts.ReleaseChannelImages[fmt.Sprintf("%s/release-channel:%s", mirrorCtx.DeckhouseRegistryRepo, version.Prerelease())] = struct{}{}
}

} else {
for _, version := range deckhouseVersions {
layouts.DeckhouseImages[fmt.Sprintf("%s:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.InstallImages[fmt.Sprintf("%s/install:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.InstallStandaloneImages[fmt.Sprintf("%s/install-standalone:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
layouts.ReleaseChannelImages[fmt.Sprintf("%s/release-channel:v%s", mirrorCtx.DeckhouseRegistryRepo, version.String())] = struct{}{}
}
}

// If we are to pull only the specific requested version, we should not pull any release channels at all.
Expand Down

0 comments on commit 3c41b83

Please sign in to comment.