File tree Expand file tree Collapse file tree 7 files changed +126
-13
lines changed
Expand file tree Collapse file tree 7 files changed +126
-13
lines changed Original file line number Diff line number Diff line change 11package main
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "./sync"
6+ )
47
58type DeployCommand struct {
69 AbstractCommand
710 Positional struct {
811 Server string `description:"server configuration key"`
912 } `positional-args:"true"`
10- Dump bool `long:"dump" description:"dump configuration as yaml"`
13+ Dump bool `long:"dump" description:"dump configuration as yaml"`
14+ OnlyFilesystem bool `long:"filesystem" description:"deploy only filesystem"`
15+ OnlyDatabase bool `long:"database" description:"deploy only database"`
16+ SkipExec bool `long:"skip-exec" description:"skip execution"`
1117}
1218
1319// Run deployment command
@@ -21,6 +27,8 @@ func (command *DeployCommand) Execute(args []string) error {
2127 Logger .Step ("using Server[%s]" , server )
2228 Logger .Step ("using %s" , confServer .Connection .GetInstance ().String ())
2329
30+ confServer .SetRunConfiguration (command .buildSyncRunConfig ())
31+
2432 // --dump
2533 if command .Dump {
2634 fmt .Println ()
@@ -32,3 +40,26 @@ func (command *DeployCommand) Execute(args []string) error {
3240
3341 return nil
3442}
43+
44+ func (command * DeployCommand ) buildSyncRunConfig () (conf sync.RunConfiguration ) {
45+ // Init
46+ conf .Exec = true
47+ conf .Database = true
48+ conf .Filesystem = true
49+
50+ if command .OnlyFilesystem {
51+ conf .Database = false
52+ conf .Filesystem = true
53+ }
54+
55+ if command .OnlyDatabase {
56+ conf .Database = true
57+ conf .Filesystem = false
58+ }
59+
60+ if command .SkipExec {
61+ conf .Exec = false
62+ }
63+
64+ return
65+ }
Original file line number Diff line number Diff line change 11package main
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "./sync"
6+ )
47
58type SyncCommand struct {
69 AbstractCommand
710 Positional struct {
811 Server string `description:"server configuration key"`
912 } `positional-args:"true"`
10- Dump bool `long:"dump" description:"dump configuration as yaml"`
13+ Dump bool `long:"dump" description:"dump configuration as yaml"`
14+ OnlyFilesystem bool `long:"filesystem" description:"sync only filesystem"`
15+ OnlyDatabase bool `long:"database" description:"sync only database"`
16+ SkipExec bool `long:"skip-exec" description:"skip execution"`
1117}
1218
1319// Run sync command
@@ -21,6 +27,8 @@ func (command *SyncCommand) Execute(args []string) error {
2127 Logger .Step ("using Server[%s]" , server )
2228 Logger .Step ("using %s" , confServer .Connection .GetInstance ().String ())
2329
30+ confServer .SetRunConfiguration (command .buildSyncRunConfig ())
31+
2432 // --dump
2533 if command .Dump {
2634 fmt .Println ()
@@ -32,3 +40,26 @@ func (command *SyncCommand) Execute(args []string) error {
3240
3341 return nil
3442}
43+
44+ func (command * SyncCommand ) buildSyncRunConfig () (conf sync.RunConfiguration ) {
45+ // Init
46+ conf .Exec = true
47+ conf .Database = true
48+ conf .Filesystem = true
49+
50+ if command .OnlyFilesystem {
51+ conf .Database = false
52+ conf .Filesystem = true
53+ }
54+
55+ if command .OnlyDatabase {
56+ conf .Database = true
57+ conf .Filesystem = false
58+ }
59+
60+ if command .SkipExec {
61+ conf .Exec = false
62+ }
63+
64+ return
65+ }
Original file line number Diff line number Diff line change @@ -82,9 +82,17 @@ type Server struct {
8282 Database []Database `yaml:"database"`
8383 ExecStartup []Execution `yaml:"exec-startup"`
8484 ExecFinish []Execution `yaml:"exec-finish"`
85+
86+ runConfiguration * RunConfiguration
8587}
8688
8789type SyncConfig struct {
8890 Sync map [string ]Server `yaml:"sync"`
8991 Deploy map [string ]Server `yaml:"deploy"`
9092}
93+
94+ type RunConfiguration struct {
95+ Database bool
96+ Filesystem bool
97+ Exec bool
98+ }
Original file line number Diff line number Diff line change 11package sync
22
3- import "gopkg.in/yaml.v2"
3+ import (
4+ "gopkg.in/yaml.v2"
5+ )
6+
7+ func (server * Server ) Init () {
8+ if server .runConfiguration == nil {
9+ server .runConfiguration = & RunConfiguration {
10+ Database : true ,
11+ Filesystem : true ,
12+ }
13+ }
14+ }
415
516func (server * Server ) GetLocalPath () string {
617 if server .Path == "" {
@@ -10,6 +21,10 @@ func (server *Server) GetLocalPath() string {
1021 return server .Path
1122}
1223
24+ func (server * Server ) SetRunConfiguration (conf RunConfiguration ) {
25+ server .runConfiguration = & conf
26+ }
27+
1328func (server * Server ) AsYaml () string {
1429 conf , _ := yaml .Marshal (server )
1530 return string (conf )
Original file line number Diff line number Diff line change @@ -6,10 +6,23 @@ func (server *Server) Deploy() {
66 ShellErrorHandler (recover )
77 }()
88
9- server .RunExec ("startup" )
10- server .DeployFilesystem ()
11- server .DeployDatabases ()
12- server .RunExec ("finish" )
9+ server .Init ()
10+
11+ if server .runConfiguration .Exec {
12+ server .RunExec ("startup" )
13+ }
14+
15+ if server .runConfiguration .Filesystem {
16+ server .DeployFilesystem ()
17+ }
18+
19+ if server .runConfiguration .Database {
20+ server .DeployDatabases ()
21+ }
22+
23+ if server .runConfiguration .Exec {
24+ server .RunExec ("finish" )
25+ }
1326
1427 waitGroup .Wait ()
1528}
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ func (server *Server) RunExec(when string) {
88 ShellErrorHandler (recover )
99 }()
1010
11+ server .Init ()
12+
1113 execList := server .GetExecByWhen (when )
1214
1315 if len (execList ) >= 1 {
Original file line number Diff line number Diff line change @@ -6,10 +6,23 @@ func (server *Server) Sync() {
66 ShellErrorHandler (recover )
77 }()
88
9- server .RunExec ("startup" )
10- server .SyncFilesystem ()
11- server .SyncDatabases ()
12- server .RunExec ("finish" )
9+ server .Init ()
10+
11+ if server .runConfiguration .Exec {
12+ server .RunExec ("startup" )
13+ }
14+
15+ if server .runConfiguration .Filesystem {
16+ server .SyncFilesystem ()
17+ }
18+
19+ if server .runConfiguration .Database {
20+ server .SyncDatabases ()
21+ }
22+
23+ if server .runConfiguration .Exec {
24+ server .RunExec ("finish" )
25+ }
1326
1427 waitGroup .Wait ()
1528}
You can’t perform that action at this time.
0 commit comments