From 876705474aeca8e509dbb13c0df5377bea2e75ae Mon Sep 17 00:00:00 2001 From: Chingis Sandanov Date: Fri, 1 Mar 2019 16:29:48 +0700 Subject: [PATCH] Fixes --- cmd/wodby/ci/initialize/initialize.go | 36 +++++------ pkg/types/types.go | 87 +++++++++++++-------------- 2 files changed, 57 insertions(+), 66 deletions(-) diff --git a/cmd/wodby/ci/initialize/initialize.go b/cmd/wodby/ci/initialize/initialize.go index 7044ade..3a488d6 100644 --- a/cmd/wodby/ci/initialize/initialize.go +++ b/cmd/wodby/ci/initialize/initialize.go @@ -25,16 +25,16 @@ import ( ) type options struct { - uuid string - context string - dind bool - buildNumber string - username string - email string - url string - fixPermissionDir string - provider string - message string + uuid string + context string + dind bool + buildNumber string + username string + email string + url string + fixPermissions bool + provider string + message string } var opts options @@ -179,15 +179,11 @@ var Cmd = &cobra.Command{ } // We will fix permissions either when it was instructed or when a it's a managed stack and a known CI environment. - if opts.fixPermissionDir != "" || (!config.BuildConfig.Custom && metadata.ProjectDir != "") { - var dir string - - if opts.fixPermissionDir != "" { - dir = opts.fixPermissionDir - fmt.Println("Fixing codebase permissions in a provided directory...") + if opts.fixPermissions || (!config.BuildConfig.Custom && metadata.Provider != "Unknown") { + if opts.fixPermissions { + fmt.Println("Instructed to fix codebase permissions...") } else { - dir = metadata.ProjectDir - fmt.Println(fmt.Sprintf("Managed stack detected in a known CI environment %s – fixing codebase permissions in %s...", metadata.Provider, metadata.ProjectDir)) + fmt.Println(fmt.Sprintf("Managed stack detected in a known CI environment %s – automatically fixing codebase permissions...", metadata.Provider)) } defaultUser, err := dockerClient.GetImageDefaultUser(defaultService.Image) @@ -208,7 +204,7 @@ var Cmd = &cobra.Command{ runConfig.Volumes = append(runConfig.Volumes, fmt.Sprintf("%s:%s", config.Context, config.WorkingDir)) } - args := []string{"chown", "-R", fmt.Sprintf("%s:%s", defaultUser, defaultUser), dir} + args := []string{"chown", "-R", fmt.Sprintf("%s:%s", defaultUser, defaultUser), "."} err := dockerClient.Run(args, runConfig) if err != nil { @@ -262,7 +258,7 @@ var Cmd = &cobra.Command{ func init() { Cmd.Flags().StringVarP(&opts.context, "context", "c", "", "Build context (default: current directory)") Cmd.Flags().BoolVar(&opts.dind, "dind", false, "Use data container for sharing files between commands") - Cmd.Flags().StringVar(&opts.fixPermissionDir, "fix-permissions-dir", "", "Fix permissions to the default service user id in provided directory. Performed automatically for known CI environments") + Cmd.Flags().BoolVar(&opts.fixPermissions, "fix-permissions", false, "Fix codebase permissions. Performed automatically for known CI environments. WARNING: make sure you run wodby ci init from the project directory") Cmd.Flags().StringVarP(&opts.buildNumber, "build-num", "n", "", "Custom build number (used if can't identify automatically)") Cmd.Flags().StringVar(&opts.url, "url", "", "Custom build url (used if can't acquire automatically)") Cmd.Flags().StringVar(&opts.provider, "provider", "p", "Custom build provider name (used if can't identify automatically)") diff --git a/pkg/types/types.go b/pkg/types/types.go index 326f0fc..e10a8d5 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -72,19 +72,18 @@ type BuildConfig struct { } type BuildMetadata struct { - Provider string `json,mapstructure:"provider"` - Username string `json,mapstructure:"username"` - Email string `json,mapstructure:"email"` - Number string `json,mapstructure:"number"` - URL string `json,mapstructure:"url"` - Branch string `json,mapstructure:"branch"` - Commit string `json,mapstructure:"commit"` - Message string `json,mapstructure:"message"` - Tag string `json,mapstructure:"tag"` - Slug string `json,mapstructure:"slug"` - RepoURL string `json,mapstructure:"repo_url"` - Id string `json,mapstructure:"id"` - ProjectDir string `json,mapstructure:"project_dir"` + Provider string `json,mapstructure:"provider"` + Username string `json,mapstructure:"username"` + Email string `json,mapstructure:"email"` + Number string `json,mapstructure:"number"` + URL string `json,mapstructure:"url"` + Branch string `json,mapstructure:"branch"` + Commit string `json,mapstructure:"commit"` + Message string `json,mapstructure:"message"` + Tag string `json,mapstructure:"tag"` + Slug string `json,mapstructure:"slug"` + RepoURL string `json,mapstructure:"repo_url"` + Id string `json,mapstructure:"id"` } func NewBuildMetadata(provider string, buildNumber string, url string) (*BuildMetadata, error) { @@ -92,50 +91,46 @@ func NewBuildMetadata(provider string, buildNumber string, url string) (*BuildMe if os.Getenv("TRAVIS") != "" { metadata = &BuildMetadata{ - Provider: TravisCI, - URL: url, - Id: os.Getenv("TRAVIS_BUILD_ID"), - Number: os.Getenv("TRAVIS_BUILD_NUMBER"), - Branch: os.Getenv("TRAVIS_BRANCH"), - Commit: os.Getenv("TRAVIS_COMMIT"), - Message: os.Getenv("TRAVIS_COMMIT_MESSAGE"), - Tag: os.Getenv("TRAVIS_TAG"), - Slug: os.Getenv("TRAVIS_REPO_SLUG"), - ProjectDir: os.Getenv("TRAVIS_REPO_SLUG"), + Provider: TravisCI, + URL: url, + Id: os.Getenv("TRAVIS_BUILD_ID"), + Number: os.Getenv("TRAVIS_BUILD_NUMBER"), + Branch: os.Getenv("TRAVIS_BRANCH"), + Commit: os.Getenv("TRAVIS_COMMIT"), + Message: os.Getenv("TRAVIS_COMMIT_MESSAGE"), + Tag: os.Getenv("TRAVIS_TAG"), + Slug: os.Getenv("TRAVIS_REPO_SLUG"), } } else if os.Getenv("CIRCLECI") != "" { metadata = &BuildMetadata{ - Provider: CircleCI, - URL: os.Getenv("CIRCLE_BUILD_URL"), - Number: os.Getenv("CIRCLE_BUILD_NUM"), - Branch: os.Getenv("CIRCLE_BRANCH"), - Commit: os.Getenv("CIRCLE_SHA1"), - Tag: os.Getenv("CIRCLE_TAG"), - Slug: os.Getenv("CIRCLE_PROJECT_REPONAME"), - RepoURL: os.Getenv("CIRCLE_REPOSITORY_URL"), - ProjectDir: os.Getenv("CIRCLE_WORKING_DIRECTORY"), + Provider: CircleCI, + URL: os.Getenv("CIRCLE_BUILD_URL"), + Number: os.Getenv("CIRCLE_BUILD_NUM"), + Branch: os.Getenv("CIRCLE_BRANCH"), + Commit: os.Getenv("CIRCLE_SHA1"), + Tag: os.Getenv("CIRCLE_TAG"), + Slug: os.Getenv("CIRCLE_PROJECT_REPONAME"), + RepoURL: os.Getenv("CIRCLE_REPOSITORY_URL"), } } else if os.Getenv("BITBUCKET_BUILD_NUMBER") != "" { metadata = &BuildMetadata{ - Provider: BitbucketPipelines, - Number: os.Getenv("BITBUCKET_BUILD_NUMBER"), - Branch: os.Getenv("BITBUCKET_BRANCH"), - Commit: os.Getenv("BITBUCKET_COMMIT"), - Tag: os.Getenv("BITBUCKET_TAG"), - Slug: os.Getenv("BITBUCKET_REPO_SLUG"), - ProjectDir: os.Getenv("BITBUCKET_CLONE_DIR"), + Provider: BitbucketPipelines, + Number: os.Getenv("BITBUCKET_BUILD_NUMBER"), + Branch: os.Getenv("BITBUCKET_BRANCH"), + Commit: os.Getenv("BITBUCKET_COMMIT"), + Tag: os.Getenv("BITBUCKET_TAG"), + Slug: os.Getenv("BITBUCKET_REPO_SLUG"), } // @todo acquire repo slug and git tag from Jenkins. } else if os.Getenv("JENKINS_HOME") != "" { metadata = &BuildMetadata{ - Provider: Jenkins, - URL: os.Getenv("JOB_URL"), - Number: os.Getenv("BUILD_NUMBER"), - Branch: os.Getenv("GIT_BRANCH"), - Commit: os.Getenv("GIT_COMMIT"), - RepoURL: os.Getenv("GIT_URL"), - ProjectDir: os.Getenv("WORKSPACE"), + Provider: Jenkins, + URL: os.Getenv("JOB_URL"), + Number: os.Getenv("BUILD_NUMBER"), + Branch: os.Getenv("GIT_BRANCH"), + Commit: os.Getenv("GIT_COMMIT"), + RepoURL: os.Getenv("GIT_URL"), } } else { metadata = &BuildMetadata{}