-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloudfoundry.go
More file actions
128 lines (104 loc) · 4.23 KB
/
cloudfoundry.go
File metadata and controls
128 lines (104 loc) · 4.23 KB
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
127
128
package switchblade
import (
"bytes"
"fmt"
"path/filepath"
"github.com/cloudfoundry/switchblade/internal/cloudfoundry"
)
//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface InitializePhase --name CloudFoundryInitializePhase --output fakes/cloudfoundry_initialize_phase.go
//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface DeinitializePhase --name CloudFoundryDeinitializePhase --output fakes/cloudfoundry_deinitialize_phase.go
//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface SetupPhase --name CloudFoundrySetupPhase --output fakes/cloudfoundry_setup_phase.go
//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface StagePhase --name CloudFoundryStagePhase --output fakes/cloudfoundry_stage_phase.go
//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface TeardownPhase --name CloudFoundryTeardownPhase --output fakes/cloudfoundry_teardown_phase.go
func NewCloudFoundry(initialize cloudfoundry.InitializePhase, deinitialize cloudfoundry.DeinitializePhase, setup cloudfoundry.SetupPhase, stage cloudfoundry.StagePhase, teardown cloudfoundry.TeardownPhase, workspace string, cli cloudfoundry.Executable) Platform {
return Platform{
initialize: cloudFoundryInitializeProcess{initialize: initialize},
deinitialize: cloudFoundryDeinitializeProcess{deinitialize: deinitialize},
Deploy: cloudFoundryDeployProcess{setup: setup, stage: stage, workspace: workspace, cli: cli},
Delete: cloudFoundryDeleteProcess{teardown: teardown, workspace: workspace},
}
}
type cloudFoundryInitializeProcess struct {
initialize cloudfoundry.InitializePhase
}
func (p cloudFoundryInitializeProcess) Execute(buildpacks ...Buildpack) error {
var bps []cloudfoundry.Buildpack
for _, buildpack := range buildpacks {
bps = append(bps, cloudfoundry.Buildpack{
Name: buildpack.Name,
URI: buildpack.URI,
})
}
return p.initialize.Run(bps)
}
type cloudFoundryDeinitializeProcess struct {
deinitialize cloudfoundry.DeinitializePhase
}
func (p cloudFoundryDeinitializeProcess) Execute() error {
return p.deinitialize.Run()
}
type cloudFoundryDeployProcess struct {
setup cloudfoundry.SetupPhase
stage cloudfoundry.StagePhase
workspace string
cli cloudfoundry.Executable
}
func (p cloudFoundryDeployProcess) WithBuildpacks(buildpacks ...string) DeployProcess {
p.setup = p.setup.WithBuildpacks(buildpacks...)
return p
}
func (p cloudFoundryDeployProcess) WithStack(stack string) DeployProcess {
p.setup = p.setup.WithStack(stack)
return p
}
func (p cloudFoundryDeployProcess) WithEnv(env map[string]string) DeployProcess {
p.setup = p.setup.WithEnv(env)
return p
}
func (p cloudFoundryDeployProcess) WithoutInternetAccess() DeployProcess {
p.setup = p.setup.WithoutInternetAccess()
return p
}
func (p cloudFoundryDeployProcess) WithServices(services map[string]Service) DeployProcess {
s := make(map[string]map[string]interface{})
for name, service := range services {
s[name] = service
}
p.setup = p.setup.WithServices(s)
return p
}
func (p cloudFoundryDeployProcess) WithStartCommand(command string) DeployProcess {
p.setup = p.setup.WithStartCommand(command)
return p
}
func (p cloudFoundryDeployProcess) WithHealthCheckType(healthCheckType string) DeployProcess {
p.setup = p.setup.WithHealthCheckType(healthCheckType)
return p
}
func (p cloudFoundryDeployProcess) Execute(name, source string) (Deployment, fmt.Stringer, error) {
logs := bytes.NewBuffer(nil)
home := filepath.Join(p.workspace, name)
internalURL, err := p.setup.Run(logs, home, name, source)
if err != nil {
return Deployment{}, logs, err
}
externalURL, err := p.stage.Run(logs, home, name)
if err != nil {
return Deployment{}, logs, err
}
return Deployment{
Name: name,
ExternalURL: externalURL,
InternalURL: internalURL,
platform: CloudFoundry,
workspace: home,
cfCLI: p.cli,
}, logs, nil
}
type cloudFoundryDeleteProcess struct {
teardown cloudfoundry.TeardownPhase
workspace string
}
func (p cloudFoundryDeleteProcess) Execute(name string) error {
return p.teardown.Run(filepath.Join(p.workspace, name), name)
}