You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
devCmdUp.Flags().Int32Var(¶ms.ServiceMonitorPort, "service-monitor-port", params.ServiceMonitorPort, "Set Service port to scrape in ServiceMonitor.")
52
67
devCmdUp.Flags().StringVar(¶ms.ServiceMonitorOperatorName, "service-monitor-operator-name", params.ServiceMonitorOperatorName, "Name of prometheus-operator instance to create ServiceMonitor for.")
53
68
54
-
55
69
devCmd.AddCommand(devCmdDown)
56
70
devCmdDown.Flags().StringVarP(¶ms.NameSpace, "namespace", "n", "", "namespace to work on, if not supplied it will use current active namespace.")
57
71
devCmdDown.Flags().BoolVar(¶ms.Everything, "everything", false, "Delete all resources and artifacts generated from mg dev up.")
@@ -61,6 +75,11 @@ func init() {
61
75
devCmdBuild.Flags().StringVar(¶ms.SourceRef, "ref", "master", "Specify the git ref or branch ref to build.")
62
76
devCmdBuild.Flags().StringVarP(¶ms.NameSpace, "namespace", "n", "", "namespace to work on, if not supplied it will use current active namespace.")
63
77
devCmdBuild.Flags().BoolVar(¶ms.LocalBuild, "local", false, "Builds application from src in current (.) direcotry.")
78
+
79
+
devCmd.AddCommand(devCmdWatch)
80
+
devCmdWatch.Flags().StringVarP(¶ms.NameSpace, "namespace", "n", "", "namespace to work on, if not supplied it will use current active namespace.")
81
+
devCmdWatch.Flags().StringSliceVar(&CVars, "cvars", []string{}, "Slice of key=value pairs, seperated by ,")
82
+
devCmdWatch.Flags().StringVar(¶ms.PropertiesFile, "cvfile", "", "Property file with component configuration values. Can be generated with \"mg generate properties\" command.)")
64
83
}
65
84
66
85
vardevCmd=&cobra.Command{
@@ -69,6 +88,51 @@ var devCmd = &cobra.Command{
69
88
Long: `dev subcommands`,
70
89
}
71
90
91
+
vardevCmdWatch=&cobra.Command{
92
+
Use: "watch <metagraf.json>",
93
+
Short: "watches for local filechanges and rebuilds or redeploys the component.",
94
+
Long: `Inspired by skaffold.dev. Watches for local file changes and rebuilds and redeploys.`,
95
+
Run: func(cmd*cobra.Command, args []string) {
96
+
requireMetagraf(args)
97
+
requireNamespace()
98
+
99
+
mg:=metagraf.Parse(args[0])
100
+
bc:=mg.Name(OName, Version)
101
+
102
+
FlagPassingHack()
103
+
modules.NameSpace=params.NameSpace
104
+
105
+
// Crate a buffered channel with room for one event.
106
+
chEvents:=make(chanWatchEvent, 1)
107
+
// Channel to indicate if we are in processing state.
108
+
chProcessing:=make(chanbool, 1)
109
+
110
+
wg.Add(2)
111
+
112
+
gofilteredFileWatcher(chEvents, chProcessing)
113
+
114
+
for {
115
+
select {
116
+
casecommand:=<-chEvents:
117
+
chProcessing<-true
118
+
switchcommand {
119
+
caseBuildAndDeploy:
120
+
buildGenerate(&mg, params.NameSpace, true)
121
+
err:=s2ibuild(bc, params.NameSpace, true)
122
+
iferr!=nil {
123
+
log.Fatalf("Unable to build: %v ", err)
124
+
}
125
+
devUp(args[0])
126
+
caseDeploy:
127
+
devUp(args[0])
128
+
}
129
+
chProcessing<-false
130
+
}
131
+
}
132
+
wg.Wait()
133
+
},
134
+
}
135
+
72
136
vardevCmdUp=&cobra.Command{
73
137
Use: "up <metagraf.json>",
74
138
Short: "creates the required component resources.",
@@ -113,36 +177,12 @@ var devCmdBuild = &cobra.Command{
113
177
FlagPassingHack()
114
178
modules.NameSpace=params.NameSpace
115
179
116
-
// Remove RepSecRef from generated BuildConfig if --local argument is provided.
0 commit comments