-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hypnoglow/develop
helm s3 command unleashed
- Loading branch information
Showing
150 changed files
with
21,337 additions
and
1,946 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,21 @@ | ||
# Contributing to helm s3 plugin | ||
|
||
## Development | ||
|
||
On regular plugin installation, helm triggers post-install hook | ||
that downloads prebuilt versioned release of the plugin binary and installs it. | ||
To disable this behavior, you need to pass `HELM_S3_PLUGIN_NO_INSTALL_HOOK=true` | ||
to the installer: | ||
|
||
$ HELM_S3_PLUGIN_NO_INSTALL_HOOK=true helm plugin install https://github.com/hypnoglow/helm-s3.git | ||
Development mode: not downloading versioned release. | ||
Installed plugin: s3 | ||
|
||
Next, you may want to ensure if you have all prerequisites to build | ||
the plugin from source: | ||
|
||
cd ~/.helm/plugins/helm-s3 | ||
make 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. |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# TODO | ||
|
||
- [x] ~~The code is currently super dirty, need to refactor heavily.~~ | ||
- [ ] Get rid of Golang dependency. Plugin "install" hook should download | ||
prebuilt **helms3** binary file from github releases. | ||
- [ ] Make `helm s3` command able to upload the charts to the repo. Remember | ||
- [x] ~~Get rid of Golang dependency. Plugin "install" hook should download | ||
prebuilt **helms3** binary file from github releases.~~ | ||
- [x] ~~Make `helm s3` command able to upload the charts to the repo. Remember | ||
that helm has no build-in command like `push` or `publish`, so we need to provide | ||
easy way to push charts to the repository. | ||
easy way to push charts to the repository.~~ | ||
- [ ] On `helm s3 push` need to check that the file is a valid 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
bin/* | ||
tmp | ||
releases | ||
|
||
.env | ||
coverage.txt |
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,14 @@ | ||
builds: | ||
- main: ./cmd/helms3 | ||
binary: ./bin/helms3 | ||
goos: | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 | ||
|
||
archive: | ||
format: tar.gz | ||
files: | ||
- LICENSE | ||
- plugin.yaml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
pkg := github.com/hypnoglow/helm-s3 | ||
|
||
build: | ||
@./sh/build.sh $(CURDIR) $(pkg) | ||
@./sh/build.sh $(CURDIR) $(pkg) | ||
|
||
install: | ||
@./sh/install.sh |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"log" | ||
"text/template" | ||
"time" | ||
|
||
"github.com/hypnoglow/helm-s3/pkg/awss3" | ||
"github.com/hypnoglow/helm-s3/pkg/awsutil" | ||
) | ||
|
||
const ( | ||
indexTemplate = `apiVersion: v1 | ||
entries: {} | ||
generated: {{ .Date }}` | ||
) | ||
|
||
func runInit(uri string) { | ||
tpl := template.New("index") | ||
tpl, err := tpl.Parse(indexTemplate) | ||
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) | ||
} | ||
|
||
awsConfig, err := awsutil.Config() | ||
if err != nil { | ||
log.Fatalf("failed to get aws config: %s", err) | ||
} | ||
|
||
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) | ||
} | ||
|
||
fmt.Printf("Initialized empty repository at %s\n", uri) | ||
} |
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 |
---|---|---|
@@ -1,56 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
"github.com/hypnoglow/helm-s3/pkg/awss3" | ||
"github.com/hypnoglow/helm-s3/pkg/dotaws" | ||
var ( | ||
version = "master" | ||
) | ||
|
||
const ( | ||
envAwsAccessKeyID = "AWS_ACCESS_KEY_ID" | ||
envAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY" | ||
envAWsDefaultRegion = "AWS_DEFAULT_REGION" | ||
actionPush = "push" | ||
actionInit = "init" | ||
|
||
defaultTimeout = time.Second * 5 | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 5 { | ||
fmt.Print("The direct use of \"helm s3\" command is currently not supported.") | ||
if len(os.Args) == 5 { | ||
runProxy(os.Args[4]) | ||
return | ||
} | ||
|
||
if err := dotaws.ParseCredentials(); err != nil { | ||
log.Fatalf("failed to parse aws credentials file: %s", err) | ||
} | ||
if err := dotaws.ParseConfig(); err != nil { | ||
log.Fatalf("failed to parse aws config file: %s", err) | ||
cli := kingpin.New("helm s3", "") | ||
cli.Version(version) | ||
initCmd := cli.Command(actionInit, "Initialize empty repository on AWS S3.") | ||
initURI := initCmd.Arg("uri", "URI of repository, e.g. s3://awesome-bucket/charts"). | ||
Required(). | ||
String() | ||
pushCmd := cli.Command(actionPush, "Push chart to repository.") | ||
pushChartPath := pushCmd.Arg("chartPath", "Path to a chart, e.g. ./epicservice-0.5.1.tgz"). | ||
Required(). | ||
String() | ||
pushTargetRepository := pushCmd.Arg("repo", "Target repository to runPush"). | ||
Required(). | ||
String() | ||
action := kingpin.MustParse(cli.Parse(os.Args[1:])) | ||
if action == "" { | ||
cli.Usage(os.Args[1:]) | ||
os.Exit(0) | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) | ||
defer cancel() | ||
uri := os.Args[4] | ||
awsConfig := &aws.Config{ | ||
Credentials: credentials.NewStaticCredentials( | ||
os.Getenv(envAwsAccessKeyID), | ||
os.Getenv(envAwsSecretAccessKey), | ||
"", | ||
), | ||
Region: aws.String(os.Getenv(envAWsDefaultRegion)), | ||
} | ||
switch action { | ||
|
||
b, err := awss3.FetchRaw(ctx, uri, awsConfig) | ||
if err != nil { | ||
log.Fatalf("failed to fetch from s3: %s", err) | ||
} | ||
case actionInit: | ||
runInit(*initURI) | ||
return | ||
|
||
case actionPush: | ||
runPush(*pushChartPath, *pushTargetRepository) | ||
return | ||
|
||
fmt.Print(string(b)) | ||
} | ||
} |
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,27 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hypnoglow/helm-s3/pkg/awss3" | ||
"github.com/hypnoglow/helm-s3/pkg/awsutil" | ||
) | ||
|
||
func runProxy(uri string) { | ||
awsConfig, err := awsutil.Config() | ||
if err != nil { | ||
log.Fatalf("failed to get aws config: %s", err) | ||
} | ||
|
||
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) | ||
} | ||
|
||
fmt.Print(string(b)) | ||
} |
Oops, something went wrong.