-
Notifications
You must be signed in to change notification settings - Fork 710
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 #7 from ngtuna/cobra
refactor: add cobra
- Loading branch information
Showing
13 changed files
with
233 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,10 @@ | ||
FROM quay.io/deis/go-dev:v1.6.0 as builder | ||
COPY . /go/src/github.com/kubeapps/chartsvc/cmd/chart-repo | ||
WORKDIR /go/src/github.com/kubeapps/chartsvc/cmd/chart-repo | ||
RUN dep ensure | ||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo | ||
|
||
FROM scratch | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /go/src/github.com/kubeapps/chartsvc/cmd/chart-repo/chart-repo /chart-repo | ||
CMD ["/chart-repo"] |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright (c) 2017-2018 Bitnami | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "chart-repo", | ||
Short: "Kubeapps Chart Repository utility", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
func main() { | ||
cmd := RootCmd | ||
if err := cmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cmds := []*cobra.Command{syncCmd, deleteCmd} | ||
|
||
for _, cmd := range cmds { | ||
RootCmd.AddCommand(cmd) | ||
cmd.Flags().String("mongo-url", "localhost", "MongoDB URL (see https://godoc.org/labix.org/v2/mgo#Dial for format)") | ||
cmd.Flags().String("mongo-database", "charts", "MongoDB database") | ||
cmd.Flags().String("mongo-user", "", "MongoDB user") | ||
cmd.Flags().Bool("debug", false, "verbose logging") | ||
} | ||
} |
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,30 @@ | ||
/* | ||
Copyright (c) 2017-2018 Bitnami | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete [REPO NAME]", | ||
Short: "delete a chart repository", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
return | ||
}, | ||
} |
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,69 @@ | ||
/* | ||
Copyright (c) 2017-2018 Bitnami | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/sirupsen/logrus" | ||
"github.com/kubeapps/common/datastore" | ||
) | ||
|
||
var syncCmd = &cobra.Command{ | ||
Use: "sync [REPO NAME] [REPO URL]", | ||
Short: "add a new chart repository, and resync its charts periodically", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
logrus.Info("Need exactly two arguments: [REPO NAME] [REPO URL]") | ||
cmd.Help() | ||
return | ||
} | ||
|
||
mongoURL, err := cmd.Flags().GetString("mongo-url") | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
mongoDB, err := cmd.Flags().GetString("mongo-database") | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
mongoUser, err := cmd.Flags().GetString("mongo-user") | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
mongoPW := os.Getenv("MONGO_PASSWORD") | ||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
if debug { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
mongoConfig := datastore.Config{URL: mongoURL, Database: mongoDB, Username: mongoUser, Password: mongoPW} | ||
dbSession, err := datastore.NewSession(mongoConfig) | ||
if err != nil { | ||
logrus.Fatalf("Can't connect to mongoDB: %v", err) | ||
} | ||
|
||
if err = syncRepo(dbSession, args[0], args[1]); err != nil { | ||
logrus.Fatalf("Can't add chart repository to database: %v", err) | ||
} | ||
|
||
logrus.Infof("Successfully added the chart repository %s to database", args[0]) | ||
}, | ||
} |
File renamed without changes.
File renamed without changes.
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.