Skip to content

Instantly share code, notes, and snippets.

@mweagle
mweagle / main.go
Created August 26, 2016 05:11
Spartav0.8.0_buildDockerImage
// 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)
@mweagle
mweagle / main.go
Created August 26, 2016 05:07
Spartav0.8.0_sshKeyName
// 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")
@mweagle
mweagle / main.go
Last active August 26, 2016 05:06
Spartav0.8.0_newCommand
// 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)
@mweagle
mweagle / pipeline.yml
Created May 25, 2016 14:11
Concourse CI pipeline for http://gosparta.io application build
################################################################################
# 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
@mweagle
mweagle / build.groovy
Created May 22, 2016 17:23
Jenkins 2.0 build
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')
}
"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(":"),
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
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)
// 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
// 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"