forked from redhat-developer/kam
/
bootstrap.go
567 lines (514 loc) · 20.1 KB
/
bootstrap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
package pipelines
import (
"errors"
"fmt"
"net/url"
"os"
"path/filepath"
"sort"
"strings"
ssv1alpha1 "github.com/bitnami-labs/sealed-secrets/pkg/apis/sealed-secrets/v1alpha1"
"github.com/mitchellh/go-homedir"
"github.com/spf13/afero"
corev1 "k8s.io/api/core/v1"
v1rbac "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/config"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/deployment"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/dryrun"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/eventlisteners"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/imagerepo"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/ioutils"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/meta"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/namespaces"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/pipelines"
res "github.com/chetan-rns/gitops-cli/pkg/pipelines/resources"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/roles"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/routes"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/scm"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/secrets"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/statustracker"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/tasks"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/triggers"
"github.com/chetan-rns/gitops-cli/pkg/pipelines/yaml"
)
const (
// Kustomize constants for kustomization.yaml
Kustomize = "kustomization.yaml"
namespacesPath = "01-namespaces/cicd-environment.yaml"
rolesPath = "02-rolebindings/pipeline-service-role.yaml"
rolebindingsPath = "02-rolebindings/pipeline-service-rolebinding.yaml"
serviceAccountPath = "02-rolebindings/pipeline-service-account.yaml"
secretsPath = "03-secrets/gitops-webhook-secret.yaml"
dockerConfigPath = "03-secrets/docker-config.yaml"
gitopsTasksPath = "04-tasks/deploy-from-source-task.yaml"
appTaskPath = "04-tasks/deploy-using-kubectl-task.yaml"
ciPipelinesPath = "05-pipelines/ci-dryrun-from-push-pipeline.yaml"
appCiPipelinesPath = "05-pipelines/app-ci-pipeline.yaml"
pushTemplatePath = "07-templates/ci-dryrun-from-push-template.yaml"
appCIPushTemplatePath = "07-templates/app-ci-build-from-push-template.yaml"
eventListenerPath = "08-eventlisteners/cicd-event-listener.yaml"
routePath = "09-routes/gitops-webhook-event-listener.yaml"
dockerSecretName = "regcred"
saName = "pipeline"
roleBindingName = "pipelines-service-role-binding"
webhookSecretLength = 20
pipelinesFile = "pipelines.yaml"
bootstrapImage = "nginxinc/nginx-unprivileged:latest"
appCITemplateName = "app-ci-template"
version = 1
)
// BootstrapOptions is a struct that provides the optional flags
type BootstrapOptions struct {
GitOpsRepoURL string // This is where the pipelines and configuration are.
GitOpsWebhookSecret string // This is the secret for authenticating hooks from your GitOps repo.
Prefix string
DockerConfigJSONFilename string
ImageRepo string // This is where built images are pushed to.
InternalRegistryHostname string // This is the internal registry hostname used for pushing images.
OutputPath string // Where to write the bootstrapped files to?
SealedSecretsService types.NamespacedName // SealedSecrets Services name
StatusTrackerAccessToken string // The auth token to use to send commit-status notifications.
Overwrite bool // This allows to overwrite if there is an exixting gitops repository
ServiceRepoURL string // This is the full URL to your GitHub repository for your app source.
ServiceWebhookSecret string // This is the secret for authenticating hooks from your app source.
PrivateRepoDriver string // Records the type of the GitOpsRepoURL driver if not a well-known host.
}
// PolicyRules to be bound to service account
var (
Rules = []v1rbac.PolicyRule{
{
APIGroups: []string{""},
Resources: []string{"namespaces", "services"},
Verbs: []string{"patch", "get", "create"},
},
{
APIGroups: []string{"rbac.authorization.k8s.io"},
Resources: []string{"clusterroles", "roles"},
Verbs: []string{"bind", "patch", "get"},
},
{
APIGroups: []string{"rbac.authorization.k8s.io"},
Resources: []string{"clusterrolebindings", "rolebindings"},
Verbs: []string{"get", "create", "patch"},
},
{
APIGroups: []string{"bitnami.com"},
Resources: []string{"sealedsecrets"},
Verbs: []string{"get", "patch", "create"},
},
{
APIGroups: []string{"apps"},
Resources: []string{"deployments"},
Verbs: []string{"get", "create", "patch"},
},
{
APIGroups: []string{"argoproj.io"},
Resources: []string{"applications", "argocds"},
Verbs: []string{"get", "create", "patch"},
},
}
)
// Bootstrap bootstraps a GitOps pipelines and repository structure.
func Bootstrap(o *BootstrapOptions, appFs afero.Fs) error {
err := checkPipelinesFileExists(appFs, o.OutputPath, o.Overwrite)
if err != nil {
return err
}
if o.GitOpsWebhookSecret == "" {
gitopsSecret, err := secrets.GenerateString(webhookSecretLength)
if err != nil {
return fmt.Errorf("failed to generate GitOps webhook secret: %v", err)
}
o.GitOpsWebhookSecret = gitopsSecret
}
if o.ServiceWebhookSecret == "" {
appSecret, err := secrets.GenerateString(webhookSecretLength)
if err != nil {
return fmt.Errorf("failed to generate application webhook secret: %v", err)
}
o.ServiceWebhookSecret = appSecret
}
bootstrapped, err := bootstrapResources(o, appFs)
if err != nil {
return fmt.Errorf("failed to bootstrap resources: %v", err)
}
buildParams := &BuildParameters{
PipelinesFolderPath: pipelinesFile,
OutputPath: o.OutputPath,
}
m := bootstrapped[pipelinesFile].(*config.Manifest)
built, err := buildResources(appFs, buildParams, m)
if err != nil {
return fmt.Errorf("failed to build resources: %v", err)
}
bootstrapped = res.Merge(built, bootstrapped)
_, err = yaml.WriteResources(appFs, o.OutputPath, bootstrapped)
return err
}
func bootstrapResources(o *BootstrapOptions, appFs afero.Fs) (res.Resources, error) {
isInternalRegistry, imageRepo, err := imagerepo.ValidateImageRepo(o.ImageRepo, o.InternalRegistryHostname)
if err != nil {
return nil, err
}
gitOpsRepo, err := scm.NewRepository(o.GitOpsRepoURL)
if err != nil {
return nil, err
}
appRepo, err := scm.NewRepository(o.ServiceRepoURL)
if err != nil {
return nil, err
}
repoName, err := repoFromURL(appRepo.URL())
if err != nil {
return nil, fmt.Errorf("invalid app repo URL: %v", err)
}
bootstrapped, err := createInitialFiles(
appFs, gitOpsRepo, o)
if err != nil {
return nil, err
}
ns := namespaces.NamesWithPrefix(o.Prefix)
appName := repoToAppName(repoName)
serviceName := repoName
secretName := secrets.MakeServiceWebhookSecretName(ns["dev"], serviceName)
envs, configEnv, err := bootstrapEnvironments(appRepo, o.Prefix, secretName, ns)
if err != nil {
return nil, err
}
if o.PrivateRepoDriver != "" {
host, err := scm.HostnameFromURL(o.GitOpsRepoURL)
if err != nil {
return nil, fmt.Errorf("failed to get hostname from URL %q: %w", o.GitOpsRepoURL, err)
}
configEnv.Git = &config.GitConfig{Drivers: map[string]string{host: o.PrivateRepoDriver}}
}
m := createManifest(gitOpsRepo.URL(), configEnv, envs...)
devEnv := m.GetEnvironment(ns["dev"])
if devEnv == nil {
return nil, errors.New("unable to bootstrap without dev environment")
}
app := m.GetApplication(ns["dev"], appName)
if app == nil {
return nil, errors.New("unable to bootstrap without application")
}
svcFiles, err := bootstrapServiceDeployment(devEnv, app)
if err != nil {
return nil, err
}
hookSecret, err := secrets.CreateSealedSecret(
meta.NamespacedName(ns["cicd"], secretName),
o.SealedSecretsService,
o.ServiceWebhookSecret,
eventlisteners.WebhookSecretKey)
if err != nil {
return nil, fmt.Errorf("failed to generate GitHub Webhook Secret: %v", err)
}
cfg := m.GetPipelinesConfig()
if cfg == nil {
return nil, errors.New("failed to find a pipeline configuration - unable to continue bootstrap")
}
secretFilename := filepath.Join("03-secrets", secretName+".yaml")
secretsPath := filepath.Join(config.PathForPipelines(cfg), "base", secretFilename)
bootstrapped[secretsPath] = hookSecret
bindingName, imageRepoBindingFilename, svcImageBinding := createSvcImageBinding(cfg, devEnv, appName, serviceName, imageRepo, !isInternalRegistry)
bootstrapped = res.Merge(svcImageBinding, bootstrapped)
kustomizePath := filepath.Join(config.PathForPipelines(cfg), "base", "kustomization.yaml")
k, ok := bootstrapped[kustomizePath].(res.Kustomization)
if !ok {
return nil, fmt.Errorf("no kustomization for the %s environment found", kustomizePath)
}
if isInternalRegistry {
filenames, resources, err := imagerepo.CreateInternalRegistryResources(
cfg, roles.CreateServiceAccount(meta.NamespacedName(cfg.Name, saName)),
imageRepo, o.GitOpsRepoURL)
if err != nil {
return nil, fmt.Errorf("failed to get resources for internal image repository: %v", err)
}
bootstrapped = res.Merge(resources, bootstrapped)
k.Resources = append(k.Resources, filenames...)
}
// This is specific to bootstrap, because there's only one service.
devEnv.Apps[0].Services[0].Pipelines = &config.Pipelines{
Integration: &config.TemplateBinding{
Bindings: append([]string{bindingName}, devEnv.Pipelines.Integration.Bindings[:]...),
},
}
bootstrapped[pipelinesFile] = m
k.Resources = append(k.Resources, secretFilename, imageRepoBindingFilename)
sort.Strings(k.Resources)
bootstrapped[kustomizePath] = k
bootstrapped = res.Merge(svcFiles, bootstrapped)
return bootstrapped, nil
}
func bootstrapServiceDeployment(dev *config.Environment, app *config.Application) (res.Resources, error) {
svc := dev.Apps[0].Services[0]
svcBase := filepath.Join(config.PathForService(app, dev, svc.Name), "base", "config")
resources := res.Resources{}
// TODO: This should change if we add Namespace to Environment.
// We'd need to create the resources in the namespace _of_ the Environment.
resources[filepath.Join(svcBase, "100-deployment.yaml")] = deployment.Create(app.Name, dev.Name, svc.Name, bootstrapImage, deployment.ContainerPort(8080))
resources[filepath.Join(svcBase, "200-service.yaml")] = createBootstrapService(app.Name, dev.Name, svc.Name)
resources[filepath.Join(svcBase, "kustomization.yaml")] = &res.Kustomization{Resources: []string{"100-deployment.yaml", "200-service.yaml"}}
return resources, nil
}
func bootstrapEnvironments(repo scm.Repository, prefix, secretName string, ns map[string]string) ([]*config.Environment, *config.Config, error) {
envs := []*config.Environment{}
var pipelinesConfig *config.PipelinesConfig
for _, k := range []string{"cicd", "dev", "stage"} {
v := ns[k]
if k == "cicd" {
pipelinesConfig = &config.PipelinesConfig{Name: prefix + "cicd"}
} else {
env := &config.Environment{Name: v}
if k == "dev" {
svc, err := serviceFromRepo(repo.URL(), secretName, ns["cicd"])
if err != nil {
return nil, nil, err
}
app, err := applicationFromRepo(repo.URL(), svc)
if err != nil {
return nil, nil, err
}
app.Services = []*config.Service{svc}
env.Apps = []*config.Application{app}
env.Pipelines = defaultPipelines(repo)
}
envs = append(envs, env)
}
}
cfg := &config.Config{Pipelines: pipelinesConfig, ArgoCD: &config.ArgoCDConfig{Namespace: "argocd"}}
return envs, cfg, nil
}
func serviceFromRepo(repoURL, secretName, secretNS string) (*config.Service, error) {
repo, err := repoFromURL(repoURL)
if err != nil {
return nil, err
}
return &config.Service{
Name: repo,
SourceURL: repoURL,
Webhook: &config.Webhook{
Secret: &config.Secret{
Name: secretName,
Namespace: secretNS,
},
},
}, nil
}
func applicationFromRepo(repoURL string, service *config.Service) (*config.Application, error) {
repo, err := repoFromURL(repoURL)
if err != nil {
return nil, err
}
return &config.Application{
Name: repoToAppName(repo),
Services: []*config.Service{service},
}, nil
}
func repoFromURL(raw string) (string, error) {
u, err := url.Parse(raw)
if err != nil {
return "", err
}
parts := strings.Split(u.Path, "/")
return strings.TrimSuffix(parts[len(parts)-1], ".git"), nil
}
func orgRepoFromURL(raw string) (string, error) {
u, err := url.Parse(raw)
if err != nil {
return "", err
}
parts := strings.Split(u.Path, "/")
orgRepo := strings.Join(parts[len(parts)-2:], "/")
return strings.TrimSuffix(orgRepo, ".git"), nil
}
func createBootstrapService(appName, ns, name string) *corev1.Service {
svc := &corev1.Service{
TypeMeta: meta.TypeMeta("Service", "v1"),
ObjectMeta: meta.ObjectMeta(meta.NamespacedName(ns, name)),
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "http",
Protocol: corev1.ProtocolTCP,
Port: 8080,
TargetPort: intstr.FromInt(8080)},
},
},
}
labels := map[string]string{
deployment.KubernetesAppNameLabel: name,
deployment.KubernetesPartOfLabel: appName,
}
svc.ObjectMeta.Labels = labels
svc.Spec.Selector = labels
return svc
}
func repoToAppName(repoName string) string {
return "app-" + repoName
}
func defaultPipelines(r scm.Repository) *config.Pipelines {
return &config.Pipelines{
Integration: &config.TemplateBinding{
Template: appCITemplateName,
Bindings: []string{r.PushBindingName()},
},
}
}
// Checks whether the pipelines.yaml is present in the output path specified.
func checkPipelinesFileExists(appFs afero.Fs, outputPath string, overWrite bool) error {
exists, _ := ioutils.IsExisting(appFs, filepath.Join(outputPath, pipelinesFile))
if exists && !overWrite {
return fmt.Errorf("pipelines.yaml in output path already exists. If you want to replace your existing files, please rerun with --overwrite.")
}
return nil
}
func createInitialFiles(fs afero.Fs, repo scm.Repository, o *BootstrapOptions) (res.Resources, error) {
cicd := &config.PipelinesConfig{Name: o.Prefix + "cicd"}
pipelineConfig := &config.Config{Pipelines: cicd}
pipelines := createManifest(repo.URL(), pipelineConfig)
initialFiles := res.Resources{
pipelinesFile: pipelines,
}
resources, err := createCICDResources(fs, repo, cicd, o)
if err != nil {
return nil, err
}
files := getResourceFiles(resources)
prefixedResources := addPrefixToResources(pipelinesPath(pipelines.Config), resources)
initialFiles = res.Merge(prefixedResources, initialFiles)
pipelinesConfigKustomizations := addPrefixToResources(
config.PathForPipelines(pipelines.Config.Pipelines),
getCICDKustomization(files))
initialFiles = res.Merge(pipelinesConfigKustomizations, initialFiles)
return initialFiles, nil
}
// createDockerSecret creates a secret that allows pushing images to upstream repositories.
func createDockerSecret(fs afero.Fs, dockerConfigJSONFilename, secretNS string, SealedSecretsService types.NamespacedName) (*ssv1alpha1.SealedSecret, error) {
if dockerConfigJSONFilename == "" {
return nil, errors.New("failed to generate path to file: --dockerconfigjson flag is not provided")
}
authJSONPath, err := homedir.Expand(dockerConfigJSONFilename)
if err != nil {
return nil, fmt.Errorf("failed to generate path to file: %v", err)
}
f, err := fs.Open(authJSONPath)
if err != nil {
return nil, fmt.Errorf("failed to read Docker config %#v : %s", authJSONPath, err)
}
defer f.Close()
dockerSecret, err := secrets.CreateSealedDockerConfigSecret(meta.NamespacedName(secretNS, dockerSecretName), SealedSecretsService, f)
if err != nil {
return nil, err
}
return dockerSecret, nil
}
// createCICDResources creates resources assocated to pipelines.
func createCICDResources(fs afero.Fs, repo scm.Repository, pipelineConfig *config.PipelinesConfig, o *BootstrapOptions) (res.Resources, error) {
cicdNamespace := pipelineConfig.Name
// key: path of the resource
// value: YAML content of the resource
outputs := map[string]interface{}{}
githubSecret, err := secrets.CreateSealedSecret(meta.NamespacedName(cicdNamespace, eventlisteners.GitOpsWebhookSecret),
o.SealedSecretsService, o.GitOpsWebhookSecret, eventlisteners.WebhookSecretKey)
if err != nil {
return nil, fmt.Errorf("failed to generate GitHub Webhook Secret: %w", err)
}
outputs[secretsPath] = githubSecret
outputs[namespacesPath] = namespaces.Create(cicdNamespace, o.GitOpsRepoURL)
outputs[rolesPath] = roles.CreateClusterRole(meta.NamespacedName("", roles.ClusterRoleName), Rules)
sa := roles.CreateServiceAccount(meta.NamespacedName(cicdNamespace, saName))
if o.DockerConfigJSONFilename != "" {
dockerSecret, err := createDockerSecret(fs, o.DockerConfigJSONFilename, cicdNamespace,
o.SealedSecretsService)
if err != nil {
return nil, err
}
outputs[dockerConfigPath] = dockerSecret
outputs[serviceAccountPath] = roles.AddSecretToSA(sa, dockerSecretName)
}
if o.StatusTrackerAccessToken != "" {
trackerResources, err := statustracker.Resources(cicdNamespace, o.StatusTrackerAccessToken, o.SealedSecretsService,
o.GitOpsRepoURL, o.PrivateRepoDriver)
if err != nil {
return nil, err
}
outputs = res.Merge(outputs, trackerResources)
}
outputs[rolebindingsPath] = roles.CreateClusterRoleBinding(meta.NamespacedName("", roleBindingName), sa, "ClusterRole", roles.ClusterRoleName)
script, err := dryrun.MakeScript("kubectl", cicdNamespace)
if err != nil {
return nil, err
}
outputs[gitopsTasksPath] = tasks.CreateDeployFromSourceTask(cicdNamespace, script)
outputs[appTaskPath] = tasks.CreateDeployUsingKubectlTask(cicdNamespace)
outputs[ciPipelinesPath] = pipelines.CreateCIPipeline(meta.NamespacedName(cicdNamespace, "ci-dryrun-from-push-pipeline"), cicdNamespace)
outputs[appCiPipelinesPath] = pipelines.CreateAppCIPipeline(meta.NamespacedName(cicdNamespace, "app-ci-pipeline"))
pushBinding, pushBindingName := repo.CreatePushBinding(cicdNamespace)
outputs[filepath.Join("06-bindings", pushBindingName+".yaml")] = pushBinding
outputs[pushTemplatePath] = triggers.CreateCIDryRunTemplate(cicdNamespace, saName)
outputs[appCIPushTemplatePath] = triggers.CreateDevCIBuildPRTemplate(cicdNamespace, saName)
outputs[eventListenerPath] = eventlisteners.Generate(repo, cicdNamespace, saName, eventlisteners.GitOpsWebhookSecret)
route, err := routes.Generate(cicdNamespace)
if err != nil {
return nil, err
}
outputs[routePath] = route
return outputs, nil
}
func createManifest(gitOpsRepoURL string, configEnv *config.Config, envs ...*config.Environment) *config.Manifest {
return &config.Manifest{
GitOpsURL: gitOpsRepoURL,
Environments: envs,
Config: configEnv,
Version: version,
}
}
func getCICDKustomization(files []string) res.Resources {
return res.Resources{
"overlays/kustomization.yaml": res.Kustomization{
Bases: []string{"../base"},
},
"base/kustomization.yaml": res.Kustomization{
Resources: files,
},
}
}
func pipelinesPath(m *config.Config) string {
return filepath.Join(config.PathForPipelines(m.Pipelines), "base")
}
func addPrefixToResources(prefix string, files res.Resources) map[string]interface{} {
updated := map[string]interface{}{}
for k, v := range files {
updated[filepath.Join(prefix, k)] = v
}
return updated
}
func getResourceFiles(res res.Resources) []string {
files := []string{}
for k := range res {
files = append(files, k)
}
sort.Strings(files)
return files
}
// check if the file exists or not
func CheckFileExists(fs afero.Fs, dockerConfigJSONFilename string) (string, error) {
if dockerConfigJSONFilename == "" {
return "", errors.New("failed to generate path to file: must provide --dockerconfigjson parameter")
}
authJSONPath, err := homedir.Expand(dockerConfigJSONFilename)
if err != nil {
return "", fmt.Errorf("failed to generate path to file: %v", err)
}
_, err = fs.Stat(authJSONPath)
if os.IsNotExist(err) {
return "", fmt.Errorf("file does not exist at the file-path passed to access the dockercfgjson, kindly enter a valid file path")
}
if err != nil {
return "", fmt.Errorf("failed to read Docker config %q : %s", authJSONPath, err)
}
return authJSONPath, nil
}