-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (88 loc) · 3.02 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
/*
Docker Compose Deployment Script for Bamboo
For more information see https://github.com/herzog31/docker-deploy-bamboo-go
*/
package main
import (
"flag"
"log"
"strings"
)
func main() {
c := new(DockerDeployClient)
flag.StringVar(&c.Mode, "mode", "DEPLOY,TEST", "Comma separated list of operations that should be executed. The following operations are available: CLEAR, DEPLOY, TEST, REMOVE.")
flag.IntVar(&c.SSHPort, "sshPort", 22, "Port for SSH authentication.")
flag.StringVar(&c.SSHUser, "sshUser", "", "Username for SSH authentication.")
flag.StringVar(&c.SSHPassword, "sshPassword", "", "Password for SSH authentication.")
flag.StringVar(&c.SSHHost, "sshHost", "", "Hostname or IP of deployment target.")
flag.StringVar(&c.ProjectName, "projectName", "", "Project name of Docker composition. Example: production")
flag.StringVar(&c.ComposeFile, "composeFile", "docker-compose.yml", "Name of Docker Compose file.")
flag.IntVar(&c.StartTime, "startTime", 10, "Time in seconds the deployment script waits for your containers to start during the TEST operation.")
flag.StringVar(&c.RemoteWorkingDir, "remoteWorkingDir", "", "Absolute path of remote working directory on the deployment target, where the build artifact is copied and executed.")
flag.StringVar(&c.LocalWorkingDir, "localWorkingDir", "", "Absolute or relative path to local working directory on the build agent, where the build artifact is stored.")
flag.StringVar(&c.LocalArtifact, "artifact", "", "Relative or absolute path to zip file that contains the composition.")
flag.IntVar(&c.ServiceDiscoveryPort, "serviceDiscoveryPort", 8080, "Port for access to the service discovery API.")
flag.BoolVar(&c.ClearVolumes, "clearVolumes", false, "Set true to clear container volumes during CLEAR and REMOVE operations.")
flag.Parse()
var err error
defer func() {
if p := recover(); p != nil {
if err = c.remoteCleanUp(); err != nil {
log.Print(err)
}
c.disconnect()
log.Fatalf("Deployment aborted: %v", p)
}
}()
if err = c.findLocalArtifact(); err != nil {
log.Fatal(err)
}
if err = c.connect(); err != nil {
log.Fatal(err)
}
if err = c.prepareRemoteWorkdir(); err != nil {
panic(err)
}
if err = c.copyArtifact(); err != nil {
panic(err)
}
if err = c.unzipArtifact(); err != nil {
panic(err)
}
if err = c.checkDockerInstallation(); err != nil {
panic(err)
}
if strings.Contains(c.Mode, "CLEAR") {
if err = c.stopComposition(); err != nil {
panic(err)
}
if err = c.removeComposition(); err != nil {
panic(err)
}
}
if strings.Contains(c.Mode, "DEPLOY") {
if err = c.buildComposition(); err != nil {
panic(err)
}
if err = c.runComposition(); err != nil {
panic(err)
}
}
if strings.Contains(c.Mode, "TEST") {
if err = c.serviceDiscoveryTest(); err != nil {
panic(err)
}
}
if strings.Contains(c.Mode, "REMOVE") {
if err = c.stopComposition(); err != nil {
panic(err)
}
if err = c.removeComposition(); err != nil {
panic(err)
}
}
if err = c.remoteCleanUp(); err != nil {
log.Fatal(err)
}
c.disconnect()
}