Skip to content

Commit

Permalink
[redis] Use chainguard image WEB-574 (#18067)
Browse files Browse the repository at this point in the history
* [redis] Use chainguard image

* Fix

* empty

* Fix
  • Loading branch information
easyCZ authored Jun 27, 2023
1 parent 943f630 commit 664e19c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
16 changes: 16 additions & 0 deletions install/installer/pkg/common/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/docker/distribution/reference"
"github.com/opencontainers/go-digest"
"helm.sh/helm/v3/pkg/cli/values"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -123,6 +124,21 @@ func (r *RenderContext) ImageName(repo, name, tag string) string {
return ref
}

func (r *RenderContext) ImageDigest(repo, name string, digest digest.Digest) string {
ref := fmt.Sprintf("%s@%s", r.RepoName(repo, name), digest)
pref, err := reference.ParseNamed(ref)
if err != nil {
panic(fmt.Sprintf("cannot parse image ref %s: %v", ref, err))
}

canonical, err := reference.WithDigest(pref, digest)
if err != nil {
panic(fmt.Sprintf("image ref %s has no canonical version: %v", ref, err))
}

return canonical.String()
}

// generateValues generates the random values used throughout the context
// todo(sje): find a way of persisting these values for updates
func (r *RenderContext) generateValues() error {
Expand Down
16 changes: 11 additions & 5 deletions install/installer/pkg/components/redis/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@

package redis

import "github.com/opencontainers/go-digest"

const (
Component = "redis"

PortName = "api"
Port = 6379

RegistryRepo = "registry.hub.docker.com"
RegistryImage = "library/redis"
ImageTag = "7.0.8"
RegistryRepo = "cgr.dev"
RegistryImage = "chainguard/redis"

ContainerName = "redis"

ExporterRegistryImage = "oliver006/redis_exporter"
ExporterImageTag = "v1.48.0"
ExporterRegistryImage = "chainguard/prometheus-redis-exporter"

ExporterContainerName = "exporter"
ExporterPortName = "exporter"
ExporterPort = 9500
)

var (
ImageDigest = digest.Digest("sha256:d2802dec2f97b47c7fb34eee0b4d658fd0574577271e5e426e2d949cc3d47110")
ExporterImageDigest = digest.Digest("sha256:30948f2fe1bee4bd13d33061f0abbbd1d045b69ec4e02b6213af8709ea7bb710")
)
4 changes: 2 additions & 2 deletions install/installer/pkg/components/redis/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Containers: []corev1.Container{
{
Name: ContainerName,
Image: ctx.ImageName(common.ThirdPartyContainerRepo(ctx.Config.Repository, RegistryRepo), RegistryImage, ImageTag),
Image: ctx.ImageDigest(common.ThirdPartyContainerRepo(ctx.Config.Repository, RegistryRepo), RegistryImage, ImageDigest),
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{
"redis-server",
Expand Down Expand Up @@ -103,7 +103,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
{
Name: ExporterContainerName,
Image: ctx.ImageName(common.ThirdPartyContainerRepo(ctx.Config.Repository, RegistryRepo), ExporterRegistryImage, ExporterImageTag),
Image: ctx.ImageDigest(common.ThirdPartyContainerRepo(ctx.Config.Repository, RegistryRepo), ExporterRegistryImage, ExporterImageDigest),
ImagePullPolicy: corev1.PullIfNotPresent,
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
[]v1.EnvVar{
Expand Down

0 comments on commit 664e19c

Please sign in to comment.