Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Tuan Anh Tran <[email protected]>
  • Loading branch information
tuananh committed Nov 25, 2023
1 parent f432b5d commit a426af1
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 16 deletions.
18 changes: 11 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/mutate"
v1tar "github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/tuananh/helm-oci-proxy/pkg/serve"
"helm.sh/helm/v3/pkg/registry"
)

func main() {
Expand Down Expand Up @@ -165,7 +166,11 @@ func (s *server) build(ctx context.Context, chartName string, chartVersion strin

path := path.Join(wd, "argo-cd-5.51.4.tgz")
slog.InfoContext(ctx, "path", "path", path)
v1Layer, err := v1tar.LayerFromFile(path)

// use helm content layer type
v1Layer, err := v1tar.LayerFromFile(path,
v1tar.WithMediaType(registry.ChartLayerMediaType),
)
if err != nil {
return nil, fmt.Errorf("failed to create OCI layer from tar.gz: %w", err)
}
Expand All @@ -179,22 +184,22 @@ func (s *server) build(ctx context.Context, chartName string, chartVersion strin
CreatedBy: "github.com/tuananh/oci-helm-proxy",
Created: v1.Time{Time: time.Time{}},
},
MediaType: serve.HelmChartContentLayer,
MediaType: registry.ChartLayerMediaType,
})

v1Image, err := mutate.Append(empty.Image, adds...)
if err != nil {
return empty.Image, fmt.Errorf("unable to append OCI layer to empty image: %w", err)
}

// change mediatype to helm config type
v1Image = mutate.MediaType(v1Image, serve.CNCFHelmConfig)
// empty.Image use docker mediatype => change mediatype to helm config type
v1Image = mutate.MediaType(v1Image, registry.ConfigMediaType)

// add annotations
v1Image = mutate.Annotations(v1Image, map[string]string{
"org.opencontainers.image.description": "fooooo",
"org.opencontainers.image.url": "https://github.com/aws/karpenter/",
"org.opencontainers.image.version": "5.51.4",
// "org.opencontainers.image.url": "https://github.com/aws/karpenter/",
"org.opencontainers.image.version": "5.51.4",
}).(v1.Image)

cfg, err := v1Image.ConfigFile()
Expand All @@ -217,7 +222,6 @@ func (s *server) build(ctx context.Context, chartName string, chartVersion strin
}

func cacheKey(keys []string) string {
slog.InfoContext(context.TODO(), "cacheKey", "key", strings.Join(keys, ","))
ck := []byte(strings.Join(keys, ","))
return fmt.Sprintf("helm-oci-proxy-%x", md5.Sum(ck))
}
32 changes: 30 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,58 @@ require (
github.com/google/go-containerregistry v0.16.1
golang.org/x/sync v0.5.0
google.golang.org/api v0.151.0
helm.sh/helm/v3 v3.13.2
)

require (
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/cli v24.0.7+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
Expand All @@ -48,5 +73,8 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gotest.tools/v3 v3.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/client-go v0.28.2 // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit a426af1

Please sign in to comment.