-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
126 lines (111 loc) · 3.6 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
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
/**
* Copyright 2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package main
import (
"fmt"
"os"
"github.com/silogen/cluster-forge/cmd/caster"
"github.com/silogen/cluster-forge/cmd/forger"
"github.com/silogen/cluster-forge/cmd/smelter"
"github.com/silogen/cluster-forge/cmd/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func main() {
var rootCmd = &cobra.Command{Use: "app"}
var smeltCmd = &cobra.Command{
Use: "smelt",
Short: "Run smelt",
Long: `The smelt command processes the input configuration and performs the smelting operation.
It reads the configuration from the input directory and generates normalized yaml in the working directory.
This output can then be edited or customized if needed before casting.
The reason for customizing is to create cluster specific configurations.
For example, you could template a 'baseDomain' which could then be input and templated at the forge step.`,
Run: func(cmd *cobra.Command, args []string) {
runSmelt()
},
}
var castCmd = &cobra.Command{
Use: "cast",
Short: "Run cast",
Long: `The cast command processes the normalized (and possibly custom templated) yaml from the working directory and performs the casting operation.
This step creates a container image which can be used during forge step to deploy all the components in a stack to a cluster.`,
Run: func(cmd *cobra.Command, args []string) {
runCast()
},
}
var forgeCmd = &cobra.Command{
Use: "forge",
Short: "Run forge",
Long: `The forge command deploys a stack from the cast phase into a cluster.
It reads the KUBECONFIG env variable to find a destination, and deploys the stack.`,
Run: func(cmd *cobra.Command, args []string) {
runForge()
},
}
rootCmd.AddCommand(smeltCmd, castCmd, forgeCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func runSmelt() {
workingDir := "./working"
utils.Setup()
log.Println("starting up...")
configs, err := utils.LoadConfig("input/config.yaml")
if err != nil {
log.Fatalf("Failed to read config: %v", err)
}
for _, config := range configs {
log.Printf("Read config for : %+v", config.Name)
}
fmt.Print(utils.ForgeLogo)
fmt.Println("Smelting")
smelter.Smelt(configs, workingDir)
}
func runCast() {
workingDir := "./working"
stacksDir := "./stacks"
filesDir := "./output"
utils.Setup()
log.Println("starting up...")
configs, err := utils.LoadConfig("input/config.yaml")
if err != nil {
log.Fatalf("Failed to read config: %v", err)
}
for _, config := range configs {
log.Printf("Read config for : %+v", config.Name)
}
fmt.Print(utils.ForgeLogo)
fmt.Println("Casting")
caster.Cast(configs, filesDir, workingDir, stacksDir)
}
func runForge() {
stacksDir := "./stacks"
utils.Setup()
log.Println("starting up...")
configs, err := utils.LoadConfig("input/config.yaml")
if err != nil {
log.Fatalf("Failed to read config: %v", err)
}
for _, config := range configs {
log.Printf("Read config for : %+v", config.Name)
}
fmt.Print(utils.ForgeLogo)
fmt.Println("Forging")
forger.Forge(stacksDir)
}