Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ services:
- apcera/gnatsd
- dockerfile/rethinkdb
script:
- pip install fabric
- go get -t -v ./...
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- GOMAXPROCS=4 go test -v github.com/lavab/api/setup
- GOMAXPROCS=4 go test -v -covermode=count -coverprofile=coverage.out github.com/lavab/api/routes
- /var/cache/drone/bin/goveralls -coverprofile=coverage.out -service=lavadrone -repotoken $COVERALLS_TOKEN
- "if [ \"$DRONE_BRANCH\" = \"master\" ]; then export CONTAINER_NAME=api-master; export CONTAINER_PORT=10000; fi"
- "if [ \"$DRONE_BRANCH\" = \"staging\" ]; then export CONTAINER_NAME=api-staging; export CONTAINER_PORT=10001; fi"
- "if [ \"$DRONE_BRANCH\" = \"develop\" ]; then export CONTAINER_NAME=api-develop; export CONTAINER_PORT=10002; fi"
- "if [ -n \"$CONTAINER_NAME\" ]; then chmod +x ./.drone/build.sh && ./.drone/build.sh; fi"
- "if [ -n \"$CONTAINER_NAME\" ]; then ssh -p 36412 root@lisa.lavaboom.io \"/opt/deploy/$CONTAINER_NAME.sh\"; fi"
- "if [ \"$DRONE_BRANCH\" = \"master\" ]; then fab -H marge.lavaboom.io:36104 deploy; fi"
- "if [ \"$DRONE_BRANCH\" = \"staging\" ]; then fab -H lisa.lavaboom.io:36412 deploy; fi"
- "if [ \"$DRONE_BRANCH\" = \"develop\" ]; then fab -H bart.lavaboom.io:36467 deploy; fi"
notify:
slack:
- webhook_url: $$SLACK_URL
Expand Down
6 changes: 6 additions & 0 deletions env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ type Flags struct {
YubiCloudKey string

LogglyToken string

SlackURL string
SlackLevels string
SlackChannel string
SlackIcon string
SlackUsername string
}
24 changes: 24 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os, random, string
from fabric.api import run, env, cd, settings

env.key_filename = os.getenv('HOME', '/root') + '/.ssh/id_rsa'

def deploy():
branch = os.getenv('DRONE_BRANCH', 'master')
commit = os.getenv('DRONE_COMMIT', 'master')
tmp_dir = '/tmp/' + ''.join(random.choice(string.lowercase) for i in xrange(10))

run('mkdir ' + tmp_dir)
with cd(tmp_dir):
run('git clone git@github.com:lavab/api.git')
with cd('api'):
run('git checkout ' + commit)
run('docker build -t registry.lavaboom.io/lavaboom/api-' + branch + ' .')

run('git clone git@github.com:lavab/docker.git')
with settings(warn_only=True):
run('docker rm -f api-' + branch)
with cd('docker/runners'):
run('./api-' + branch + '.sh')

run('rm -r ' + tmp_dir)
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ var (
// YubiCloud params
yubiCloudID = flag.String("yubicloud_id", "", "YubiCloud API id")
yubiCloudKey = flag.String("yubicloud_key", "", "YubiCloud API key")
// Loggly URL
// loggly
logglyToken = flag.String("loggly_token", "", "Loggly token")
// etcd
etcdAddress = flag.String("etcd_address", "", "etcd peer addresses split by commas")
etcdCAFile = flag.String("etcd_ca_file", "", "etcd path to server cert's ca")
etcdCertFile = flag.String("etcd_cert_file", "", "etcd path to client cert file")
etcdKeyFile = flag.String("etcd_key_file", "", "etcd path to client key file")
etcdPath = flag.String("etcd_path", "settings/", "Path of the keys")
// slack
slackURL = flag.String("slack_url", "", "URL of the Slack Incoming webhook")
slackLevels = flag.String("slack_level", "warning", "minimal level required to have messages sent to slack")
slackChannel = flag.String("slack_channel", "#api-logs", "channel to which Slack bot will send messages")
slackIcon = flag.String("slack_icon", ":ghost:", "emoji icon of the Slack bot")
slackUsername = flag.String("slack_username", "API", "username of the Slack bot")
)

func main() {
Expand Down Expand Up @@ -103,6 +109,12 @@ func main() {
YubiCloudKey: *yubiCloudKey,

LogglyToken: *logglyToken,

SlackURL: *slackURL,
SlackLevels: *slackLevels,
SlackChannel: *slackChannel,
SlackIcon: *slackIcon,
SlackUsername: *slackUsername,
}

// Generate a mux
Expand Down
2 changes: 2 additions & 0 deletions models/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Email struct {
// Snippet string
//Preview Encrypted `json:"preview" gorethink:"preview"`

Headers []string `json:"headers" gorethink:"headers"`

// ThreadID
Thread string `json:"thread" gorethink:"thread"`

Expand Down
8 changes: 4 additions & 4 deletions routes/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func init() {

// Connect to the RethinkDB server
rdbSession, err := gorethink.Connect(gorethink.ConnectOpts{
Address: env.Config.RethinkDBAddress,
AuthKey: env.Config.RethinkDBKey,
MaxIdle: 10,
IdleTimeout: time.Second * 10,
Address: env.Config.RethinkDBAddress,
AuthKey: env.Config.RethinkDBKey,
MaxIdle: 10,
Timeout: time.Second * 10,
})
if err != nil {
panic("connecting to RethinkDB should not return an error, got " + err.Error())
Expand Down
36 changes: 32 additions & 4 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/apcera/nats"
"github.com/dancannon/gorethink"
"github.com/johntdyer/slackrus"
"github.com/pzduniak/glogrus"
"github.com/segmentio/go-loggly"
"github.com/zenazn/goji/web"
Expand Down Expand Up @@ -59,6 +60,33 @@ func PrepareMux(flags *env.Flags) *web.Mux {
})
}

if flags.SlackURL != "" {
var level []logrus.Level

switch flags.SlackLevels {
case "debug":
level = slackrus.LevelThreshold(logrus.DebugLevel)
case "error":
level = slackrus.LevelThreshold(logrus.ErrorLevel)
case "fatal":
level = slackrus.LevelThreshold(logrus.FatalLevel)
case "info":
level = slackrus.LevelThreshold(logrus.InfoLevel)
case "panic":
level = slackrus.LevelThreshold(logrus.PanicLevel)
case "warn":
level = slackrus.LevelThreshold(logrus.WarnLevel)
}

log.Hooks.Add(&slackrus.SlackrusHook{
HookURL: flags.SlackURL,
AcceptedLevels: level,
Channel: flags.SlackChannel,
IconEmoji: flags.SlackIcon,
Username: flags.SlackUsername,
})
}

// Pass it to the environment package
env.Log = log

Expand All @@ -78,10 +106,10 @@ func PrepareMux(flags *env.Flags) *web.Mux {

// Set up the database
rethinkOpts := gorethink.ConnectOpts{
Address: flags.RethinkDBAddress,
AuthKey: flags.RethinkDBKey,
MaxIdle: 10,
IdleTimeout: time.Second * 10,
Address: flags.RethinkDBAddress,
AuthKey: flags.RethinkDBKey,
MaxIdle: 10,
Timeout: time.Second * 10,
}
err = db.Setup(rethinkOpts)
if err != nil {
Expand Down