Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: option to disable registry login in "werf ci-env"
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Oct 13, 2023
1 parent 9c8ac10 commit 170d068
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/werf/ci_env/ci_env.go
Expand Up @@ -34,6 +34,7 @@ var cmdData struct {
AsEnvFile bool
OutputFilePath string
Shell string
AllowRegistryLogin bool
}

var commonCmdData common.CmdData
Expand Down Expand Up @@ -77,6 +78,7 @@ Currently supported only GitLab (gitlab) and GitHub (github) CI systems`,

common.SetupLogOptions(&commonCmdData, cmd)

cmd.Flags().BoolVarP(&cmdData.AllowRegistryLogin, "login-to-registry", "", util.GetBoolEnvironmentDefaultTrue("WERF_LOGIN_TO_REGISTRY"), "Log in to CI-specific registry automatically if possible (default $WERF_LOGIN_TO_REGISTRY).")
cmd.Flags().BoolVarP(&cmdData.AsFile, "as-file", "", util.GetBoolEnvironmentDefaultFalse("WERF_AS_FILE"), "Create the script and print the path for sourcing (default $WERF_AS_FILE).")
cmd.Flags().BoolVarP(&cmdData.AsEnvFile, "as-env-file", "", util.GetBoolEnvironmentDefaultFalse("WERF_AS_ENV_FILE"), "Create the .env file and print the path for sourcing (default $WERF_AS_ENV_FILE).")
cmd.Flags().StringVarP(&cmdData.OutputFilePath, "output-file-path", "o", os.Getenv("WERF_OUTPUT_FILE_PATH"), "Write to custom file (default $WERF_OUTPUT_FILE_PATH).")
Expand Down Expand Up @@ -217,7 +219,7 @@ func generateGitlabEnvs(ctx context.Context, w io.Writer, dockerConfig string) e
}
}

if doLogin {
if doLogin && cmdData.AllowRegistryLogin {
err := docker.Login(ctx, imagesUsername, imagesPassword, ciRegistryImageEnv)
if err != nil {
return fmt.Errorf("unable to login into docker repo %s: %w", ciRegistryImageEnv, err)
Expand Down Expand Up @@ -321,7 +323,7 @@ func generateGithubEnvs(ctx context.Context, w io.Writer, dockerConfig string) e

ciGithubActor := os.Getenv("GITHUB_ACTOR")
ciGithubToken := os.Getenv("GITHUB_TOKEN")
if ciGithubActor != "" && ciGithubToken != "" {
if ciGithubActor != "" && ciGithubToken != "" && cmdData.AllowRegistryLogin {
err := docker.Login(ctx, ciGithubActor, ciGithubToken, registryToLogin)
if err != nil {
return fmt.Errorf("unable to login into docker registry %s: %w", defaultRegistry, err)
Expand Down

0 comments on commit 170d068

Please sign in to comment.