-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (73 loc) · 2.04 KB
/
main.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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/thoughtgears/streamlitter/config"
"github.com/thoughtgears/streamlitter/pkg/deploy"
)
var (
filePath string
region string
project string
credentialsFile string
repository string
debug bool
version bool
Version string
)
func init() {
flag.StringVar(&filePath, "file-path", "apps.yaml", "Path to the configuration file")
flag.StringVar(®ion, "region", "europe-west1", "GCP Region")
flag.StringVar(&project, "project", "", "GCP Project")
flag.StringVar(&repository, "repository", "", "Artifact Registry Repository")
flag.StringVar(&credentialsFile, "credentials-file", "", "Google JSON key file")
flag.BoolVar(&debug, "debug", false, "For debug purposes only")
flag.BoolVar(&version, "version", false, "Display app version")
flag.Parse()
if version {
fmt.Printf("Version: %s\n", Version)
os.Exit(0)
}
if project == "" {
project = os.Getenv("GPC_PROJECT_ID")
}
if region == "" {
region = os.Getenv("GPC_REGION")
}
if repository == "" {
repository = os.Getenv("REPO_NAME")
}
}
func main() {
cfg, err := config.NewConfig(project, region, repository, filePath)
if err != nil {
log.Fatal(err)
}
if debug {
fmt.Println("GCP config")
fmt.Printf(" Project: %s\n Region: %s\n Repo: %s\n", cfg.Project, cfg.Region, cfg.ArtifactRegistryName)
fmt.Println("App Configs:")
for _, app := range cfg.Apps {
fmt.Printf(" Name: %s\n Public App: %v\n", app.Name, app.Public)
fmt.Printf(" Image: %s\n Version: %s\n", app.Image, app.Version)
fmt.Printf(" ImageURL: %s\n ServiceName: %s\n\n", app.ImageURL, app.ServiceName)
}
}
clients, err := deploy.NewClient(project, region, credentialsFile)
if err != nil {
log.Fatal(err)
}
if err := clients.VerifyRepository(context.TODO(), repository); err != nil {
log.Fatal(err)
}
for _, app := range cfg.Apps {
operation, err := clients.DeployApplication(project, region, app)
if err != nil {
log.Fatal(err)
}
fmt.Println(operation)
}
}