From adebe21cb8a8c0e7612dc50aba76e5f21fede456 Mon Sep 17 00:00:00 2001 From: "dmitry.denisenko" Date: Thu, 5 Sep 2024 16:13:00 +0300 Subject: [PATCH] add standalone image Signed-off-by: Denisenko Dmitry <54986280+d2285@users.noreply.github.com> --- internal/mirror/cmd/pull/pull.go | 4 ++++ pkg/libmirror/layouts/layouts.go | 24 ++++++++++++++++++------ pkg/libmirror/layouts/pull.go | 15 +++++++++++++++ pkg/libmirror/layouts/tag_resolver.go | 1 + pkg/libmirror/operations/push.go | 19 +++++++++++++------ testing/e2e/mirror/mirror_e2e_test.go | 6 ++++++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/internal/mirror/cmd/pull/pull.go b/internal/mirror/cmd/pull/pull.go index 541f65d..0dec3bb 100644 --- a/internal/mirror/cmd/pull/pull.go +++ b/internal/mirror/cmd/pull/pull.go @@ -328,6 +328,10 @@ func PullDeckhouseToLocalFS( return fmt.Errorf("pull installers: %w", err) } + if err = layouts.PullStandaloneInstallers(pullCtx, imageLayouts); err != nil { + return fmt.Errorf("pull standalone installers: %w", err) + } + logger.InfoF("Searching for Deckhouse built-in modules digests") for imageTag := range imageLayouts.InstallImages { digests, err := images.ExtractImageDigestsFromDeckhouseInstaller(pullCtx, imageTag, imageLayouts.Install) diff --git a/pkg/libmirror/layouts/layouts.go b/pkg/libmirror/layouts/layouts.go index aee6b74..892d410 100644 --- a/pkg/libmirror/layouts/layouts.go +++ b/pkg/libmirror/layouts/layouts.go @@ -46,6 +46,9 @@ type ImageLayouts struct { Install layout.Path InstallImages map[string]struct{} + InstallStandalone layout.Path + InstallStandaloneImages map[string]struct{} + ReleaseChannel layout.Path ReleaseChannelImages map[string]struct{} @@ -80,12 +83,13 @@ func CreateOCIImageLayoutsForDeckhouse( } fsPaths := map[*layout.Path]string{ - &layouts.Deckhouse: rootFolder, - &layouts.Install: filepath.Join(rootFolder, "install"), - &layouts.ReleaseChannel: filepath.Join(rootFolder, "release-channel"), - &layouts.TrivyDB: filepath.Join(rootFolder, "security", "trivy-db"), - &layouts.TrivyBDU: filepath.Join(rootFolder, "security", "trivy-bdu"), - &layouts.TrivyJavaDB: filepath.Join(rootFolder, "security", "trivy-java-db"), + &layouts.Deckhouse: rootFolder, + &layouts.Install: filepath.Join(rootFolder, "install"), + &layouts.InstallStandalone: filepath.Join(rootFolder, "install-standalone"), + &layouts.ReleaseChannel: filepath.Join(rootFolder, "release-channel"), + &layouts.TrivyDB: filepath.Join(rootFolder, "security", "trivy-db"), + &layouts.TrivyBDU: filepath.Join(rootFolder, "security", "trivy-bdu"), + &layouts.TrivyJavaDB: filepath.Join(rootFolder, "security", "trivy-java-db"), } for layoutPtr, fsPath := range fsPaths { *layoutPtr, err = CreateEmptyImageLayoutAtPath(fsPath) @@ -173,6 +177,7 @@ func FillLayoutsWithBasicDeckhouseImages( ) { layouts.DeckhouseImages = map[string]struct{}{} layouts.InstallImages = map[string]struct{}{} + layouts.InstallStandaloneImages = map[string]struct{}{} layouts.ReleaseChannelImages = map[string]struct{}{} layouts.TrivyDBImages = map[string]struct{}{ mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-db:2": {}, @@ -183,6 +188,7 @@ func FillLayoutsWithBasicDeckhouseImages( 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{}{} } @@ -203,6 +209,12 @@ func FillLayoutsWithBasicDeckhouseImages( layouts.InstallImages[mirrorCtx.DeckhouseRegistryRepo+"/install:stable"] = struct{}{} layouts.InstallImages[mirrorCtx.DeckhouseRegistryRepo+"/install:rock-solid"] = struct{}{} + layouts.InstallStandaloneImages[mirrorCtx.DeckhouseRegistryRepo+"/install-standalone:alpha"] = struct{}{} + layouts.InstallStandaloneImages[mirrorCtx.DeckhouseRegistryRepo+"/install-standalone:beta"] = struct{}{} + layouts.InstallStandaloneImages[mirrorCtx.DeckhouseRegistryRepo+"/install-standalone:early-access"] = struct{}{} + layouts.InstallStandaloneImages[mirrorCtx.DeckhouseRegistryRepo+"/install-standalone:stable"] = struct{}{} + layouts.InstallStandaloneImages[mirrorCtx.DeckhouseRegistryRepo+"/install-standalone:rock-solid"] = struct{}{} + layouts.ReleaseChannelImages[mirrorCtx.DeckhouseRegistryRepo+"/release-channel:alpha"] = struct{}{} layouts.ReleaseChannelImages[mirrorCtx.DeckhouseRegistryRepo+"/release-channel:beta"] = struct{}{} layouts.ReleaseChannelImages[mirrorCtx.DeckhouseRegistryRepo+"/release-channel:early-access"] = struct{}{} diff --git a/pkg/libmirror/layouts/pull.go b/pkg/libmirror/layouts/pull.go index 84e171e..8515cb5 100644 --- a/pkg/libmirror/layouts/pull.go +++ b/pkg/libmirror/layouts/pull.go @@ -48,6 +48,21 @@ func PullInstallers(mirrorCtx *contexts.PullContext, layouts *ImageLayouts) erro return nil } +func PullStandaloneInstallers(mirrorCtx *contexts.PullContext, layouts *ImageLayouts) error { + mirrorCtx.Logger.InfoLn("Beginning to pull standalone installers") + if err := PullImageSet( + mirrorCtx, + layouts.InstallStandalone, + layouts.InstallStandaloneImages, + WithTagToDigestMapper(layouts.TagsResolver.GetTagDigest), + WithAllowMissingTags(true), + ); err != nil { + return err + } + mirrorCtx.Logger.InfoLn("✅ All required standalone installers are pulled!") + return nil +} + func PullDeckhouseReleaseChannels(mirrorCtx *contexts.PullContext, layouts *ImageLayouts) error { mirrorCtx.Logger.InfoLn("Beginning to pull Deckhouse release channels information") if err := PullImageSet( diff --git a/pkg/libmirror/layouts/tag_resolver.go b/pkg/libmirror/layouts/tag_resolver.go index 49782b0..7461487 100644 --- a/pkg/libmirror/layouts/tag_resolver.go +++ b/pkg/libmirror/layouts/tag_resolver.go @@ -48,6 +48,7 @@ func (r *TagsResolver) ResolveTagsDigestsForImageLayouts(mirrorCtx *contexts.Bas layouts.DeckhouseImages, layouts.ReleaseChannelImages, layouts.InstallImages, + layouts.InstallStandaloneImages, } for _, moduleImageLayout := range layouts.Modules { diff --git a/pkg/libmirror/operations/push.go b/pkg/libmirror/operations/push.go index d7a0e90..38b4912 100644 --- a/pkg/libmirror/operations/push.go +++ b/pkg/libmirror/operations/push.go @@ -137,6 +137,7 @@ func pushModulesTags(mirrorCtx *contexts.BaseContext, modulesList []string) erro func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path, []string, error) { deckhouseIndexRef := mirrorCtx.RegistryHost + mirrorCtx.RegistryPath installersIndexRef := path.Join(deckhouseIndexRef, "install") + installersStandaloneIndexRef := path.Join(deckhouseIndexRef, "install-standalone") releasesIndexRef := path.Join(deckhouseIndexRef, "release-channel") trivyDBIndexRef := path.Join(deckhouseIndexRef, "security", "trivy-db") trivyBDUIndexRef := path.Join(deckhouseIndexRef, "security", "trivy-bdu") @@ -144,6 +145,7 @@ func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path, deckhouseLayoutPath := mirrorCtx.UnpackedImagesPath installersLayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "install") + installersStandaloneLayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "install-standalone") releasesLayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "release-channel") trivyDBLayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "security", "trivy-db") trivyBDULayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "security", "trivy-bdu") @@ -157,6 +159,10 @@ func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path, if err != nil { return nil, nil, err } + installersStandaloneLayout, err := layout.FromPath(installersStandaloneLayoutPath) + if err != nil { + return nil, nil, err + } releasesLayout, err := layout.FromPath(releasesLayoutPath) if err != nil { return nil, nil, err @@ -176,12 +182,13 @@ func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path, modulesPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "modules") ociLayouts := map[string]layout.Path{ - deckhouseIndexRef: deckhouseLayout, - installersIndexRef: installersLayout, - releasesIndexRef: releasesLayout, - trivyDBIndexRef: trivyDBLayout, - trivyBDUIndexRef: trivyBDULayout, - trivyJavaDBIndexRef: trivyJavaDBLayout, + deckhouseIndexRef: deckhouseLayout, + installersIndexRef: installersLayout, + installersStandaloneIndexRef: installersStandaloneLayout, + releasesIndexRef: releasesLayout, + trivyDBIndexRef: trivyDBLayout, + trivyBDUIndexRef: trivyBDULayout, + trivyJavaDBIndexRef: trivyJavaDBLayout, } modulesNames := make([]string, 0) diff --git a/testing/e2e/mirror/mirror_e2e_test.go b/testing/e2e/mirror/mirror_e2e_test.go index fc1f818..70cfbe4 100644 --- a/testing/e2e/mirror/mirror_e2e_test.go +++ b/testing/e2e/mirror/mirror_e2e_test.go @@ -189,6 +189,12 @@ func createDeckhouseControllersAndInstallersInRegistry(t *testing.T, repo string err = remote.Write(ref, installer, remoteOpts...) require.NoError(t, err) + + ref, err = name.ParseReference(repo+"/install-standalone:"+shortTag, nameOpts...) + require.NoError(t, err) + + err = remote.Write(ref, installer, remoteOpts...) + require.NoError(t, err) } }