Skip to content

Commit

Permalink
Merge pull request #6 from hypnoglow/repo-index-rework
Browse files Browse the repository at this point in the history
Repo index rework
  • Loading branch information
hypnoglow authored Oct 14, 2017
2 parents 17623d6 + c57ee74 commit 1d33094
Show file tree
Hide file tree
Showing 2,511 changed files with 206 additions and 1,626,718 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
working_directory: /go/src/github.com/hypnoglow/helm-s3
steps:
- checkout
# - run: go get -u -v github.com/golang/dep/cmd/dep
# - run: dep ensure -v
- run: go get -u -v github.com/golang/dep/cmd/dep
- run: dep ensure -v
- run: ./.circleci/testcover.sh
- run: bash <(curl -s https://codecov.io/bash)
- run: go build -o bin/helms3 ./cmd/helms3
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Next, you may want to ensure if you have all prerequisites to build
the plugin from source:

cd ~/.helm/plugins/helm-s3
make build
make dep build

If you see no messages - build was successful. Try to run some helm commands
that involve the plugin, or jump straight into plugin development.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bin/*
tmp
releases
vendor

.env
coverage.txt
62 changes: 61 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@
[[constraint]]
name = "gopkg.in/alecthomas/kingpin.v2"
version = "2.2.5"

[[constraint]]
name = "github.com/ghodss/yaml"
version = "1.0.0"

[[constraint]]
name = "k8s.io/helm"
version = "2.6.2"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pkg := github.com/hypnoglow/helm-s3

dep:
@dep ensure -v -vendor-only

build:
@./sh/build.sh $(CURDIR) $(pkg)

Expand Down
35 changes: 11 additions & 24 deletions cmd/helms3/init.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
package main

import (
"bytes"
"context"
"fmt"
"log"
"text/template"
"time"

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/index"
)

const (
indexTemplate = `apiVersion: v1
entries: {}
generated: {{ .Date }}`
)

func runInit(uri string) {
tpl := template.New("index")
tpl, err := tpl.Parse(indexTemplate)
func runInit(uri string) error {
r, err := index.New().Reader()
if err != nil {
log.Fatalf("failed to parse index.yaml template: %s", err)
}

buf := &bytes.Buffer{}
if err := tpl.Execute(buf, map[string]interface{}{"Date": time.Now().Format(time.RFC3339Nano)}); err != nil {
log.Fatalf("failed to execute index.yaml temlate: %s", err)
return errors.WithMessage(err, "get index reader")
}

awsConfig, err := awsutil.Config()
if err != nil {
log.Fatalf("failed to get aws config: %s", err)
return errors.WithMessage(err, "get aws config")
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

if _, err := awss3.Upload(ctx, uri+"/index.yaml", buf, awsConfig); err != nil {
log.Fatalf("failed to upload chart to s3: %s", err)
if _, err := awss3.Upload(ctx, uri+"/index.yaml", r, awsConfig); err != nil {
return errors.WithMessage(err, "upload index to s3")
}

fmt.Printf("Initialized empty repository at %s\n", uri)
return nil

}
15 changes: 12 additions & 3 deletions cmd/helms3/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"
"log"
"os"
"time"

Expand All @@ -20,7 +22,9 @@ const (

func main() {
if len(os.Args) == 5 {
runProxy(os.Args[4])
if err := runProxy(os.Args[4]); err != nil {
log.Fatal(err)
}
return
}

Expand All @@ -46,11 +50,16 @@ func main() {
switch action {

case actionInit:
runInit(*initURI)
if err := runInit(*initURI); err != nil {
log.Fatal(err)
}
fmt.Printf("Initialized empty repository at %s\n", *initURI)
return

case actionPush:
runPush(*pushChartPath, *pushTargetRepository)
if err := runPush(*pushChartPath, *pushTargetRepository); err != nil {
log.Fatal(err)
}
return

}
Expand Down
10 changes: 6 additions & 4 deletions cmd/helms3/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ package main
import (
"context"
"fmt"
"log"

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
)

func runProxy(uri string) {
func runProxy(uri string) error {
awsConfig, err := awsutil.Config()
if err != nil {
log.Fatalf("failed to get aws config: %s", err)
return errors.WithMessage(err, "get aws config")
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

b, err := awss3.FetchRaw(ctx, uri, awsConfig)
if err != nil {
log.Fatalf("failed to fetch from s3: %s", err)
return errors.WithMessage(err, "fetch from s3")
}

fmt.Print(string(b))
return nil
}
Loading

0 comments on commit 1d33094

Please sign in to comment.