Skip to content

Commit

Permalink
Merge pull request #882 from convox/20160719
Browse files Browse the repository at this point in the history
[RELEASE] 20160719
  • Loading branch information
ddollar authored Jul 20, 2016
2 parents a92dfa4 + be60236 commit 24b0c4e
Show file tree
Hide file tree
Showing 60 changed files with 3,196 additions and 294 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env
cmd/convox/convox
cmd/changes/changes
coverage.txt
tags
4 changes: 4 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fail_on_violations: true

go:
enabled: true
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
sudo: required

services:
- docker
env:
global:
- DOCKER_VERSION=1.10.1-0~trusty

branches:
except:
- "/^\\d{14}/"

language: go

go:
- 1.6.1

before_install:
- go get -u github.com/convox/version

#list docker-engine versions
- apt-cache madison docker-engine
script:
- make test

# upgrade docker-engine to specific version
- sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION}
after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
slack:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test-deps:
test:
docker info >/dev/null
go get -t ./...
env PROVIDER=test go test -v -cover ./...
env PROVIDER=test bin/test

vendor:
godep restore
Expand Down
55 changes: 45 additions & 10 deletions api/controllers/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,54 @@ func BuildLogs(ws *websocket.Conn) *httperr.Error {
}

quit := make(chan bool)
logErr := make(chan error)

go keepAlive(ws, quit)
go func() {
e := client.Logs(docker.LogsOptions{
Container: fmt.Sprintf("build-%s", build),
Follow: true,
Stdout: true,
Stderr: true,
Tail: "all",
RawTerminal: false,
OutputStream: ws,
ErrorStream: ws,
})

logErr <- e
}()

ForLoop:
for {
select {

case err = <-logErr:
break ForLoop

default:
b, err := provider.BuildGet(app, build)
if err != nil {
break ForLoop
}

err = client.Logs(docker.LogsOptions{
Container: fmt.Sprintf("build-%s", build),
Follow: true,
Stdout: true,
Stderr: true,
Tail: "all",
RawTerminal: false,
OutputStream: ws,
ErrorStream: ws,
})
switch b.Status {
case "complete":
err = nil
break ForLoop
case "error":
err = fmt.Errorf("%s build failed", app)
break ForLoop
case "failed":
err = fmt.Errorf("%s build failed", app)
break ForLoop
}

// Maybe have another case to handle a timeout? But what's a good value?
}

time.Sleep(2 * time.Second)
}

quit <- true

Expand Down
2 changes: 1 addition & 1 deletion api/models/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func (a *App) RunAttached(process, command, releaseId string, height, width int,
}

if container == nil {
return fmt.Errorf("unable to find contaier for %s", process)
return fmt.Errorf("unable to find container for %s", process)
}

ea := make([]string, 0)
Expand Down
22 changes: 22 additions & 0 deletions api/models/service-logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
)

// UpdateLogger needs an IAM role to update the lambda, therefore requires IAM capabilitites for updates
func (s *Service) UpdateLogger() (*cloudformation.UpdateStackInput, error) {
formation, err := s.Formation()
if err != nil {
return nil, err
}

req := &cloudformation.UpdateStackInput{
Capabilities: []*string{aws.String("CAPABILITY_IAM")},
StackName: aws.String(s.StackName()),
TemplateBody: aws.String(formation),
}

return req, nil
}
2 changes: 2 additions & 0 deletions api/models/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func (s *Service) Update(changes map[string]string) error {
return fmt.Errorf("can not update webhook")
case "s3", "sns", "sqs":
req, err = s.UpdateIAMService()
case "syslog":
req, err = s.UpdateLogger()
default:
req, err = s.UpdateDatastore()
}
Expand Down
192 changes: 192 additions & 0 deletions api/models/templates/service/syslog.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{{ define "service" }}
{
"AWSTemplateFormatVersion": "2010-09-09",
"Outputs": {
{{ range $k, $app := .Apps }}
"{{ upper $app.Name }}Link": {
"Value": "{{ $app.Outputs.LogGroup }}"
},
{{ end }}
"Url": {
"Value": {
"Ref": "Url"
}
}
},
"Parameters": {
"Url": {
"Description": "Syslog URL, e.g. 'tcp+tls://logs1.papertrailapp.com:11235'",
"Type": "String"
}
},
"Resources": {
{{ range $k, $app := .Apps }}
"{{ upper $app.Name }}Permission": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "Function"
},
"Principal": {
"Fn::Join": [
".",
[
"logs",
{
"Ref": "AWS::Region"
},
"amazonaws.com"
]
]
},
"SourceAccount": {
"Ref": "AWS::AccountId"
},
"SourceArn": {
"Fn::Join": [
"",
[
"arn:aws:logs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":log-group:{{ $app.Outputs.LogGroup }}:*"
]
]
}
},
"Type": "AWS::Lambda::Permission"
},
"{{ upper $app.Name }}SubscriptionFilter": {
"DependsOn": [
"{{ upper $app.Name }}Permission"
],
"Properties": {
"DestinationArn": {
"Fn::GetAtt": [
"Function",
"Arn"
]
},
"FilterPattern": "",
"LogGroupName": "{{ $app.Outputs.LogGroup }}"
},
"Type": "AWS::Logs::SubscriptionFilter"
},
{{ end }}
"Function": {
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Join": [
"-",
[
"convox",
{
"Ref": "AWS::Region"
}
]
]
},
"S3Key": "lambda/syslog.zip"
},
"Description": {
"Ref": "Url"
},
"FunctionName": {
"Ref": "AWS::StackName"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"Role",
"Arn"
]
},
"Runtime": "nodejs",
"Timeout": "25"
},
"Type": "AWS::Lambda::Function"
},
"Role": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"Path": "/",
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": [
"cloudwatch:PutMetricData",
"lambda:InvokeFunction"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:*"
},
{
"Action": [
"cloudformation:DescribeStacks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:cloudformation:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":stack/",
{
"Ref": "AWS::StackName"
},
"/*"
]
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "LambdaCloudFormationCloudWatch"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
{{ end }}
2 changes: 1 addition & 1 deletion api/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func init() {
case "test":
CurrentProvider = TestProvider
default:
die(fmt.Errorf("PROVIDER must be one of (aws)"))
die(fmt.Errorf("PROVIDER must be one of (aws, test)"))
}

if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

echo "" > coverage.txt

for d in $(find . -name '*.go' -exec dirname {} \; | sort -u); do
go test -coverprofile=profile.out -covermode=atomic $d

if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
Loading

0 comments on commit 24b0c4e

Please sign in to comment.