/
common.go
1601 lines (1307 loc) · 56.9 KB
/
common.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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package common
import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"
"github.com/spf13/cobra"
"github.com/werf/logboek"
"github.com/werf/logboek/pkg/level"
"github.com/werf/logboek/pkg/style"
"github.com/werf/logboek/pkg/types"
"github.com/werf/werf/pkg/build"
"github.com/werf/werf/pkg/build/stage"
"github.com/werf/werf/pkg/config"
"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/docker_registry"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/giterminism_manager"
"github.com/werf/werf/pkg/logging"
"github.com/werf/werf/pkg/storage"
"github.com/werf/werf/pkg/true_git"
"github.com/werf/werf/pkg/util"
"github.com/werf/werf/pkg/werf"
"github.com/werf/werf/pkg/werf/global_warnings"
)
type CmdData struct {
GitWorkTree *string
ProjectName *string
Dir *string
ConfigPath *string
ConfigTemplatesDir *string
TmpDir *string
HomeDir *string
SSHKeys *[]string
HelmChartDir *string
Environment *string
Release *string
Namespace *string
AddAnnotations *[]string
AddLabels *[]string
KubeContext *string
KubeConfig *string
KubeConfigBase64 *string
KubeConfigPathMergeList *[]string
StatusProgressPeriodSeconds *int64
HooksStatusProgressPeriodSeconds *int64
ReleasesHistoryMax *int
SetDockerConfigJsonValue *bool
Set *[]string
SetString *[]string
Values *[]string
SetFile *[]string
SecretValues *[]string
IgnoreSecretKey *bool
CommonRepoData *RepoData
StagesStorage *string
CommonFinalRepoData *RepoData
FinalStagesStorage *string
SecondaryStagesStorage *[]string
CacheStagesStorage *[]string
SkipBuild *bool
StubTags *bool
AddCustomTag *[]string
UseCustomTag *string
Synchronization *string
Parallel *bool
ParallelTasksLimit *int64
DockerConfig *string
InsecureRegistry *bool
SkipTlsVerifyRegistry *bool
InsecureHelmDependencies *bool
DryRun *bool
KeepStagesBuiltWithinLastNHours *uint64
WithoutKube *bool
LooseGiterminism *bool
Dev *bool
DevIgnore *[]string
DevBranch *string
IntrospectBeforeError *bool
IntrospectAfterError *bool
StagesToIntrospect *[]string
Follow *bool
LogDebug *bool
LogPretty *bool
LogVerbose *bool
LogQuiet *bool
LogColorMode *string
LogProjectDir *bool
LogTerminalWidth *int64
ReportPath *string
ReportFormat *string
VirtualMerge *bool
ScanContextNamespaceOnly *bool
// Host storage cleanup options
DisableAutoHostCleanup *bool
DockerServerStoragePath *string
AllowedDockerStorageVolumeUsage *uint
AllowedDockerStorageVolumeUsageMargin *uint
AllowedLocalCacheVolumeUsage *uint
AllowedLocalCacheVolumeUsageMargin *uint
Platform *string
}
const (
CleaningCommandsForceOptionDescription = "First remove containers that use werf docker images which are going to be deleted"
StubRepoAddress = "stub/repository"
StubTag = "TAG"
DefaultBuildParallelTasksLimit = 5
DefaultCleanupParallelTasksLimit = 10
)
func GetLongCommandDescription(text string) string {
return logboek.FitText(text, types.FitTextOptions{MaxWidth: 100})
}
func SetupSetDockerConfigJsonValue(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SetDockerConfigJsonValue = new(bool)
cmd.Flags().BoolVarP(cmdData.SetDockerConfigJsonValue, "set-docker-config-json-value", "", GetBoolEnvironmentDefaultFalse("WERF_SET_DOCKER_CONFIG_JSON_VALUE"), "Shortcut to set current docker config into the .Values.dockerconfigjson")
}
func SetupGitWorkTree(cmdData *CmdData, cmd *cobra.Command) {
cmdData.GitWorkTree = new(string)
cmd.Flags().StringVarP(cmdData.GitWorkTree, "git-work-tree", "", os.Getenv("WERF_GIT_WORK_TREE"), "Use specified git work tree dir (default $WERF_WORK_TREE or lookup for directory that contains .git in the current or parent directories)")
}
func SetupProjectName(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ProjectName = new(string)
cmd.Flags().StringVarP(cmdData.ProjectName, "project-name", "N", os.Getenv("WERF_PROJECT_NAME"), "Set a specific project name (default $WERF_PROJECT_NAME)")
}
func SetupDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Dir = new(string)
cmd.Flags().StringVarP(cmdData.Dir, "dir", "", os.Getenv("WERF_DIR"), "Use specified project directory where project’s werf.yaml and other configuration files should reside (default $WERF_DIR or current working directory)")
}
func SetupConfigPath(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ConfigPath = new(string)
cmd.Flags().StringVarP(cmdData.ConfigPath, "config", "", os.Getenv("WERF_CONFIG"), `Use custom configuration file (default $WERF_CONFIG or werf.yaml in working directory)`)
}
func SetupConfigTemplatesDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ConfigTemplatesDir = new(string)
cmd.Flags().StringVarP(cmdData.ConfigTemplatesDir, "config-templates-dir", "", os.Getenv("WERF_CONFIG_TEMPLATES_DIR"), `Custom configuration templates directory (default $WERF_CONFIG_TEMPLATES_DIR or .werf in working directory)`)
}
func SetupTmpDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.TmpDir = new(string)
cmd.Flags().StringVarP(cmdData.TmpDir, "tmp-dir", "", "", "Use specified dir to store tmp files and dirs (default $WERF_TMP_DIR or system tmp dir)")
}
func SetupGiterminismOptions(cmdData *CmdData, cmd *cobra.Command) {
setupLooseGiterminism(cmdData, cmd)
setupDev(cmdData, cmd)
setupDevIgnore(cmdData, cmd)
setupDevBranch(cmdData, cmd)
}
func setupLooseGiterminism(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LooseGiterminism = new(bool)
cmd.Flags().BoolVarP(cmdData.LooseGiterminism, "loose-giterminism", "", GetBoolEnvironmentDefaultFalse("WERF_LOOSE_GITERMINISM"), "Loose werf giterminism mode restrictions (NOTE: not all restrictions can be removed, more info https://werf.io/documentation/advanced/giterminism.html, default $WERF_LOOSE_GITERMINISM)")
}
func setupDev(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Dev = new(bool)
cmd.Flags().BoolVarP(cmdData.Dev, "dev", "", GetBoolEnvironmentDefaultFalse("WERF_DEV"), `Enable development mode (default $WERF_DEV).
The mode allows working with project files without doing redundant commits during debugging and development`)
}
func setupDevIgnore(cmdData *CmdData, cmd *cobra.Command) {
cmdData.DevIgnore = new([]string)
cmd.Flags().StringArrayVarP(cmdData.DevIgnore, "dev-ignore", "", []string{}, `Add rules to ignore tracked and untracked changes in development mode (can specify multiple).
Also, can be specified with $WERF_DEV_IGNORE_* (e.g. $WERF_DEV_IGNORE_TESTS=*_test.go, $WERF_DEV_IGNORE_DOCS=path/to/docs)`)
}
func setupDevBranch(cmdData *CmdData, cmd *cobra.Command) {
cmdData.DevBranch = new(string)
defaultValue := "_werf-dev"
envValue := os.Getenv("WERF_DEV_BRANCH")
if envValue != "" {
defaultValue = envValue
}
cmd.Flags().StringVarP(cmdData.DevBranch, "dev-branch", "", defaultValue, fmt.Sprintf("Set dev git branch name (default $WERF_DEV_BRANCH or %q)", defaultValue))
}
func SetupHomeDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.HomeDir = new(string)
cmd.Flags().StringVarP(cmdData.HomeDir, "home-dir", "", "", "Use specified dir to store werf cache files and dirs (default $WERF_HOME or ~/.werf)")
}
func SetupSSHKey(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SSHKeys = new([]string)
cmd.Flags().StringArrayVarP(cmdData.SSHKeys, "ssh-key", "", []string{}, `Use only specific ssh key(s).
Can be specified with $WERF_SSH_KEY_* (e.g. $WERF_SSH_KEY_REPO=~/.ssh/repo_rsa, $WERF_SSH_KEY_NODEJS=~/.ssh/nodejs_rsa).
Defaults to $WERF_SSH_KEY_*, system ssh-agent or ~/.ssh/{id_rsa|id_dsa}, see https://werf.io/documentation/reference/toolbox/ssh.html`)
}
func SetupReportPath(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ReportPath = new(string)
cmd.Flags().StringVarP(cmdData.ReportPath, "report-path", "", os.Getenv("WERF_REPORT_PATH"), "Report save path ($WERF_REPORT_PATH by default)")
}
func SetupReportFormat(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ReportFormat = new(string)
defaultValue := os.Getenv("WERF_REPORT_FORMAT")
if defaultValue == "" {
defaultValue = string(build.ReportJSON)
}
cmd.Flags().StringVarP(cmdData.ReportFormat, "report-format", "", defaultValue, fmt.Sprintf(`Report format: %[1]s or %[2]s (%[1]s or $WERF_REPORT_FORMAT by default)
%[1]s:
{
"Images": {
"<WERF_IMAGE_NAME>": {
"WerfImageName": "<WERF_IMAGE_NAME>",
"DockerRepo": "<REPO>",
"DockerTag": "<TAG>"
"DockerImageName": "<REPO>:<TAG>",
"DockerImageID": "<SHA256>",
"DockerImageDigest": "<SHA256>",
},
...
}
}
%[2]s:
WERF_<FORMATTED_WERF_IMAGE_NAME>_DOCKER_IMAGE_NAME=<REPO>:<TAG>
...
<FORMATTED_WERF_IMAGE_NAME> is werf image name from werf.yaml modified according to the following rules:
- all characters are uppercase (app -> APP);
- charset /- is replaced with _ (DEV/APP-FRONTEND -> DEV_APP_FRONTEND)`, string(build.ReportJSON), string(build.ReportEnvFile)))
}
func GetReportFormat(cmdData *CmdData) (build.ReportFormat, error) {
switch format := build.ReportFormat(*cmdData.ReportFormat); format {
case build.ReportJSON, build.ReportEnvFile:
return format, nil
default:
return "", fmt.Errorf("bad --report-format given %q, expected: \"%s\"", format, strings.Join([]string{string(build.ReportJSON), string(build.ReportEnvFile)}, "\", \""))
}
}
func SetupWithoutKube(cmdData *CmdData, cmd *cobra.Command) {
cmdData.WithoutKube = new(bool)
cmd.Flags().BoolVarP(cmdData.WithoutKube, "without-kube", "", GetBoolEnvironmentDefaultFalse("WERF_WITHOUT_KUBE"), "Do not skip deployed Kubernetes images (default $WERF_WITHOUT_KUBE)")
}
func SetupKeepStagesBuiltWithinLastNHours(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KeepStagesBuiltWithinLastNHours = new(uint64)
envValue, err := GetUint64EnvVar("WERF_KEEP_STAGES_BUILT_WITHIN_LAST_N_HOURS")
if err != nil {
TerminateWithError(err.Error(), 1)
}
var defaultValue uint64
if envValue != nil {
defaultValue = *envValue
} else {
defaultValue = 2
}
cmd.Flags().Uint64VarP(cmdData.KeepStagesBuiltWithinLastNHours, "keep-stages-built-within-last-n-hours", "", defaultValue, "Keep stages that were built within last hours (default $WERF_KEEP_STAGES_BUILT_WITHIN_LAST_N_HOURS or 2)")
}
func PredefinedValuesByEnvNamePrefix(envNamePrefix string, envNamePrefixesToExcept ...string) []string {
var result []string
env := os.Environ()
sort.Strings(env)
environLoop:
for _, keyValue := range env {
parts := strings.SplitN(keyValue, "=", 2)
if strings.HasPrefix(parts[0], envNamePrefix) {
for _, exceptEnvNamePrefix := range envNamePrefixesToExcept {
if strings.HasPrefix(parts[0], exceptEnvNamePrefix) {
continue environLoop
}
}
result = append(result, parts[1])
}
}
return result
}
func SetupEnvironment(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Environment = new(string)
cmd.Flags().StringVarP(cmdData.Environment, "env", "", os.Getenv("WERF_ENV"), "Use specified environment (default $WERF_ENV)")
}
func SetupRelease(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Release = new(string)
cmd.Flags().StringVarP(cmdData.Release, "release", "", os.Getenv("WERF_RELEASE"), "Use specified Helm release name (default [[ project ]]-[[ env ]] template or deploy.helmRelease custom template from werf.yaml or $WERF_RELEASE)")
}
func SetupNamespace(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Namespace = new(string)
cmd.Flags().StringVarP(cmdData.Namespace, "namespace", "", os.Getenv("WERF_NAMESPACE"), "Use specified Kubernetes namespace (default [[ project ]]-[[ env ]] template or deploy.namespace custom template from werf.yaml or $WERF_NAMESPACE)")
}
func SetupAddAnnotations(cmdData *CmdData, cmd *cobra.Command) {
cmdData.AddAnnotations = new([]string)
cmd.Flags().StringArrayVarP(cmdData.AddAnnotations, "add-annotation", "", []string{}, `Add annotation to deploying resources (can specify multiple).
Format: annoName=annoValue.
Also, can be specified with $WERF_ADD_ANNOTATION_* (e.g. $WERF_ADD_ANNOTATION_1=annoName1=annoValue1, $WERF_ADD_ANNOTATION_2=annoName2=annoValue2)`)
}
func SetupAddLabels(cmdData *CmdData, cmd *cobra.Command) {
cmdData.AddLabels = new([]string)
cmd.Flags().StringArrayVarP(cmdData.AddLabels, "add-label", "", []string{}, `Add label to deploying resources (can specify multiple).
Format: labelName=labelValue.
Also, can be specified with $WERF_ADD_LABEL_* (e.g. $WERF_ADD_LABEL_1=labelName1=labelValue1, $WERF_ADD_LABEL_2=labelName2=labelValue2)`)
}
func SetupKubeContext(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KubeContext = new(string)
cmd.PersistentFlags().StringVarP(cmdData.KubeContext, "kube-context", "", os.Getenv("WERF_KUBE_CONTEXT"), "Kubernetes config context (default $WERF_KUBE_CONTEXT)")
}
func SetupKubeConfig(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KubeConfig = new(string)
cmd.PersistentFlags().StringVarP(cmdData.KubeConfig, "kube-config", "", "", "Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or $KUBECONFIG)")
cmdData.KubeConfigPathMergeList = new([]string)
kubeConfigPathMergeListStr := GetFirstExistingKubeConfigEnvVar()
for _, path := range filepath.SplitList(kubeConfigPathMergeListStr) {
*cmdData.KubeConfigPathMergeList = append(*cmdData.KubeConfigPathMergeList, path)
}
}
func GetFirstExistingKubeConfigEnvVar() string {
return GetFirstExistingEnvVarAsString("WERF_KUBE_CONFIG", "WERF_KUBECONFIG", "KUBECONFIG")
}
func SetupKubeConfigBase64(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KubeConfigBase64 = new(string)
cmd.PersistentFlags().StringVarP(cmdData.KubeConfigBase64, "kube-config-base64", "", GetFirstExistingEnvVarAsString("WERF_KUBE_CONFIG_BASE64", "WERF_KUBECONFIG_BASE64", "KUBECONFIG_BASE64"), "Kubernetes config data as base64 string (default $WERF_KUBE_CONFIG_BASE64 or $WERF_KUBECONFIG_BASE64 or $KUBECONFIG_BASE64)")
}
func GetFirstExistingEnvVarAsString(envNames ...string) string {
for _, envName := range envNames {
if v := os.Getenv(envName); v != "" {
return v
}
}
return ""
}
func SetupCommonRepoData(cmdData *CmdData, cmd *cobra.Command) {
cmdData.CommonRepoData = &RepoData{IsCommon: true}
SetupImplementationForRepoData(cmdData.CommonRepoData, cmd, "repo-implementation", []string{"WERF_REPO_IMPLEMENTATION"}) // legacy
SetupContainerRegistryForRepoData(cmdData.CommonRepoData, cmd, "repo-container-registry", []string{"WERF_REPO_CONTAINER_REGISTRY"})
SetupDockerHubUsernameForRepoData(cmdData.CommonRepoData, cmd, "repo-docker-hub-username", []string{"WERF_REPO_DOCKER_HUB_USERNAME"})
SetupDockerHubPasswordForRepoData(cmdData.CommonRepoData, cmd, "repo-docker-hub-password", []string{"WERF_REPO_DOCKER_HUB_PASSWORD"})
SetupDockerHubTokenForRepoData(cmdData.CommonRepoData, cmd, "repo-docker-hub-token", []string{"WERF_REPO_DOCKER_HUB_TOKEN"})
SetupGithubTokenForRepoData(cmdData.CommonRepoData, cmd, "repo-github-token", []string{"WERF_REPO_GITHUB_TOKEN"})
SetupHarborUsernameForRepoData(cmdData.CommonRepoData, cmd, "repo-harbor-username", []string{"WERF_REPO_HARBOR_USERNAME"})
SetupHarborPasswordForRepoData(cmdData.CommonRepoData, cmd, "repo-harbor-password", []string{"WERF_REPO_HARBOR_PASSWORD"})
SetupQuayTokenForRepoData(cmdData.CommonRepoData, cmd, "repo-quay-token", []string{"WERF_REPO_QUAY_TOKEN"})
}
func SetupCommonFinalRepoData(cmdData *CmdData, cmd *cobra.Command) {
cmdData.CommonFinalRepoData = &RepoData{}
cmdData.CommonFinalRepoData.Implementation = new(string) // legacy
SetupContainerRegistryForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-container-registry", []string{"WERF_FINAL_REPO_CONTAINER_REGISTRY"})
SetupDockerHubUsernameForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-docker-hub-username", []string{"WERF_FINAL_REPO_DOCKER_HUB_USERNAME"})
SetupDockerHubPasswordForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-docker-hub-password", []string{"WERF_FINAL_REPO_DOCKER_HUB_PASSWORD"})
SetupDockerHubTokenForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-docker-hub-token", []string{"WERF_FINAL_REPO_DOCKER_HUB_TOKEN"})
SetupGithubTokenForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-github-token", []string{"WERF_FINAL_REPO_GITHUB_TOKEN"})
SetupHarborUsernameForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-harbor-username", []string{"WERF_FINAL_REPO_HARBOR_USERNAME"})
SetupHarborPasswordForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-harbor-password", []string{"WERF_FINAL_REPO_HARBOR_PASSWORD"})
SetupQuayTokenForRepoData(cmdData.CommonFinalRepoData, cmd, "final-repo-quay-token", []string{"WERF_FINAL_REPO_QUAY_TOKEN"})
}
func SetupSecondaryStagesStorageOptions(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SecondaryStagesStorage = new([]string)
cmd.Flags().StringArrayVarP(cmdData.SecondaryStagesStorage, "secondary-repo", "", []string{}, `Specify one or multiple secondary read-only repos with images that will be used as a cache.
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=..., $WERF_SECONDARY_REPO_2=...)`)
}
func SetupAddCustomTag(cmdData *CmdData, cmd *cobra.Command) {
cmdData.AddCustomTag = new([]string)
cmd.Flags().StringArrayVarP(cmdData.AddCustomTag, "add-custom-tag", "", []string{}, `Set tag aliases for the content-based tag of each image.
It is necessary to use the image name shortcut %image% or %image_slug% in the tag format if there is more than one image in the werf config.
Also, can be defined with $WERF_ADD_CUSTOM_TAG_* (e.g. $WERF_ADD_CUSTOM_TAG_1="%image%-tag1", $WERF_ADD_CUSTOM_TAG_2="%image%-tag2").
For cleaning custom tags and associated content-based tag are treated as one`)
}
func SetupUseCustomTag(cmdData *CmdData, cmd *cobra.Command) {
cmdData.UseCustomTag = new(string)
cmd.Flags().StringVarP(cmdData.UseCustomTag, "use-custom-tag", "", os.Getenv("WERF_USE_CUSTOM_TAG"), `Use a tag alias in helm templates instead of an image content-based tag (NOT RECOMMENDED).
It is necessary to use the image name shortcut %image% or %image_slug% in the tag format if there is more than one image in the werf config.
Also, can be defined with $WERF_USE_CUSTOM_TAG (e.g. $WERF_USE_CUSTOM_TAG="%image%-tag").
For cleaning custom tags and associated content-based tag are treated as one`)
}
func SetupCacheStagesStorageOptions(cmdData *CmdData, cmd *cobra.Command) {
cmdData.CacheStagesStorage = new([]string)
cmd.Flags().StringArrayVarP(cmdData.CacheStagesStorage, "cache-repo", "", []string{}, `Specify one or multiple cache repos with images that will be used as a cache. Cache will be populated when pushing newly built images into the primary repo and when pulling existing images from the primary repo. Cache repo will be used to pull images and to get manifests before making requests to the primary repo.
Also, can be specified with $WERF_CACHE_REPO_* (e.g. $WERF_CACHE_REPO_1=..., $WERF_CACHE_REPO_2=...)`)
}
func SetupStagesStorageOptions(cmdData *CmdData, cmd *cobra.Command) {
SetupInsecureRegistry(cmdData, cmd)
SetupSkipTlsVerifyRegistry(cmdData, cmd)
SetupCommonRepoData(cmdData, cmd)
setupStagesStorage(cmdData, cmd)
}
func SetupFinalStagesStorageOptions(cmdData *CmdData, cmd *cobra.Command) {
SetupCommonFinalRepoData(cmdData, cmd)
setupFinalStagesStorage(cmdData, cmd)
}
func setupStagesStorage(cmdData *CmdData, cmd *cobra.Command) {
cmdData.StagesStorage = new(string)
cmd.Flags().StringVarP(cmdData.StagesStorage, "repo", "", os.Getenv("WERF_REPO"), fmt.Sprintf("Docker Repo to store stages (default $WERF_REPO)"))
}
func setupFinalStagesStorage(cmdData *CmdData, cmd *cobra.Command) {
cmdData.FinalStagesStorage = new(string)
cmd.Flags().StringVarP(cmdData.FinalStagesStorage, "final-repo", "", os.Getenv("WERF_FINAL_REPO"), fmt.Sprintf("Docker Repo to store only those stages which are going to be used by the Kubernetes cluster, in other word final images (default $WERF_FINAL_REPO)"))
}
func SetupStatusProgressPeriod(cmdData *CmdData, cmd *cobra.Command) {
cmdData.StatusProgressPeriodSeconds = new(int64)
SetupStatusProgressPeriodP(cmdData.StatusProgressPeriodSeconds, cmd)
}
func SetupStatusProgressPeriodP(destination *int64, cmd *cobra.Command) {
cmd.PersistentFlags().Int64VarP(
destination,
"status-progress-period",
"",
*statusProgressPeriodDefaultValue(),
"Status progress period in seconds. Set -1 to stop showing status progress. Defaults to $WERF_STATUS_PROGRESS_PERIOD_SECONDS or 5 seconds",
)
}
func SetupReleasesHistoryMax(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ReleasesHistoryMax = new(int)
defaultValueP, err := GetIntEnvVar("WERF_RELEASES_HISTORY_MAX")
if err != nil {
TerminateWithError(fmt.Sprintf("bad WERF_RELEASES_HISTORY_MAX value: %s", err), 1)
}
var defaultValue int
if defaultValueP != nil {
defaultValue = int(*defaultValueP)
}
cmd.Flags().IntVarP(
cmdData.ReleasesHistoryMax,
"releases-history-max",
"",
defaultValue,
"Max releases to keep in release storage. Can be set by environment variable $WERF_RELEASES_HISTORY_MAX. By default werf keeps all releases.",
)
}
func statusProgressPeriodDefaultValue() *int64 {
defaultValue := int64(5)
v, err := GetIntEnvVar("WERF_STATUS_PROGRESS_PERIOD_SECONDS")
if err != nil {
TerminateWithError(err.Error(), 1)
}
if v == nil {
v, err = GetIntEnvVar("WERF_STATUS_PROGRESS_PERIOD")
if err != nil {
TerminateWithError(err.Error(), 1)
}
if v == nil {
return &defaultValue
} else {
return v
}
} else {
return v
}
}
func SetupHooksStatusProgressPeriod(cmdData *CmdData, cmd *cobra.Command) {
cmdData.HooksStatusProgressPeriodSeconds = new(int64)
SetupHooksStatusProgressPeriodP(cmdData.HooksStatusProgressPeriodSeconds, cmd)
}
func SetupHooksStatusProgressPeriodP(destination *int64, cmd *cobra.Command) {
cmd.PersistentFlags().Int64VarP(
destination,
"hooks-status-progress-period",
"",
*hooksStatusProgressPeriodDefaultValue(),
"Hooks status progress period in seconds. Set 0 to stop showing hooks status progress. Defaults to $WERF_HOOKS_STATUS_PROGRESS_PERIOD_SECONDS or status progress period value",
)
}
func hooksStatusProgressPeriodDefaultValue() *int64 {
defaultValue := statusProgressPeriodDefaultValue()
v, err := GetIntEnvVar("WERF_HOOKS_STATUS_PROGRESS_PERIOD_SECONDS")
if err != nil {
TerminateWithError(err.Error(), 1)
}
if v == nil {
v, err = GetIntEnvVar("WERF_HOOKS_STATUS_PROGRESS_PERIOD")
if err != nil {
TerminateWithError(err.Error(), 1)
}
if v == nil {
return defaultValue
} else {
return v
}
} else {
return v
}
}
func SetupInsecureHelmDependencies(cmdData *CmdData, cmd *cobra.Command) {
cmdData.InsecureHelmDependencies = new(bool)
cmd.Flags().BoolVarP(cmdData.InsecureHelmDependencies, "insecure-helm-dependencies", "", GetBoolEnvironmentDefaultFalse("WERF_INSECURE_HELM_DEPENDENCIES"), "Allow insecure oci registries to be used in the .helm/Chart.yaml dependencies configuration (default $WERF_INSECURE_HELM_DEPENDENCIES)")
}
func SetupInsecureRegistry(cmdData *CmdData, cmd *cobra.Command) {
if cmdData.InsecureRegistry != nil {
return
}
cmdData.InsecureRegistry = new(bool)
cmd.Flags().BoolVarP(cmdData.InsecureRegistry, "insecure-registry", "", GetBoolEnvironmentDefaultFalse("WERF_INSECURE_REGISTRY"), "Use plain HTTP requests when accessing a registry (default $WERF_INSECURE_REGISTRY)")
}
func SetupSkipTlsVerifyRegistry(cmdData *CmdData, cmd *cobra.Command) {
if cmdData.SkipTlsVerifyRegistry != nil {
return
}
cmdData.SkipTlsVerifyRegistry = new(bool)
cmd.Flags().BoolVarP(cmdData.SkipTlsVerifyRegistry, "skip-tls-verify-registry", "", GetBoolEnvironmentDefaultFalse("WERF_SKIP_TLS_VERIFY_REGISTRY"), "Skip TLS certificate validation when accessing a registry (default $WERF_SKIP_TLS_VERIFY_REGISTRY)")
}
func SetupDryRun(cmdData *CmdData, cmd *cobra.Command) {
cmdData.DryRun = new(bool)
cmd.Flags().BoolVarP(cmdData.DryRun, "dry-run", "", GetBoolEnvironmentDefaultFalse("WERF_DRY_RUN"), "Indicate what the command would do without actually doing that (default $WERF_DRY_RUN)")
}
func SetupDockerConfig(cmdData *CmdData, cmd *cobra.Command, extraDesc string) {
defaultValue := os.Getenv("WERF_DOCKER_CONFIG")
if defaultValue == "" {
defaultValue = os.Getenv("DOCKER_CONFIG")
}
cmdData.DockerConfig = new(string)
desc := "Specify docker config directory path. Default $WERF_DOCKER_CONFIG or $DOCKER_CONFIG or ~/.docker (in the order of priority)"
if extraDesc != "" {
desc += "\n"
desc += extraDesc
}
cmd.Flags().StringVarP(cmdData.DockerConfig, "docker-config", "", defaultValue, desc)
}
func SetupLogOptions(cmdData *CmdData, cmd *cobra.Command) {
setupLogDebug(cmdData, cmd)
setupLogVerbose(cmdData, cmd)
setupLogQuiet(cmdData, cmd, false)
setupLogColor(cmdData, cmd)
setupLogPretty(cmdData, cmd)
setupTerminalWidth(cmdData, cmd)
}
func SetupLogOptionsDefaultQuiet(cmdData *CmdData, cmd *cobra.Command) {
setupLogDebug(cmdData, cmd)
setupLogVerbose(cmdData, cmd)
setupLogQuiet(cmdData, cmd, true)
setupLogColor(cmdData, cmd)
setupLogPretty(cmdData, cmd)
setupTerminalWidth(cmdData, cmd)
}
func setupLogDebug(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogDebug = new(bool)
defaultValue := false
for _, envName := range []string{
"WERF_LOG_DEBUG",
"WERF_DEBUG",
} {
if os.Getenv(envName) != "" {
defaultValue = GetBoolEnvironmentDefaultFalse(envName)
break
}
}
for alias, env := range map[string]string{
"log-debug": "WERF_LOG_DEBUG",
"debug": "WERF_DEBUG",
} {
cmd.PersistentFlags().BoolVarP(
cmdData.LogDebug,
alias,
"",
defaultValue,
fmt.Sprintf("Enable debug (default $%s).", env),
)
}
if err := cmd.PersistentFlags().MarkHidden("debug"); err != nil {
panic(err)
}
}
func setupLogColor(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogColorMode = new(string)
logColorEnvironmentValue := os.Getenv("WERF_LOG_COLOR_MODE")
defaultValue := "auto"
if logColorEnvironmentValue != "" {
defaultValue = logColorEnvironmentValue
}
cmd.PersistentFlags().StringVarP(cmdData.LogColorMode, "log-color-mode", "", defaultValue, `Set log color mode.
Supported on, off and auto (based on the stdout’s file descriptor referring to a terminal) modes.
Default $WERF_LOG_COLOR_MODE or auto mode.`)
}
func setupLogQuiet(cmdData *CmdData, cmd *cobra.Command, isDefaultQuiet bool) {
cmdData.LogQuiet = new(bool)
defaultValue := isDefaultQuiet
for _, envName := range []string{
"WERF_LOG_QUIET",
"WERF_QUIET",
} {
if os.Getenv(envName) != "" {
if defaultValue {
defaultValue = GetBoolEnvironmentDefaultTrue(envName)
} else {
defaultValue = GetBoolEnvironmentDefaultFalse(envName)
}
break
}
}
for alias, env := range map[string]string{
"log-quiet": "WERF_LOG_QUIET",
"quiet": "WERF_QUIET",
} {
cmd.PersistentFlags().BoolVarP(
cmdData.LogQuiet,
alias,
"",
defaultValue,
fmt.Sprintf(`Disable explanatory output (default $%s).`, env),
)
}
if err := cmd.PersistentFlags().MarkHidden("quiet"); err != nil {
panic(err)
}
}
func setupLogVerbose(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogVerbose = new(bool)
var defaultValue bool
for _, envName := range []string{
"WERF_LOG_VERBOSE",
"WERF_VERBOSE",
} {
if os.Getenv(envName) != "" {
defaultValue = GetBoolEnvironmentDefaultFalse(envName)
break
}
}
for alias, env := range map[string]string{
"log-verbose": "WERF_LOG_VERBOSE",
"verbose": "WERF_VERBOSE",
} {
cmd.PersistentFlags().BoolVarP(
cmdData.LogVerbose,
alias,
"",
defaultValue,
fmt.Sprintf(`Enable verbose output (default $%s).`, env),
)
}
if err := cmd.PersistentFlags().MarkHidden("verbose"); err != nil {
panic(err)
}
}
func setupLogPretty(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogPretty = new(bool)
var defaultValue bool
if os.Getenv("WERF_LOG_PRETTY") != "" {
defaultValue = GetBoolEnvironmentDefaultFalse("WERF_LOG_PRETTY")
} else {
defaultValue = true
}
cmd.PersistentFlags().BoolVarP(cmdData.LogPretty, "log-pretty", "", defaultValue, `Enable emojis, auto line wrapping and log process border (default $WERF_LOG_PRETTY or true).`)
}
func setupTerminalWidth(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogTerminalWidth = new(int64)
cmd.PersistentFlags().Int64VarP(cmdData.LogTerminalWidth, "log-terminal-width", "", -1, fmt.Sprintf(`Set log terminal width.
Defaults to:
* $WERF_LOG_TERMINAL_WIDTH
* interactive terminal width or %d`, 140))
}
func SetupSet(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Set = new([]string)
cmd.Flags().StringArrayVarP(cmdData.Set, "set", "", []string{}, `Set helm values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2).
Also, can be defined with $WERF_SET_* (e.g. $WERF_SET_1=key1=val1, $WERF_SET_2=key2=val2)`)
}
func SetupSetString(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SetString = new([]string)
cmd.Flags().StringArrayVarP(cmdData.SetString, "set-string", "", []string{}, `Set STRING helm values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2).
Also, can be defined with $WERF_SET_STRING_* (e.g. $WERF_SET_STRING_1=key1=val1, $WERF_SET_STRING_2=key2=val2)`)
}
func SetupValues(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Values = new([]string)
cmd.Flags().StringArrayVarP(cmdData.Values, "values", "", []string{}, `Specify helm values in a YAML file or a URL (can specify multiple).
Also, can be defined with $WERF_VALUES_* (e.g. $WERF_VALUES_ENV=.helm/values_test.yaml, $WERF_VALUES_DB=.helm/values_db.yaml)`)
}
func SetupSetFile(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SetFile = new([]string)
cmd.Flags().StringArrayVarP(cmdData.SetFile, "set-file", "", []string{}, `Set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2).
Also, can be defined with $WERF_SET_FILE_* (e.g. $WERF_SET_FILE_1=key1=path1, $WERF_SET_FILE_2=key2=val2)`)
}
func SetupSecretValues(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SecretValues = new([]string)
cmd.Flags().StringArrayVarP(cmdData.SecretValues, "secret-values", "", []string{}, `Specify helm secret values in a YAML file (can specify multiple).
Also, can be defined with $WERF_SECRET_VALUES_* (e.g. $WERF_SECRET_VALUES_ENV=.helm/secret_values_test.yaml, $WERF_SECRET_VALUES_DB=.helm/secret_values_db.yaml)`)
}
func SetupIgnoreSecretKey(cmdData *CmdData, cmd *cobra.Command) {
cmdData.IgnoreSecretKey = new(bool)
cmd.Flags().BoolVarP(cmdData.IgnoreSecretKey, "ignore-secret-key", "", GetBoolEnvironmentDefaultFalse("WERF_IGNORE_SECRET_KEY"), "Disable secrets decryption (default $WERF_IGNORE_SECRET_KEY)")
}
func SetupParallelOptions(cmdData *CmdData, cmd *cobra.Command, defaultValue int64) {
SetupParallel(cmdData, cmd)
SetupParallelTasksLimit(cmdData, cmd, defaultValue)
}
func SetupParallel(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Parallel = new(bool)
cmd.Flags().BoolVarP(cmdData.Parallel, "parallel", "p", GetBoolEnvironmentDefaultTrue("WERF_PARALLEL"), "Run in parallel (default $WERF_PARALLEL or true)")
}
func SetupParallelTasksLimit(cmdData *CmdData, cmd *cobra.Command, defaultValue int64) {
cmdData.ParallelTasksLimit = new(int64)
cmd.Flags().Int64VarP(cmdData.ParallelTasksLimit, "parallel-tasks-limit", "", defaultValue, "Parallel tasks limit, set -1 to remove the limitation (default $WERF_PARALLEL_TASKS_LIMIT or 5)")
}
func SetupLogProjectDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.LogProjectDir = new(bool)
cmd.Flags().BoolVarP(cmdData.LogProjectDir, "log-project-dir", "", GetBoolEnvironmentDefaultFalse("WERF_LOG_PROJECT_DIR"), `Print current project directory path (default $WERF_LOG_PROJECT_DIR)`)
}
func SetupIntrospectAfterError(cmdData *CmdData, cmd *cobra.Command) {
cmdData.IntrospectAfterError = new(bool)
cmd.Flags().BoolVarP(cmdData.IntrospectAfterError, "introspect-error", "", false, "Introspect failed stage in the state, right after running failed assembly instruction")
}
func SetupIntrospectBeforeError(cmdData *CmdData, cmd *cobra.Command) {
cmdData.IntrospectBeforeError = new(bool)
cmd.Flags().BoolVarP(cmdData.IntrospectBeforeError, "introspect-before-error", "", false, "Introspect failed stage in the clean state, before running all assembly instructions of the stage")
}
func SetupIntrospectStage(cmdData *CmdData, cmd *cobra.Command) {
cmdData.StagesToIntrospect = new([]string)
cmd.Flags().StringArrayVarP(cmdData.StagesToIntrospect, "introspect-stage", "", []string{}, `Introspect a specific stage. The option can be used multiple times to introspect several stages.
There are the following formats to use:
* specify IMAGE_NAME/STAGE_NAME to introspect stage STAGE_NAME of either image or artifact IMAGE_NAME
* specify STAGE_NAME or */STAGE_NAME for the introspection of all existing stages with name STAGE_NAME
IMAGE_NAME is the name of an image or artifact described in werf.yaml, the nameless image specified with ~.
STAGE_NAME should be one of the following: `+strings.Join(allStagesNames(), ", "))
}
func SetupSkipBuild(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SkipBuild = new(bool)
cmd.Flags().BoolVarP(cmdData.SkipBuild, "skip-build", "Z", GetBoolEnvironmentDefaultFalse("WERF_SKIP_BUILD"), "Disable building of docker images, cached images in the repo should exist in the repo if werf.yaml contains at least one image description (default $WERF_SKIP_BUILD)")
}
func SetupStubTags(cmdData *CmdData, cmd *cobra.Command) {
cmdData.StubTags = new(bool)
cmd.Flags().BoolVarP(cmdData.StubTags, "stub-tags", "", GetBoolEnvironmentDefaultFalse("WERF_STUB_TAGS"), "Use stubs instead of real tags (default $WERF_STUB_TAGS)")
}
func SetupFollow(cmdData *CmdData, cmd *cobra.Command) {
cmdData.Follow = new(bool)
cmd.Flags().BoolVarP(cmdData.Follow, "follow", "", GetBoolEnvironmentDefaultFalse("WERF_FOLLOW"), `Enable follow mode (default $WERF_FOLLOW).
The mode allows restarting the command on a new commit.
In development mode (--dev), werf restarts the command on any changes (including untracked files) in the git repository worktree`)
}
func allStagesNames() []string {
var stageNames []string
for _, stageName := range stage.AllStages {
stageNames = append(stageNames, string(stageName))
}
return stageNames
}
func GetBoolEnvironmentDefaultFalse(environmentName string) bool {
switch os.Getenv(environmentName) {
case "1", "true", "yes":
return true
default:
return false
}
}
func GetBoolEnvironmentDefaultTrue(environmentName string) bool {
switch os.Getenv(environmentName) {
case "0", "false", "no":
return false
default:
return true
}
}
func getInt64EnvVar(varName string) (*int64, error) {
if v := os.Getenv(varName); v != "" {
vInt, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return nil, fmt.Errorf("bad %s variable value %q: %s", varName, v, err)
}
res := new(int64)
*res = vInt
return res, nil
}
return nil, nil
}
func GetIntEnvVarStrict(varName string) *int64 {
valP, err := GetIntEnvVar(varName)
if err != nil {
TerminateWithError(fmt.Sprintf("bad %s value: %s", varName, err), 1)
}
return valP
}
func GetIntEnvVar(varName string) (*int64, error) {
if v := os.Getenv(varName); v != "" {
vInt, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return nil, fmt.Errorf("bad %s variable value %q: %s", varName, v, err)
}
res := new(int64)
*res = vInt
return res, nil
}
return nil, nil
}
func GetUint64EnvVarStrict(varName string) *uint64 {
valP, err := GetUint64EnvVar(varName)
if err != nil {
TerminateWithError(fmt.Sprintf("bad %s value: %s", varName, err), 1)
}
return valP
}
func GetUint64EnvVar(varName string) (*uint64, error) {
if v := os.Getenv(varName); v != "" {
vUint, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return nil, fmt.Errorf("bad %s variable value %q: %s", varName, v, err)
}
res := new(uint64)
*res = vUint
return res, nil
}
return nil, nil
}
func GetParallelTasksLimit(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_PARALLEL_TASKS_LIMIT")
if err != nil {
return 0, err
}
if v == nil {
v = cmdData.ParallelTasksLimit
}
if *v <= 0 {
return -1, nil
} else {
return *v, nil
}
}
func GetStagesStorageAddress(cmdData *CmdData) (string, error) {
if *cmdData.StagesStorage == "" || *cmdData.StagesStorage == storage.LocalStorageAddress {
return "", fmt.Errorf("--repo=ADDRESS param required")
}
return *cmdData.StagesStorage, nil
}
func GetOptionalStagesStorageAddress(cmdData *CmdData) string {
if *cmdData.StagesStorage == "" {
return storage.LocalStorageAddress
}
return *cmdData.StagesStorage
}
func GetLocalStagesStorage(containerRuntime container_runtime.ContainerRuntime) (storage.StagesStorage, error) {
return storage.NewStagesStorage(
storage.LocalStorageAddress,
containerRuntime,
storage.StagesStorageOptions{},
)
}
func GetStagesStorage(stagesStorageAddress string, containerRuntime container_runtime.ContainerRuntime, cmdData *CmdData) (storage.StagesStorage, error) {
if _, match := containerRuntime.(*container_runtime.BuildahRuntime); match {
if stagesStorageAddress == "" || stagesStorageAddress == storage.LocalStorageAddress {
return nil, fmt.Errorf(`"--repo" should be specified and not equal ":local" for Buildah container runtime`)
}
}
if err := ValidateRepoContainerRegistry(cmdData.CommonRepoData.GetContainerRegistry()); err != nil {
return nil, err
}
return storage.NewStagesStorage(
stagesStorageAddress,
containerRuntime,
storage.StagesStorageOptions{
RepoStagesStorageOptions: storage.RepoStagesStorageOptions{
ContainerRegistry: cmdData.CommonRepoData.GetContainerRegistry(),