-
Notifications
You must be signed in to change notification settings - Fork 18
/
config_run.go
78 lines (66 loc) · 1.65 KB
/
config_run.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
package main
import (
"fmt"
"path/filepath"
"github.com/fatih/color"
)
// Run execute the current configuration
func (config *TGFConfig) Run() int {
app := config.tgf
if app.Image != "" {
config.Image = app.Image
config.RecommendedImageVersion = ""
config.RequiredVersionRange = ""
config.ImageVersion = nil
config.ImageTag = nil
}
if app.ImageVersion != "-" {
config.ImageVersion = &app.ImageVersion
}
if app.ImageTag != "-" {
config.ImageTag = &app.ImageTag
}
if app.Entrypoint != "" {
config.EntryPoint = app.Entrypoint
}
if !config.ValidateVersion() {
return 1
}
if app.ConfigDump {
fmt.Println(config.String())
return 0
}
if app.GetAllVersions {
if filepath.Base(config.EntryPoint) != "terragrunt" {
log.Error("--all-version works only with terragrunt as the entrypoint")
return 1
}
fmt.Println("TGF version", version)
app.Unmanaged = []string{"get-versions"}
}
docker := dockerConfig{config}
imageName := config.GetImageName()
if lastRefresh(imageName) > config.Refresh || config.IsPartialVersion() || !checkImage(imageName) || app.Refresh {
docker.refreshImage(imageName)
}
if app.LoggingLevel != "" {
config.LogLevel = app.LoggingLevel
}
if app.PruneImages {
docker.prune(config.Image)
return 0
}
if config.EntryPoint == "terragrunt" && app.Unmanaged == nil && !app.GetImageName {
title := color.New(color.FgYellow, color.Underline).SprintFunc()
log.Println(title("\nTGF Usage"))
app.Usage(nil)
}
if config.ImageVersion == nil {
actualVersion := docker.GetActualImageVersion()
config.ImageVersion = &actualVersion
if !config.ValidateVersion() {
return 2
}
}
return docker.call()
}