Skip to content

Commit

Permalink
Replace github client with git client for nuclio templates (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
levrado committed Jan 2, 2019
1 parent f50a705 commit 3d5aa1f
Show file tree
Hide file tree
Showing 594 changed files with 102,333 additions and 344 deletions.
33 changes: 14 additions & 19 deletions cmd/dashboard/app/dashboard.go
Expand Up @@ -44,11 +44,9 @@ func Run(listenAddress string,
defaultNamespace string,
offline bool,
platformConfigurationPath string,
templatesGithubOwner string,
templatesGithubRepository string,
templatesGithubBranch string,
templatesGithubAccessToken string) error {
var functionGithubTemplateFetcher *functiontemplates.GithubFunctionTemplateFetcher
templatesGitRepository string,
templatesGitRef string) error {
var functionGitTemplateFetcher *functiontemplates.GitFunctionTemplateFetcher

// read platform configuration
platformConfiguration, err := readPlatformConfiguration(platformConfigurationPath)
Expand All @@ -68,21 +66,18 @@ func Run(listenAddress string,
return errors.Wrap(err, "Failed to create platform")
}

// create github fetcher
if templatesGithubRepository != "" && templatesGithubOwner != "" && templatesGithubBranch != "" {
functionGithubTemplateFetcher, err = functiontemplates.NewGithubFunctionTemplateFetcher(rootLogger,
templatesGithubOwner,
templatesGithubRepository,
templatesGithubBranch,
templatesGithubAccessToken)
// create git fetcher
if templatesGitRepository != "" && templatesGitRef != "" {
functionGitTemplateFetcher, err = functiontemplates.NewGitFunctionTemplateFetcher(rootLogger,
templatesGitRepository,
templatesGitRef)
if err != nil {
return errors.Wrap(err, "Failed to create github fetcher")
return errors.Wrap(err, "Failed to create git fetcher")
}
} else {
rootLogger.DebugWith("Missing github fetcher configuration, templates from github won't be fetched",
"githubTemplateRepository", templatesGithubRepository,
"templatesGithubOwner", templatesGithubOwner,
"templatesGithubBranch", templatesGithubBranch)
rootLogger.DebugWith("Missing git fetcher configuration, templates from git won't be fetched",
"gitTemplateRepository", templatesGitRepository,
"templatesGitRef", templatesGitRef)
}

// create pre-generated templates fetcher
Expand All @@ -93,8 +88,8 @@ func Run(listenAddress string,

// make repository for fetcher
functionTemplateFetchers := []functiontemplates.FunctionTemplateFetcher{functionTemplatesGeneratedFetcher}
if functionGithubTemplateFetcher != nil {
functionTemplateFetchers = append(functionTemplateFetchers, functionGithubTemplateFetcher)
if functionGitTemplateFetcher != nil {
functionTemplateFetchers = append(functionTemplateFetchers, functionGitTemplateFetcher)
}
functionTemplatesRepository, err := functiontemplates.NewRepository(rootLogger, functionTemplateFetchers)
if err != nil {
Expand Down
14 changes: 5 additions & 9 deletions cmd/dashboard/main.go
Expand Up @@ -56,11 +56,9 @@ func main() {

externalIPAddressesDefault := os.Getenv("NUCLIO_DASHBOARD_EXTERNAL_IP_ADDRESSES")

// github templating env vars
templatesGithubOwner := flag.String("templates-github-owner", getEnvOrDefaultString("NUCLIO_TEMPLATES_GITHUB_OWNER", "nuclio"), "Github templates repo's owner")
templatesGithubRepository := flag.String("templates-github-repository", getEnvOrDefaultString("NUCLIO_TEMPLATES_GITHUB_REPOSITORY", "nuclio-templates"), "Github templates repo's name")
templatesGithubBranch := flag.String("templates-github-branch", getEnvOrDefaultString("NUCLIO_TEMPLATES_GITHUB_BRANCH", "master"), "Github templates repot's branch name")
templatesGithubAccessToken := flag.String("templates-github-access-token", os.Getenv("NUCLIO_TEMPLATES_GITHUB_ACCESS_TOKEN"), "Github access token for repo with templates")
// git templating env vars
templatesGitRepository := flag.String("templates-git-repository", getEnvOrDefaultString("NUCLIO_TEMPLATES_GIT_REPOSITORY", "https://github.com/nuclio/nuclio-templates.git"), "Git templates repo's name")
templatesGitBranch := flag.String("templates-git-ref", getEnvOrDefaultString("NUCLIO_TEMPLATES_GIT_REF", "refs/heads/master"), "Git templates repo's branch name")

listenAddress := flag.String("listen-addr", ":8070", "IP/port on which the playground listens")
dockerKeyDir := flag.String("docker-key-dir", "", "Directory to look for docker keys for secure registries")
Expand Down Expand Up @@ -90,10 +88,8 @@ func main() {
*namespace,
*offline,
*platformConfigurationPath,
*templatesGithubOwner,
*templatesGithubRepository,
*templatesGithubBranch,
*templatesGithubAccessToken); err != nil {
*templatesGitRepository,
*templatesGitBranch); err != nil {

errors.PrintErrorStack(os.Stderr, err, 5)

Expand Down
20 changes: 7 additions & 13 deletions pkg/dashboard/functiontemplates/fetcher_test.go
Expand Up @@ -17,32 +17,26 @@ limitations under the License.
package functiontemplates

import (
"os"
"testing"

"github.com/nuclio/logger"
"github.com/nuclio/zap"
"github.com/stretchr/testify/suite"
)

type GithubFetcherTestSuite struct {
type GitFetcherTestSuite struct {
suite.Suite
logger logger.Logger
}

func (suite *GithubFetcherTestSuite) SetupSuite() {
func (suite *GitFetcherTestSuite) SetupSuite() {
suite.logger, _ = nucliozap.NewNuclioZapTest("test")
}

func (suite *GithubFetcherTestSuite) TestFetch() {
suite.T().Skip("Requires NUCLIO_GITHUB_ACCESS_TOKEN")

githubAccessToken := os.Getenv("NUCLIO_GITHUB_ACCESS_TOKEN")
templateFetcher, err := NewGithubFunctionTemplateFetcher(suite.logger,
"pavius",
"nuclio-templates",
"add-string-manipulator",
githubAccessToken)
func (suite *GitFetcherTestSuite) TestFetch() {
templateFetcher, err := NewGitFunctionTemplateFetcher(suite.logger,
"https://github.com/nuclio/nuclio-templates.git",
"refs/heads/master")
suite.Require().NoError(err)

templates, err := templateFetcher.Fetch()
Expand All @@ -56,5 +50,5 @@ func TestGithubFetcher(t *testing.T) {
return
}

suite.Run(t, new(GithubFetcherTestSuite))
suite.Run(t, new(GitFetcherTestSuite))
}

0 comments on commit 3d5aa1f

Please sign in to comment.