Skip to content

Commit

Permalink
Enable verbose mode correctly. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Jul 25, 2024
1 parent 658f8fa commit de95468
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 78 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
12 changes: 11 additions & 1 deletion .github/workflows/testing-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Testing code on push
name: Testing code - Commits not tied to PRs
on:
push:
branches-ignore:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
test-app:
Expand All @@ -15,5 +21,9 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run GolangCI-Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
- name: Test application
run: go test -v ./...
10 changes: 9 additions & 1 deletion .github/workflows/testing-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Testing code for the entire pull request
name: Testing code - Pull Request
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
test-app:
name: Test Application
Expand All @@ -15,6 +19,10 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run GolangCI-Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
- name: Test application
run: go test -v ./...
- name: Capture git tag
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
Expand Down
34 changes: 17 additions & 17 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ snapshot:
name_template: "{{ incpatch .Version }}-next"
dockers:
- image_templates:
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-amd64"
goos: linux
goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/patrickdappollonio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/patrickdappollonio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/patrickdappollonio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/konstructio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/konstructio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/konstructio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
Expand All @@ -55,16 +55,16 @@ dockers:
- scripts/install-binary.sh
- plugin.yaml
- image_templates:
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-arm64"
goos: linux
goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/patrickdappollonio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/patrickdappollonio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/patrickdappollonio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/konstructio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/konstructio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/konstructio/{{ .ProjectName }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
Expand All @@ -74,18 +74,18 @@ dockers:
- scripts/install-binary.sh
- plugin.yaml
docker_manifests:
- name_template: "ghcr.io/patrickdappollonio/{{ .ProjectName }}:v{{ .RawVersion }}"
- name_template: "ghcr.io/konstructio/{{ .ProjectName }}:v{{ .RawVersion }}"
image_templates:
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/patrickdappollonio/{{ .ProjectName }}:v{{ .Major }}"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/konstructio/{{ .ProjectName }}:v{{ .Major }}"
image_templates:
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/patrickdappollonio/{{ .ProjectName }}:latest"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/konstructio/{{ .ProjectName }}:latest"
image_templates:
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/patrickdappollonio/{{ .ProjectName }}:{{ .Tag }}-arm64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/konstructio/{{ .ProjectName }}:{{ .Tag }}-arm64"
changelog:
sort: asc
filters:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To make the process smooth for everyone, please follow these guidelines:
Fork the repository on GitHub and clone your fork locally:

```bash
git clone https://github.com/patrickdappollonio/helm-mirror.git
git clone https://github.com/konstructio/helm-mirror.git
cd helm-mirror
```

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# helm-mirror Plugin

[![Release](https://img.shields.io/github/release/patrickdappollonio/helm-mirror.svg)](https://github.com/patrickdappollonio/helm-mirror/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/patrickdappollonio/helm-mirror/total?color=blue&logo=github)](https://github.com/patrickdappollonio/helm-mirror/releases)
[![Release](https://img.shields.io/github/release/konstructio/helm-mirror.svg)](https://github.com/konstructio/helm-mirror/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/konstructio/helm-mirror/total?color=blue&logo=github)](https://github.com/konstructio/helm-mirror/releases)


A fork of the [`helm-mirror` plugin from openSUSE](https://github.com/openSUSE/helm-mirror). This plugin allows you to mirror Helm Charts from a repository into a local folder.
Expand All @@ -11,16 +11,16 @@ A fork of the [`helm-mirror` plugin from openSUSE](https://github.com/openSUSE/h
Using Helm plugin manager (> 2.3.x)

```bash
helm plugin install https://github.com/patrickdappollonio/helm-mirror --version main
helm plugin install https://github.com/konstructio/helm-mirror --version main
```

Using a Go environment:

```bash
go install github.com/patrickdappollonio/helm-mirror@latest
go install github.com/konstructio/helm-mirror@latest
```

Or download the binary from the [releases page](https://github.com/patrickdappollonio/helm-mirror/releases), unpack it, and use the `bin/mirror` binary directly.
Or download the binary from the [releases page](https://github.com/konstructio/helm-mirror/releases), unpack it, and use the `bin/mirror` binary directly.

## Usage

Expand Down
12 changes: 10 additions & 2 deletions cmd/inspectImages.go → cmd/inspect_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
"errors"
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"

"github.com/patrickdappollonio/helm-mirror/formatter"
"github.com/patrickdappollonio/helm-mirror/service"
"github.com/konstructio/helm-mirror/formatter"
"github.com/konstructio/helm-mirror/service"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -86,14 +87,18 @@ func init() {
}

func validateInspectImagesArgs(_ *cobra.Command, args []string) error {
logger := log.New(os.Stderr, prefix, flags)

if len(args) < 1 {
logger.Print("error: requires at least one arg to execute")
return errors.New("error: requires at least one arg")
}

if !path.IsAbs(args[0]) {
logger.Printf("error: please provide a full path for [folder|tgzfile]: `%s`", args[0])
return errors.New("error: please provide a full path for [folder|tgzfile]")
}

return nil
}

Expand Down Expand Up @@ -130,6 +135,8 @@ func resolveFormatter(output string, logger *log.Logger) (formatter.Formatter, e
}

func runInspectImages(_ *cobra.Command, args []string) error {
logger := log.New(os.Stderr, prefix, flags)

target = args[0]
formatter, err := resolveFormatter(output, logger)
if err != nil {
Expand All @@ -140,5 +147,6 @@ func runInspectImages(_ *cobra.Command, args []string) error {
if err := imagesService.Images(); err != nil {
return fmt.Errorf("cannot extract images: %w", err)
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/inspectImages_test.go → cmd/inspect_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"reflect"
"testing"

"github.com/patrickdappollonio/helm-mirror/formatter"
"github.com/konstructio/helm-mirror/formatter"
"github.com/spf13/cobra"
)

Expand Down
21 changes: 11 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path"
"strings"

"github.com/patrickdappollonio/helm-mirror/service"
"github.com/konstructio/helm-mirror/service"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/repo"
)
Expand All @@ -40,9 +40,8 @@ var (
chartName string
chartVersion string
folder string
flags = log.Ldate | log.Lmicroseconds | log.Lshortfile
flags = log.Ldate | log.Lmicroseconds
prefix = "helm-mirror: "
logger *log.Logger
username string
password string
caFile string
Expand Down Expand Up @@ -109,7 +108,6 @@ func Execute() {
}

func init() {
logger = log.New(os.Stdout, prefix, flags)
rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&IgnoreErrors, "ignore-errors", "i", false, "ignores errors while downloading or processing charts")
rootCmd.PersistentFlags().BoolVarP(&AllVersions, "all-versions", "a", false, "gets all the versions of the charts in the chart repository")
Expand All @@ -129,35 +127,36 @@ func validateRootArgs(_ *cobra.Command, args []string) error {
if len(args) == 1 && args[0] == "help" {
return nil
}
logger.Printf("error: requires at least two args to execute")
return errors.New("error: requires at least two args to execute")
}

url, err := url.Parse(args[0])
if err != nil {
logger.Printf("error: not a valid URL for index file: %s", err)
return fmt.Errorf("error: %q is not a valid URL for index file: %w", args[0], err)
}

if !strings.Contains(url.Scheme, "http") {
logger.Printf("error: not a valid URL protocol: `%s`", url.Scheme)
return errors.New("error: not a valid URL protocol")
}

if !path.IsAbs(args[1]) {
logger.Printf("error: please provide a full path for destination folder: `%s`", args[1])
return errors.New("error: please provide a full path for destination folder")
}

return nil
}

func runRoot(_ *cobra.Command, args []string) error {
logger := log.New(os.Stderr, prefix, flags)

repoURL, err := url.Parse(args[0])
if err != nil {
logger.Printf("error: not a valid URL for index file: %s", err)
return fmt.Errorf("error: %q is not a valid URL for index file: %w", args[0], err)
}

folder = args[1]
err = os.MkdirAll(folder, 0o744)
if err != nil {
if err := os.MkdirAll(folder, 0o744); err != nil {
logger.Printf("error: cannot create destination folder: %s", err)
return fmt.Errorf("cannot create destination folder %q: %w", folder, err)
}
Expand Down Expand Up @@ -190,9 +189,11 @@ func runRoot(_ *cobra.Command, args []string) error {
CertFile: certFile,
KeyFile: keyFile,
}

getService := service.NewGetService(config, AllVersions, Verbose, IgnoreErrors, logger, rootURL.String(), chartName, chartVersion)
if err := getService.Get(); err != nil {
return fmt.Errorf("cannot download index and charts to the specified directory: %w", err)
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/patrickdappollonio/helm-mirror/fixtures"
"github.com/konstructio/helm-mirror/fixtures"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion formatter/skopeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"strings"

"github.com/containers/image/types"
"github.com/containers/image/v5/types"
"github.com/distribution/reference"
yamlencoder "gopkg.in/yaml.v3"
)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/patrickdappollonio/helm-mirror
module github.com/konstructio/helm-mirror

go 1.22.0

require (
github.com/containers/image v3.0.2+incompatible
github.com/containers/image/v5 v5.31.1
github.com/distribution/reference v0.6.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.1
Expand All @@ -16,6 +16,7 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/containers/storage v1.54.0 // indirect
github.com/cyphar/filepath-securejoin v0.3.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/containers/image v3.0.2+incompatible h1:B1lqAE8MUPCrsBLE86J0gnXleeRq8zJnQryhiiGQNyE=
github.com/containers/image v3.0.2+incompatible/go.mod h1:8Vtij257IWSanUQKe1tAeNOm2sRVkSqQTVQ1IlwI3+M=
github.com/containers/image/v5 v5.31.1 h1:3x9soI6Biml/GiDLpkSmKrkRSwVGctxu/vONpoUdklA=
github.com/containers/image/v5 v5.31.1/go.mod h1:5QfOqSackPkSbF7Qxc1DnVNnPJKQ+KWLkfEfDpK590Q=
github.com/containers/storage v1.54.0 h1:xwYAlf6n9OnIlURQLLg3FYHbO74fQ/2W2N6EtQEUM4I=
github.com/containers/storage v1.54.0/go.mod h1:PlMOoinRrBSnhYODLxt4EXl0nmJt+X0kjG0Xdt9fMTw=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE=
github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
Expand Down Expand Up @@ -41,8 +43,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
Expand Down
Loading

0 comments on commit de95468

Please sign in to comment.