/
common.go
1593 lines (1305 loc) · 57.5 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/cleaning"
cleanup "github.com/werf/werf/pkg/cleaning"
"github.com/werf/werf/pkg/config"
"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/deploy/helm"
"github.com/werf/werf/pkg/docker_registry"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/logging"
"github.com/werf/werf/pkg/storage"
"github.com/werf/werf/pkg/util"
"github.com/werf/werf/pkg/werf"
)
type CmdData struct {
ProjectName *string
Dir *string
ConfigPath *string
ConfigTemplatesDir *string
TmpDir *string
HomeDir *string
SSHKeys *[]string
TagCustom *[]string
TagGitBranch *string
TagGitTag *string
TagGitCommit *string
TagByStagesSignature *bool
HelmChartDir *string
Environment *string
Release *string
Namespace *string
AddAnnotations *[]string
AddLabels *[]string
KubeContext *string
KubeConfig *string
KubeConfigBase64 *string
KubeConfigPathMergeList *[]string
HelmReleaseStorageNamespace *string
HelmReleaseStorageType *string
StatusProgressPeriodSeconds *int64
HooksStatusProgressPeriodSeconds *int64
ReleasesHistoryMax *int
Set *[]string
SetString *[]string
Values *[]string
SetFile *[]string
SecretValues *[]string
IgnoreSecretKey *bool
CommonRepoData *RepoData
StagesStorage *string
StagesStorageRepoData *RepoData
ImagesRepo *string
ImagesRepoMode *string
ImagesRepoData *RepoData
Synchronization *string
GitHistorySynchronization *bool
GitUnshallow *bool
AllowGitShallowClone *bool
Parallel *bool
ParallelTasksLimit *int64
DockerConfig *string
InsecureRegistry *bool
SkipTlsVerifyRegistry *bool
DryRun *bool
GitTagStrategyLimit *int64
GitTagStrategyExpiryDays *int64
GitCommitStrategyLimit *int64
GitCommitStrategyExpiryDays *int64
StagesSignatureStrategyLimit *int64
StagesSignatureStrategyExpiryDays *int64
WithoutKube *bool
IntrospectBeforeError *bool
IntrospectAfterError *bool
StagesToIntrospect *[]string
LogDebug *bool
LogPretty *bool
LogVerbose *bool
LogQuiet *bool
LogColorMode *string
LogProjectDir *bool
LogTerminalWidth *int64
ThreeWayMergeMode *string
PublishReportPath *string
PublishReportFormat *string
VirtualMerge *bool
VirtualMergeFromCommit *string
VirtualMergeIntoCommit *string
ScanContextNamespaceOnly *bool
}
const (
CleaningCommandsForceOptionDescription = "First remove containers that use werf docker images which are going to be deleted"
StubImagesRepoAddress = "stub/repository"
CiEnvGitTagStrategyLimitDefault = 10
CiEnvGitTagStrategyExpiryDaysDefault = 30
CiEnvGitCommitStrategyLimitDefault = 50
CiEnvGitCommitStrategyExpiryDaysDefault = 30
CiEnvStagesSignatureStrategyLimitDefault = -1
CiEnvStagesSignatureStrategyExpiryDaysDefault = -1
DefaultBuildParallelTasksLimit = 5
DefaultCleanupParallelTasksLimit = 10
)
func GetLongCommandDescription(text string) string {
return logboek.FitText(text, types.FitTextOptions{MaxWidth: 100})
}
func SetupProjectName(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ProjectName = new(string)
cmd.Flags().StringVarP(cmdData.ProjectName, "project-name", "N", os.Getenv("WERF_PROJECT_NAME"), "Use custom 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 custom working directory (default $WERF_DIR or current 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"), `Change to the 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 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}`)
}
func SetupPublishReportPath(cmdData *CmdData, cmd *cobra.Command) {
cmdData.PublishReportPath = new(string)
cmd.Flags().StringVarP(cmdData.PublishReportPath, "publish-report-path", "", os.Getenv("WERF_PUBLISH_REPORT_PATH"), "Publish report contains image info: full docker repo, tag, ID — for each published image ($WERF_PUBLISH_REPORT_PATH by default)")
}
func SetupPublishReportFormat(cmdData *CmdData, cmd *cobra.Command) {
cmdData.PublishReportFormat = new(string)
cmd.Flags().StringVarP(cmdData.PublishReportFormat, "publish-report-format", "", "json", "Publish report format (only json available for now, $WERF_PUBLISH_REPORT_FORMAT by default)")
}
func GetPublishReportFormat(cmdData *CmdData) (build.PublishReportFormat, error) {
switch format := build.PublishReportFormat(*cmdData.PublishReportFormat); format {
case build.PublishReportJSON:
return format, nil
default:
return "", fmt.Errorf("bad --publish-report-format given %q, expected: \"json\"", format)
}
}
func SetupImagesCleanupPolicies(cmdData *CmdData, cmd *cobra.Command) {
cmdData.GitTagStrategyLimit = new(int64)
cmdData.GitTagStrategyExpiryDays = new(int64)
cmdData.GitCommitStrategyLimit = new(int64)
cmdData.GitCommitStrategyExpiryDays = new(int64)
cmdData.StagesSignatureStrategyLimit = new(int64)
cmdData.StagesSignatureStrategyExpiryDays = new(int64)
cmd.Flags().Int64VarP(cmdData.GitTagStrategyLimit, "git-tag-strategy-limit", "", -1, "Keep max number of images published with the git-tag tagging strategy in the images repo. No limit by default, -1 disables the limit. Value can be specified by the $WERF_GIT_TAG_STRATEGY_LIMIT")
cmd.Flags().Int64VarP(cmdData.GitTagStrategyExpiryDays, "git-tag-strategy-expiry-days", "", -1, "Keep images published with the git-tag tagging strategy in the images repo for the specified maximum days since image published. Republished image will be kept specified maximum days since new publication date. No days limit by default, -1 disables the limit. Value can be specified by the $WERF_GIT_TAG_STRATEGY_EXPIRY_DAYS")
cmd.Flags().Int64VarP(cmdData.GitCommitStrategyLimit, "git-commit-strategy-limit", "", -1, "Keep max number of images published with the git-commit tagging strategy in the images repo. No limit by default, -1 disables the limit. Value can be specified by the $WERF_GIT_COMMIT_STRATEGY_LIMIT")
cmd.Flags().Int64VarP(cmdData.GitCommitStrategyExpiryDays, "git-commit-strategy-expiry-days", "", -1, "Keep images published with the git-commit tagging strategy in the images repo for the specified maximum days since image published. Republished image will be kept specified maximum days since new publication date. No days limit by default, -1 disables the limit. Value can be specified by the $WERF_GIT_COMMIT_STRATEGY_EXPIRY_DAYS")
cmd.Flags().Int64VarP(cmdData.StagesSignatureStrategyLimit, "stages-signature-strategy-limit", "", -1, "Keep max number of images published with the stages-signature tagging strategy in the images repo. No limit by default, -1 disables the limit. Value can be specified by the $WERF_STAGES_SIGNATURE_STRATEGY_LIMIT")
cmd.Flags().Int64VarP(cmdData.StagesSignatureStrategyExpiryDays, "stages-signature-strategy-expiry-days", "", -1, "Keep images published with the stages-signature tagging strategy in the images repo for the specified maximum days since image published. Republished image will be kept specified maximum days since new publication date. No days limit by default, -1 disables the limit. Value can be specified by the $WERF_STAGES_SIGNATURE_STRATEGY_EXPIRY_DAYS")
_ = cmd.Flags().MarkHidden("stages-signature-strategy-limit")
_ = cmd.Flags().MarkHidden("stages-signature-strategy-expiry-days")
}
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 SetupTag(cmdData *CmdData, cmd *cobra.Command) {
cmdData.TagCustom = new([]string)
cmdData.TagGitBranch = new(string)
cmdData.TagGitTag = new(string)
cmdData.TagGitCommit = new(string)
cmdData.TagByStagesSignature = new(bool)
cmd.Flags().StringArrayVarP(cmdData.TagCustom, "tag-custom", "", []string{}, "Use custom tagging strategy and tag by the specified arbitrary tags.\nOption can be used multiple times to produce multiple images with the specified tags.\nAlso can be specified in $WERF_TAG_CUSTOM_* (e.g. $WERF_TAG_CUSTOM_TAG1=tag1, $WERF_TAG_CUSTOM_TAG2=tag2)")
cmd.Flags().StringVarP(cmdData.TagGitBranch, "tag-git-branch", "", os.Getenv("WERF_TAG_GIT_BRANCH"), "Use git-branch tagging strategy and tag by the specified git branch (option can be enabled by specifying git branch in the $WERF_TAG_GIT_BRANCH)")
cmd.Flags().StringVarP(cmdData.TagGitTag, "tag-git-tag", "", os.Getenv("WERF_TAG_GIT_TAG"), "Use git-tag tagging strategy and tag by the specified git tag (option can be enabled by specifying git tag in the $WERF_TAG_GIT_TAG)")
cmd.Flags().StringVarP(cmdData.TagGitCommit, "tag-git-commit", "", os.Getenv("WERF_TAG_GIT_COMMIT"), "Use git-commit tagging strategy and tag by the specified git commit hash (option can be enabled by specifying git commit hash in the $WERF_TAG_GIT_COMMIT)")
cmd.Flags().BoolVarP(cmdData.TagByStagesSignature, "tag-by-stages-signature", "", GetBoolEnvironmentDefaultFalse("WERF_TAG_BY_STAGES_SIGNATURE"), "Use stages-signature tagging strategy and tag each image by the corresponding signature of last image stage (option can be enabled by specifying $WERF_TAG_BY_STAGES_SIGNATURE=true)")
}
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 SetupHelmChartDir(cmdData *CmdData, cmd *cobra.Command) {
cmdData.HelmChartDir = new(string)
cmd.Flags().StringVarP(cmdData.HelmChartDir, "helm-chart-dir", "", os.Getenv("WERF_HELM_CHART_DIR"), "Use custom helm chart dir (default $WERF_HELM_CHART_DIR or .helm in working directory)")
}
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 := getFirstExistingEnvVarAsString("WERF_KUBE_CONFIG", "WERF_KUBECONFIG", "KUBECONFIG")
for _, path := range filepath.SplitList(kubeConfigPathMergeListStr) {
*cmdData.KubeConfigPathMergeList = append(*cmdData.KubeConfigPathMergeList, path)
}
}
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 SetupHelmReleaseStorageNamespace(cmdData *CmdData, cmd *cobra.Command) {
cmdData.HelmReleaseStorageNamespace = new(string)
defaultValues := []string{
os.Getenv("WERF_HELM2_RELEASE_STORAGE_NAMESPACE"),
os.Getenv("WERF_HELM_RELEASE_STORAGE_NAMESPACE"),
os.Getenv("TILLER_NAMESPACE"),
helm.DefaultReleaseStorageNamespace,
}
var defaultValue string
for _, value := range defaultValues {
if value != "" {
defaultValue = value
break
}
}
cmd.Flags().StringVarP(cmdData.HelmReleaseStorageNamespace, "helm-release-storage-namespace", "", defaultValue, fmt.Sprintf("Helm release storage namespace (same as --tiller-namespace for regular helm, default $WERF_HELM_RELEASE_STORAGE_NAMESPACE, $TILLER_NAMESPACE or '%s')", helm.DefaultReleaseStorageNamespace))
}
func SetupHelmReleaseStorageType(cmdData *CmdData, cmd *cobra.Command) {
cmdData.HelmReleaseStorageType = new(string)
defaultValues := []string{
os.Getenv("WERF_HELM2_RELEASE_STORAGE_TYPE"),
os.Getenv("WERF_HELM_RELEASE_STORAGE_TYPE"),
helm.ConfigMapStorage,
}
var defaultValue string
for _, value := range defaultValues {
if value != "" {
defaultValue = value
break
}
}
cmd.Flags().StringVarP(cmdData.HelmReleaseStorageType, "helm-release-storage-type", "", defaultValue, fmt.Sprintf("helm storage driver to use. One of '%[1]s' or '%[2]s' (default $WERF_HELM_RELEASE_STORAGE_TYPE or '%[1]s')", helm.ConfigMapStorage, helm.SecretStorage))
}
func SetupCommonRepoData(cmdData *CmdData, cmd *cobra.Command) {
cmdData.CommonRepoData = &RepoData{IsCommon: true}
SetupImplementationForRepoData(cmdData.CommonRepoData, cmd, "repo-implementation", []string{"WERF_REPO_IMPLEMENTATION"})
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 SetupStagesStorageOptions(cmdData *CmdData, cmd *cobra.Command) {
// TODO: add the following options for images repo
SetupInsecureRegistry(cmdData, cmd)
SetupSkipTlsVerifyRegistry(cmdData, cmd)
if cmdData.CommonRepoData == nil {
SetupCommonRepoData(cmdData, cmd)
}
setupStagesStorage(cmdData, cmd)
cmdData.StagesStorageRepoData = &RepoData{DesignationStorageName: "stages storage"}
SetupImplementationForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-implementation", []string{"WERF_STAGES_STORAGE_REPO_IMPLEMENTATION", "WERF_REPO_IMPLEMENTATION"})
SetupDockerHubUsernameForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-docker-hub-username", []string{"WERF_STAGES_STORAGE_REPO_DOCKER_HUB_USERNAME", "WERF_REPO_DOCKER_HUB_USERNAME"})
SetupDockerHubPasswordForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-docker-hub-password", []string{"WERF_STAGES_STORAGE_REPO_DOCKER_HUB_PASSWORD", "WERF_REPO_DOCKER_HUB_PASSWORD"})
SetupDockerHubTokenForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-docker-hub-token", []string{"WERF_STAGES_STORAGE_REPO_DOCKER_HUB_TOKEN", "WERF_REPO_DOCKER_HUB_TOKEN"})
SetupGithubTokenForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-github-token", []string{"WERF_STAGES_STORAGE_REPO_GITHUB_TOKEN", "WERF_REPO_GITHUB_TOKEN"})
SetupHarborUsernameForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-harbor-username", []string{"WERF_STAGES_STORAGE_REPO_HARBOR_USERNAME", "WERF_REPO_HARBOR_USERNAME"})
SetupHarborPasswordForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-harbor-password", []string{"WERF_STAGES_STORAGE_REPO_HARBOR_PASSWORD", "WERF_REPO_HARBOR_PASSWORD"})
SetupQuayTokenForRepoData(cmdData.StagesStorageRepoData, cmd, "stages-storage-repo-quay-token", []string{"WERF_STAGES_STORAGE_REPO_QUAY_TOKEN", "WERF_REPO_QUAY_TOKEN"})
}
func setupStagesStorage(cmdData *CmdData, cmd *cobra.Command) {
cmdData.StagesStorage = new(string)
cmd.Flags().StringVarP(cmdData.StagesStorage, "stages-storage", "s", os.Getenv("WERF_STAGES_STORAGE"), fmt.Sprintf("Docker Repo to store stages or %[1]s for non-distributed build (only %[1]s is supported for now; default $WERF_STAGES_STORAGE environment)", storage.LocalStorageAddress))
}
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 {
return &defaultValue
} 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 {
return defaultValue
} else {
return v
}
}
func SetupImagesRepoOptions(cmdData *CmdData, cmd *cobra.Command) {
// TODO: add the following options for images repo
SetupInsecureRegistry(cmdData, cmd)
SetupSkipTlsVerifyRegistry(cmdData, cmd)
if cmdData.CommonRepoData == nil {
SetupCommonRepoData(cmdData, cmd)
}
setupImagesRepo(cmdData, cmd)
setupImagesRepoMode(cmdData, cmd)
cmdData.ImagesRepoData = &RepoData{DesignationStorageName: "images repo"}
SetupImplementationForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-implementation", []string{"WERF_IMAGES_REPO_IMPLEMENTATION", "WERF_REPO_IMPLEMENTATION"})
SetupDockerHubUsernameForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-docker-hub-username", []string{"WERF_IMAGES_REPO_DOCKER_HUB_USERNAME", "WERF_REPO_DOCKER_HUB_USERNAME"})
SetupDockerHubPasswordForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-docker-hub-password", []string{"WERF_IMAGES_REPO_DOCKER_HUB_PASSWORD", "WERF_REPO_DOCKER_HUB_PASSWORD"})
SetupDockerHubTokenForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-docker-hub-token", []string{"WERF_IMAGES_REPO_DOCKER_HUB_TOKEN", "WERF_REPO_DOCKER_HUB_TOKEN"})
SetupGithubTokenForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-github-token", []string{"WERF_IMAGES_REPO_GITHUB_TOKEN", "WERF_REPO_GITHUB_TOKEN"})
SetupHarborUsernameForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-harbor-username", []string{"WERF_IMAGES_REPO_HARBOR_USERNAME", "WERF_REPO_HARBOR_USERNAME"})
SetupHarborPasswordForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-harbor-password", []string{"WERF_IMAGES_REPO_HARBOR_PASSWORD", "WERF_REPO_HARBOR_PASSWORD"})
SetupQuayTokenForRepoData(cmdData.ImagesRepoData, cmd, "images-repo-quay-token", []string{"WERF_IMAGES_REPO_QUAY_TOKEN", "WERF_REPO_QUAY_TOKEN"})
}
func setupImagesRepo(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ImagesRepo = new(string)
cmd.Flags().StringVarP(cmdData.ImagesRepo, "images-repo", "i", os.Getenv("WERF_IMAGES_REPO"), "Docker Repo to store images (default $WERF_IMAGES_REPO)")
}
func setupImagesRepoMode(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ImagesRepoMode = new(string)
defaultValue := os.Getenv("WERF_IMAGES_REPO_MODE")
if defaultValue == "" {
defaultValue = "auto"
}
cmd.Flags().StringVarP(cmdData.ImagesRepoMode, "images-repo-mode", "", defaultValue, fmt.Sprintf(`Define how to store in images repo: %s or %s.
Default $WERF_IMAGES_REPO_MODE or auto mode`, docker_registry.MultirepoRepoMode, docker_registry.MonorepoRepoMode))
}
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)
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) {
cmdData.LogQuiet = new(bool)
var defaultValue bool
for _, envName := range []string{
"WERF_LOG_QUIET",
"WERF_QUIET",
} {
if os.Getenv(envName) != "" {
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 SetupSetFiles(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 SetupAllowGitShallowClone(cmdData *CmdData, cmd *cobra.Command) {
cmdData.AllowGitShallowClone = new(bool)
cmd.Flags().BoolVarP(cmdData.AllowGitShallowClone, "allow-git-shallow-clone", "", GetBoolEnvironmentDefaultFalse("WERF_ALLOW_GIT_SHALLOW_CLONE"), "Sign the intention of using shallow clone despite restrictions (default $WERF_ALLOW_GIT_SHALLOW_CLONE)")
}
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)")
}
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 SetupGitUnshallow(cmdData *CmdData, cmd *cobra.Command) {
cmdData.GitUnshallow = new(bool)
cmd.Flags().BoolVarP(cmdData.GitUnshallow, "git-unshallow", "", GetBoolEnvironmentDefaultFalse("WERF_GIT_UNSHALLOW"), "Convert project git clone to full one (default $WERF_GIT_UNSHALLOW)")
}
func SetupGitHistorySynchronization(cmdData *CmdData, cmd *cobra.Command) {
cmdData.GitHistorySynchronization = new(bool)
cmd.Flags().BoolVarP(cmdData.GitHistorySynchronization, "git-history-synchronization", "", GetBoolEnvironmentDefaultFalse("WERF_GIT_HISTORY_SYNCHRONIZATION"), "Synchronize git branches and tags with remote origin (default $WERF_GIT_HISTORY_SYNCHRONIZATION)")
}
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 allStagesNames() []string {
var stageNames []string
for _, stageName := range stage.AllStages {
stageNames = append(stageNames, string(stageName))
}
return stageNames
}
func SetupThreeWayMergeMode(cmdData *CmdData, cmd *cobra.Command) {
cmdData.ThreeWayMergeMode = new(string)
modeEnvironmentValue := os.Getenv("WERF_THREE_WAY_MERGE_MODE")
defaultValue := ""
if modeEnvironmentValue != "" {
defaultValue = modeEnvironmentValue
}
cmd.Flags().StringVarP(cmdData.ThreeWayMergeMode, "three-way-merge-mode", "", defaultValue, `Set three way merge mode for release.
Supported 'enabled', 'disabled' and 'onlyNewReleases'`)
}
func GetThreeWayMergeMode(threeWayMergeModeParam string) (helm.ThreeWayMergeModeType, error) {
switch threeWayMergeModeParam {
case "enabled", "disabled", "onlyNewReleases", "":
return helm.ThreeWayMergeModeType(threeWayMergeModeParam), nil
}
return "", fmt.Errorf("bad three-way-merge-mode '%s': enabled, disabled or onlyNewReleases modes can be specified", threeWayMergeModeParam)
}
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 ConvertInt32Value(v string) (int32, error) {
res, err := ConvertIntValue(v, 32)
if err != nil {
return 0, err
}
return int32(res), nil
}
func ConvertIntValue(v string, bitSize int) (int64, error) {
vInt, err := strconv.ParseInt(v, 10, bitSize)
if err != nil {
return 0, fmt.Errorf("bad integer value '%s': %s", v, err)
}
return vInt, nil
}
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 '%s': %s", varName, v, err)
}
res := new(int64)
*res = vInt
return res, nil
}
return nil, nil
}
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 '%s': %s", varName, v, err)
}
res := new(int64)
*res = vInt
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 GetGitTagStrategyLimit(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_GIT_TAG_STRATEGY_LIMIT")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.GitTagStrategyLimit, nil
}
func GetGitTagStrategyExpiryDays(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_GIT_TAG_STRATEGY_EXPIRY_DAYS")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.GitTagStrategyExpiryDays, nil
}
func GetGitCommitStrategyLimit(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_GIT_COMMIT_STRATEGY_LIMIT")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.GitCommitStrategyLimit, nil
}
func GetGitCommitStrategyExpiryDays(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_GIT_COMMIT_STRATEGY_EXPIRY_DAYS")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.GitCommitStrategyExpiryDays, nil
}
func GetStagesSignatureStrategyLimit(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_STAGES_SIGNATURE_STRATEGY_LIMIT")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.StagesSignatureStrategyLimit, nil
}
func GetStagesSignatureStrategyExpiryDays(cmdData *CmdData) (int64, error) {
v, err := getInt64EnvVar("WERF_STAGES_SIGNATURE_STRATEGY_EXPIRY_DAYS")
if err != nil {
return 0, err
}
if v != nil {
return *v, nil
}
return *cmdData.StagesSignatureStrategyExpiryDays, nil
}
func GetImagesCleanupPolicies(cmdData *CmdData) (cleanup.ImagesCleanupPolicies, error) {
tagLimit, err := GetGitTagStrategyLimit(cmdData)
if err != nil {
return cleanup.ImagesCleanupPolicies{}, err
}
tagDays, err := GetGitTagStrategyExpiryDays(cmdData)
if err != nil {
return cleanup.ImagesCleanupPolicies{}, err
}
commitLimit, err := GetGitCommitStrategyLimit(cmdData)
if err != nil {
return cleanup.ImagesCleanupPolicies{}, err
}