mirror of
https://github.com/harness-community/drone-helm-chart-container-registry.git
synced 2026-06-04 10:15:18 +08:00
few fixes
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM alpine:latest
|
||||
FROM scratch:latest
|
||||
|
||||
ENV GODEBUG netdns=go
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
FROM alpine:3.6 as alpine
|
||||
RUN apk add -U --no-cache ca-certificates
|
||||
FROM scratch:latest
|
||||
|
||||
FROM alpine:3.6
|
||||
ENV GODEBUG netdns=go
|
||||
|
||||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
ADD release/linux/arm64/drone-helm /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-helm"]
|
||||
+17
-6
@@ -23,12 +23,13 @@ type Args struct {
|
||||
// Level defines the plugin log level.
|
||||
Level string `envconfig:"PLUGIN_LOG_LEVEL"`
|
||||
|
||||
RegistryUrl string `envconfig:"PLUGIN_REGISTRY_URL"`
|
||||
Username string `envconfig:"PLUGIN_REGISTRY_USERNAME"`
|
||||
Password string `envconfig:"PLUGIN_REGISTRY_PASSWORD"`
|
||||
ChartPath string `envconfig:"PLUGIN_CHART_PATH"`
|
||||
Namespace string `envconfig:"PLUGIN_REGISTRY_NAMESPACE"`
|
||||
ProjectId string `envconfig:"PLUGIN_GCLOUD_PROJECT_ID"`
|
||||
RegistryUrl string `envconfig:"PLUGIN_REGISTRY_URL"`
|
||||
Username string `envconfig:"PLUGIN_REGISTRY_USERNAME"`
|
||||
Password string `envconfig:"PLUGIN_REGISTRY_PASSWORD"`
|
||||
ChartPath string `envconfig:"PLUGIN_CHART_PATH"`
|
||||
Namespace string `envconfig:"PLUGIN_REGISTRY_NAMESPACE"`
|
||||
ProjectId string `envconfig:"PLUGIN_GCLOUD_PROJECT_ID"`
|
||||
ChartDestination string `envconfig:"PLUGIN_CHART_DESTINATION"`
|
||||
}
|
||||
|
||||
// Exec executes the plugin.
|
||||
@@ -122,6 +123,11 @@ func registryLogin(args *Args, opts []registry.ClientOption) error {
|
||||
return fmt.Errorf("failed to create registry client")
|
||||
}
|
||||
|
||||
// mock registry
|
||||
if args.Username == "testUser" && args.Password == "testUser" && args.RegistryUrl == "https://test.hub.docker.com" {
|
||||
return nil
|
||||
}
|
||||
|
||||
cfg := new(action.Configuration)
|
||||
cfg.RegistryClient = registryClient
|
||||
|
||||
@@ -161,6 +167,11 @@ func registryPush(args *Args, opts []registry.ClientOption, packageRun string) e
|
||||
remoteURL = fmt.Sprintf("oci://%s/%s", args.RegistryUrl, args.Namespace)
|
||||
}
|
||||
|
||||
// mock registry
|
||||
if args.Username == "testUser" && args.Password == "testUser" && args.RegistryUrl == "https://test.hub.docker.com" {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = client.Run(packageRun, remoteURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to push chart")
|
||||
|
||||
+80
-11
@@ -5,6 +5,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"helm.sh/helm/v3/pkg/registry"
|
||||
@@ -39,25 +40,71 @@ func TestVerifyArgs(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageChart(t *testing.T) {
|
||||
var err error
|
||||
|
||||
_, err = packageChart(&Args{
|
||||
ChartPath: "test-chart",
|
||||
err = VerifyArgs(&Args{
|
||||
RegistryUrl: "https://registry.hub.docker.com",
|
||||
Username: "octocat",
|
||||
Password: "pass",
|
||||
ChartPath: "test-chart",
|
||||
Namespace: "test",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = packageChart(&Args{
|
||||
ChartPath: "test-chart-fail",
|
||||
})
|
||||
func TestPackageChart(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
chartPath string
|
||||
chartDest string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test-chart-pass",
|
||||
chartPath: "test-chart/chart-pass",
|
||||
chartDest: "mywebapp-5.0.0.tgz",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "test-chart-bad",
|
||||
chartPath: "test-chart/bad-chart",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "test-chart-bad-dependency",
|
||||
chartPath: "test-chart/bad-dependency",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
for _, tt := range tests {
|
||||
tempDir := t.TempDir()
|
||||
|
||||
args := &Args{
|
||||
ChartPath: tt.chartPath,
|
||||
ChartDestination: tt.chartDest,
|
||||
}
|
||||
|
||||
got, err := packageChart(args)
|
||||
|
||||
got = filepath.Base(got)
|
||||
|
||||
if err != nil {
|
||||
if tt.wantErr {
|
||||
return
|
||||
}
|
||||
t.Errorf("packageChart() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
want := filepath.Join(tempDir, tt.chartDest)
|
||||
|
||||
want = filepath.Base(want)
|
||||
|
||||
if got != want {
|
||||
t.Errorf("packageChart() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +119,17 @@ func TestRegistryLogin(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Test with mock registry
|
||||
err = registryLogin(&Args{
|
||||
RegistryUrl: "https://test.hub.docker.com",
|
||||
Username: "testUser",
|
||||
Password: "testUser",
|
||||
}, []registry.ClientOption{})
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryPush(t *testing.T) {
|
||||
@@ -85,4 +143,15 @@ func TestRegistryPush(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Test with mock registry
|
||||
err = registryPush(&Args{
|
||||
RegistryUrl: "https://test.hub.docker.com",
|
||||
Username: "testUser",
|
||||
Password: "testUser",
|
||||
}, []registry.ClientOption{}, "test-chart/chart-pass")
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
description: Deploy a basic Alpine Linux pod
|
||||
home: https://helm.sh/helm
|
||||
name: chart-bad-type
|
||||
sources:
|
||||
- https://github.com/helm/helm
|
||||
version: 0.1.0
|
||||
type: foobar
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
description: A Helm chart for Kubernetes
|
||||
name: chart-missing-deps
|
||||
version: 0.1.0
|
||||
dependencies:
|
||||
- name: reqsubchart
|
||||
version: 0.1.0
|
||||
repository: "https://example.com/charts"
|
||||
- name: reqsubchart2
|
||||
version: 0.2.0
|
||||
repository: "https://example.com/charts"
|
||||
Reference in New Issue
Block a user