-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
84 lines (75 loc) · 2.52 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
package main
import (
"fmt"
"os"
sparta "github.com/mweagle/Sparta"
"github.com/mweagle/SpartaCodePipeline/pipeline"
"github.com/spf13/cobra"
"gopkg.in/go-playground/validator.v9"
)
// PipelineName is the name of the stack to provision that supports the pipeline
var pipelineOptions pipeline.ProvisionOptions
func init() {
sparta.RegisterCodePipelineEnvironment("test", map[string]string{
"MESSAGE": "Hello Test!",
"ENVIRONMENT": "test",
})
sparta.RegisterCodePipelineEnvironment("production", map[string]string{
"MESSAGE": "Hello Production!",
"ENVIRONMENT": "prod",
})
}
// Standard AWS Lambda function
func helloSpartaWorld() (string, error) {
messageText := os.Getenv("MESSAGE")
if "" == messageText {
messageText = "$MESSAGE not defined"
}
return messageText, nil
}
////////////////////////////////////////////////////////////////////////////////
// Add a command to provision a CI pipeline
var pipelineProvisionCommand = &cobra.Command{
Use: "provisionPipeline",
Short: "Provision a CI/CD pipeline for this stack",
RunE: func(cmd *cobra.Command, args []string) error {
validate := validator.New()
cliErrors := validate.Struct(&pipelineOptions)
if cliErrors != nil {
return cliErrors
}
return pipeline.Provision(&pipelineOptions)
},
}
////////////////////////////////////////////////////////////////////////////////
// Main
func main() {
// Register the provisionPipeline command
pipelineProvisionCommand.PersistentFlags().StringVarP(&pipelineOptions.PipelineName, "pipeline", "p", "", "pipeline name")
pipelineProvisionCommand.PersistentFlags().StringVarP(&pipelineOptions.GithubRepo, "repo", "r", "", "GitHub Repo URL")
pipelineProvisionCommand.PersistentFlags().StringVarP(&pipelineOptions.GithubOAuthToken, "oauth", "o", "", "GitHub OAuth token")
pipelineProvisionCommand.PersistentFlags().StringVarP(&pipelineOptions.S3Bucket,
"s3Bucket",
"s",
"",
"S3 Bucket to use for Lambda source")
pipelineProvisionCommand.PersistentFlags().BoolVarP(&pipelineOptions.Noop, "noop",
"n",
false,
"Dry-run behavior only (do not perform mutations)")
sparta.CommandLineOptions.Root.AddCommand(pipelineProvisionCommand)
// Normal execution
lambdaFn := sparta.HandleAWSLambda("HelloWorld",
helloSpartaWorld,
sparta.IAMRoleDefinition{})
var lambdaFunctions []*sparta.LambdaAWSInfo
lambdaFunctions = append(lambdaFunctions, lambdaFn)
err := sparta.Main("SpartaCodePipeline",
fmt.Sprintf("SpartaCodePipeline CodePipeline example"),
lambdaFunctions,
nil,
nil)
if err != nil {
os.Exit(1)
}
}