This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SpartaPostBuildDockerImageHook workflow hook to build the Docker image | |
func SpartaPostBuildDockerImageHook(context map[string]interface{}, | |
serviceName string, | |
S3Bucket string, | |
buildID string, | |
awsSession *session.Session, | |
noop bool, | |
logger *logrus.Logger) error { | |
dockerServiceName := strings.ToLower(serviceName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// And add the SSHKeyName option to the provision step | |
sparta.CommandLineOptions.Provision.Flags().StringVarP(&SSHKeyName, | |
"key", | |
"k", | |
"", | |
"SSH Key Name to use for EC2 instances") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom command to startup a simple HelloWorld HTTP server | |
sqsWorkerCommand := &cobra.Command{ | |
Use: "sqsWorker", | |
Short: "Sample SQS Worker processor", | |
Long: fmt.Sprintf("Sample SQS listener"), | |
RunE: func(cmd *cobra.Command, args []string) error { | |
return sqsListener(sparta.OptionsGlobal.Logger) | |
}, | |
} | |
sparta.CommandLineOptions.Root.AddCommand(sqsWorkerCommand) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# REFERENCES | |
# ConcourseCI Docs: https://concourse.ci | |
# Concourse tutorial: https://github.com/starkandwayne/concourse-tutorial | |
# | |
# NOTES | |
# This file is a self-contained description of a Concourse CI pipeline | |
# to deploy a http://gosparta.io application. There's a couple of things to | |
# note: | |
# - The YAML uses node references so that scripts can be defined in the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
def golangExists = fileExists '/home/ec2-user/go' | |
if (!golangExists) { | |
stage "Configure Go" | |
sh('curl -vs -L https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz -o /home/ec2-user/go.linux-amd64.tar.gz') | |
sh('tar -xzf /home/ec2-user/go.linux-amd64.tar.gz -C /home/ec2-user') | |
} else { | |
sh('echo Go installed') | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"core": []iamPolicyStatement{ | |
iamPolicyStatement{ | |
Action: []string{"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents"}, | |
Effect: "Allow", | |
Resource: gocf.Join("", | |
gocf.String("arn:aws:logs:"), | |
gocf.Ref("AWS::Region"), | |
gocf.String(":"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var req = http.request(options, function(res) { | |
res.setEncoding('utf8'); | |
var body = ''; | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
// Bridge the NodeJS and golang worlds by including the golang | |
// HTTP status text in the error response if appropriate. This enables | |
// the API Gateway integration response to use standard golang StatusText regexp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (handler *LambdaHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
// Remove the leading slash and dispatch it to the golang handler | |
lambdaFunc := strings.TrimLeft(req.URL.Path, "/") | |
decoder := json.NewDecoder(req.Body) | |
var request lambdaRequest | |
defer func() { | |
if r := recover(); r != nil { | |
err, ok := r.(error) | |
if !ok { | |
err = fmt.Errorf("%v", r) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return a string representation of a JS function call that can be exposed | |
// to AWS Lambda | |
func createNewNodeJSProxyEntry(lambdaInfo *LambdaAWSInfo, logger *logrus.Logger) string { | |
logger.WithFields(logrus.Fields{ | |
"FunctionName": lambdaInfo.lambdaFnName, | |
}).Info("Registering Sparta function") | |
// We do know the CF resource name here - could write this into | |
// index.js and expose a GET localhost:9000/lambdaMetadata | |
// which wraps up DescribeStackResource for the running |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the string literal adapter, which requires us to add exported | |
// functions to the end of index.js. These NodeJS exports will be | |
// linked to the AWS Lambda NodeJS function name, and are basically | |
// automatically generated pass through proxies to the golang HTTP handler. | |
nodeJSWriter, err := lambdaArchive.Create("index.js") | |
if err != nil { | |
return nil, errors.New("Failed to create ZIP entry: index.js") | |
} | |
nodeJSSource := _escFSMustString(false, "/resources/index.js") | |
nodeJSSource += "\n// DO NOT EDIT - CONTENT UNTIL EOF IS AUTOMATICALLY GENERATED\n" |