forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: When dumping trim the standard suffices instead of a random suffix (go-gitea#19440) Add uploadpack.allowAnySHA1InWant to allow --filter=blob:none with older git clients (go-gitea#19430) Don't allow merging PR's which are being conflict checked (go-gitea#19357) doc: add brief intro on using traefik as reverse-proxy (go-gitea#19432) Fix panic in team repos API (go-gitea#19431) When updating mirror repo intervals by API reschedule next update too (go-gitea#19429) Fix nil error when some pages are rendered outside request context (go-gitea#19427) Add Helm Chart registry (go-gitea#19406)
- Loading branch information
Showing
36 changed files
with
787 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
date: "2022-04-14T00:00:00+00:00" | ||
title: "Helm Chart Registry" | ||
slug: "packages/helm" | ||
draft: false | ||
toc: false | ||
menu: | ||
sidebar: | ||
parent: "packages" | ||
name: "Helm" | ||
weight: 50 | ||
identifier: "helm" | ||
--- | ||
|
||
# Helm Chart Registry | ||
|
||
Publish [Helm](https://helm.sh/) charts for your user or organization. | ||
|
||
**Table of Contents** | ||
|
||
{{< toc >}} | ||
|
||
## Requirements | ||
|
||
To work with the Helm Chart registry use a simple HTTP client like `curl` or the [`helm cm-push`](https://github.com/chartmuseum/helm-push/) plugin. | ||
|
||
## Publish a package | ||
|
||
Publish a package by running the following command: | ||
|
||
```shell | ||
curl --user {username}:{password} -X POST --upload-file ./{chart_file}.tgz https://gitea.example.com/api/packages/{owner}/helm/api/charts | ||
``` | ||
|
||
or with the `helm cm-push` plugin: | ||
|
||
```shell | ||
helm repo add --username {username} --password {password} {repo} https://gitea.example.com/api/packages/{owner}/helm | ||
helm cm-push ./{chart_file}.tgz {repo} | ||
``` | ||
|
||
| Parameter | Description | | ||
| ------------ | ----------- | | ||
| `username` | Your Gitea username. | | ||
| `password` | Your Gitea password or a personal access token. | | ||
| `repo` | The name for the repository. | | ||
| `chart_file` | The Helm Chart archive. | | ||
| `owner` | The owner of the package. | | ||
|
||
## Install a package | ||
|
||
To install a Helm char from the registry, execute the following command: | ||
|
||
```shell | ||
helm repo add --username {username} --password {password} {repo} https://gitea.example.com/api/packages/{owner}/helm | ||
helm repo update | ||
helm install {name} {repo}/{chart} | ||
``` | ||
|
||
| Parameter | Description | | ||
| ---------- | ----------- | | ||
| `username` | Your Gitea username. | | ||
| `password` | Your Gitea password or a personal access token. | | ||
| `repo` | The name for the repository. | | ||
| `owner` | The owner of the package. | | ||
| `name` | The local name. | | ||
| `chart` | The name Helm Chart. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ menu: | |
sidebar: | ||
parent: "packages" | ||
name: "Maven" | ||
weight: 50 | ||
weight: 60 | ||
identifier: "maven" | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ menu: | |
sidebar: | ||
parent: "packages" | ||
name: "npm" | ||
weight: 60 | ||
weight: 70 | ||
identifier: "npm" | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ menu: | |
sidebar: | ||
parent: "packages" | ||
name: "NuGet" | ||
weight: 70 | ||
weight: 80 | ||
identifier: "nuget" | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ menu: | |
sidebar: | ||
parent: "packages" | ||
name: "PyPI" | ||
weight: 80 | ||
weight: 90 | ||
identifier: "pypi" | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ menu: | |
sidebar: | ||
parent: "packages" | ||
name: "RubyGems" | ||
weight: 90 | ||
weight: 100 | ||
identifier: "rubygems" | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"compress/gzip" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/models/packages" | ||
"code.gitea.io/gitea/models/unittest" | ||
user_model "code.gitea.io/gitea/models/user" | ||
helm_module "code.gitea.io/gitea/modules/packages/helm" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestPackageHelm(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) | ||
|
||
packageName := "test-chart" | ||
packageVersion := "1.0.3" | ||
packageAuthor := "KN4CK3R" | ||
packageDescription := "Gitea Test Package" | ||
|
||
filename := fmt.Sprintf("%s-%s.tgz", packageName, packageVersion) | ||
|
||
chartContent := `apiVersion: v2 | ||
description: ` + packageDescription + ` | ||
name: ` + packageName + ` | ||
type: application | ||
version: ` + packageVersion + ` | ||
maintainers: | ||
- name: ` + packageAuthor + ` | ||
dependencies: | ||
- name: dep1 | ||
repository: https://example.com/ | ||
version: 1.0.0` | ||
|
||
var buf bytes.Buffer | ||
zw := gzip.NewWriter(&buf) | ||
archive := tar.NewWriter(zw) | ||
archive.WriteHeader(&tar.Header{ | ||
Name: fmt.Sprintf("%s/Chart.yaml", packageName), | ||
Mode: 0o600, | ||
Size: int64(len(chartContent)), | ||
}) | ||
archive.Write([]byte(chartContent)) | ||
archive.Close() | ||
zw.Close() | ||
content := buf.Bytes() | ||
|
||
url := fmt.Sprintf("/api/packages/%s/helm", user.Name) | ||
|
||
t.Run("Upload", func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
||
uploadURL := url + "/api/charts" | ||
|
||
req := NewRequestWithBody(t, "POST", uploadURL, bytes.NewReader(content)) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
MakeRequest(t, req, http.StatusCreated) | ||
|
||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeHelm) | ||
assert.NoError(t, err) | ||
assert.Len(t, pvs, 1) | ||
|
||
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0]) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, pd.SemVer) | ||
assert.IsType(t, &helm_module.Metadata{}, pd.Metadata) | ||
assert.Equal(t, packageName, pd.Package.Name) | ||
assert.Equal(t, packageVersion, pd.Version.Version) | ||
|
||
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID) | ||
assert.NoError(t, err) | ||
assert.Len(t, pfs, 1) | ||
assert.Equal(t, filename, pfs[0].Name) | ||
assert.True(t, pfs[0].IsLead) | ||
|
||
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(len(content)), pb.Size) | ||
|
||
req = NewRequestWithBody(t, "POST", uploadURL, bytes.NewReader(content)) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
MakeRequest(t, req, http.StatusCreated) | ||
}) | ||
|
||
t.Run("Download", func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
||
checkDownloadCount := func(count int64) { | ||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeHelm) | ||
assert.NoError(t, err) | ||
assert.Len(t, pvs, 1) | ||
assert.Equal(t, count, pvs[0].DownloadCount) | ||
} | ||
|
||
checkDownloadCount(0) | ||
|
||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", url, filename)) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
|
||
assert.Equal(t, content, resp.Body.Bytes()) | ||
|
||
checkDownloadCount(1) | ||
}) | ||
|
||
t.Run("Index", func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
||
req := NewRequest(t, "GET", fmt.Sprintf("%s/index.yaml", url)) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
|
||
type ChartVersion struct { | ||
helm_module.Metadata `yaml:",inline"` | ||
URLs []string `yaml:"urls"` | ||
Created time.Time `yaml:"created,omitempty"` | ||
Removed bool `yaml:"removed,omitempty"` | ||
Digest string `yaml:"digest,omitempty"` | ||
} | ||
|
||
type ServerInfo struct { | ||
ContextPath string `yaml:"contextPath,omitempty"` | ||
} | ||
|
||
type Index struct { | ||
APIVersion string `yaml:"apiVersion"` | ||
Entries map[string][]*ChartVersion `yaml:"entries"` | ||
Generated time.Time `yaml:"generated,omitempty"` | ||
ServerInfo *ServerInfo `yaml:"serverInfo,omitempty"` | ||
} | ||
|
||
var result Index | ||
assert.NoError(t, yaml.NewDecoder(resp.Body).Decode(&result)) | ||
assert.NotEmpty(t, result.Entries) | ||
assert.Contains(t, result.Entries, packageName) | ||
|
||
cvs := result.Entries[packageName] | ||
assert.Len(t, cvs, 1) | ||
|
||
cv := cvs[0] | ||
assert.Equal(t, packageName, cv.Name) | ||
assert.Equal(t, packageVersion, cv.Version) | ||
assert.Equal(t, packageDescription, cv.Description) | ||
assert.Len(t, cv.Maintainers, 1) | ||
assert.Equal(t, packageAuthor, cv.Maintainers[0].Name) | ||
assert.Len(t, cv.Dependencies, 1) | ||
assert.ElementsMatch(t, []string{fmt.Sprintf("%s%s/%s", setting.AppURL, url[1:], filename)}, cv.URLs) | ||
|
||
assert.Equal(t, url, result.ServerInfo.ContextPath) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.