Skip to content

Commit

Permalink
Enable publish to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
thoeni committed Sep 3, 2017
1 parent 22e0438 commit 21ed38c
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
slack-tube-service
vendor/
.idea/*
tokens.txt
coverage.out
/bin
*.db
tags
.vscode
.vscode
dist
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language: go
go:
- master
install:
- go get -t -d -v ./...
sudo: required
before_script:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
script: go test -v ./... -covermode=count -coverprofile=coverage.out
after_script:
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
before_deploy:
- go get github.com/mitchellh/gox
- gox -ldflags "-X main.AppVersion=$TRAVIS_TAG -X main.Sha=$TRAVIS_COMMIT" -output "dist/slack-tube-service-{{.OS}}-{{.Arch}}"
- sudo chmod +x ./dist/*
deploy:
provider: releases
api_key:
secure: USgcg/9s83bKhyi/Rpe6PG5YuyEROmhQz/lBffhGiggxsau6j+lfxFQYyIKXq4tbVLZ2xUqpS/+8rT9vIrvdQCsqZts7aa4VHSHq/t56ASQcfOhXhUjV7u3VVElZnCzwTp08Ib0Voq6nerjRUGsAcwZtc5u7Ix/HO4Ly7+CsyGKHVmHxb1WSWnzF2nbV2MCjs2cP39Im2/BZmmMfgdaFWqHl+m6qz83Zb3DMVGUDQyuqWVoyyUHiFJih8wZ5GymbcC1C0ozN0QMRWOXYpoBQnkr4uL0VyPadt925F7QO2zyK+3sg3SFZRa9SoGeUB8PqvRZcOj+R/CfDjK+mu3dMtJ5Sb+DKlSdbccHVW8RWnB/6CrM/sr+SY9no0TLLA5VVbX3dV2VKxmKms7wKEelfZm2hGtTKbnxbbTs8NpH7LSCcfcUN966J3zcCf5mtDd1pmTntFyCuumr+t2H9AmCVHm9tmb741SRFdD6jzsuRylHjvXuL5h4/ZvGLeyVH4beK/R5xQGxJKIVcf4hQ8fufTUsIgPwKkEVyiUneOOODzX9NN9sguaNfhDhQ6lfJu2I8OBsSVyvoptsPb3gmotzz8+r9/rxceoo9K2t4NJBJHLchn3WPmkgHyC68dQPU4qZ9ET2GHEaEtLc+9Hk9yO0CvOu/G8MtvWtKDI5VDlpY70U=
file_glob: true
file: dist/*
skip_cleanup: true
on:
repo: thoeni/slack-tube-service
tags: true
condition: "$TRAVIS_TAG =~ ^v[0-9]+(.[0-9]+)*"
deploy:
provider: script
script: deploy_prod.sh
on:
repo: thoeni/slack-tube-service
branch: master
141 changes: 141 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.10.26"

[[constraint]]
name = "github.com/boltdb/bolt"
version = "1.3.1"

[[constraint]]
name = "github.com/golang/mock"
version = "1.0.0"

[[constraint]]
name = "github.com/gorilla/mux"
version = "1.4.0"

[[constraint]]
branch = "master"
name = "github.com/gorilla/schema"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"

[[constraint]]
name = "github.com/rs/cors"
version = "1.2.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"

[[constraint]]
branch = "master"
name = "github.com/thoeni/go-tfl"
11 changes: 7 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ test:
- go test -v -covermode=count -coverprofile=coverage.out
post:
- goveralls -coverprofile=coverage.out -service=circle-ci -repotoken $COVERALLS_REPO_TOKEN

deployment:
production:
branch: master
release:
tag: /^v[0-9]+(.[0-9]+)*/
commands:
- ./deploy_prod.sh
- go get github.com/mitchellh/gox
- go get github.com/tcnksm/ghr
- gox -osarch "linux/386 linux/amd64 windows/386 windows/amd64 darwin/386 darwin/amd64" -ldflags "-X main.AppVersion=$CIRCLE_TAG -X main.Sha=$CIRCLE_SHA1" -output "./dist/slack-tube-service-{{.OS}}-{{.Arch}}"
- ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME --replace ${CIRCLE_TAG} ./dist/
- sh deploy_prod.sh
2 changes: 1 addition & 1 deletion deploy_prod.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
ssh ec2-user@services.thoeni.io 'pkill -f slack-tube-service'
./mkbin.sh linux
scp bin/slack-tube-service-linux-amd64 ec2-user@services.thoeni.io:~/
scp dist/slack-tube-service-linux-amd64 ec2-user@services.thoeni.io:~/
ssh ec2-user@services.thoeni.io screen -d -m './slack-tube-service-linux-amd64 &'
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"time"

"flag"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
Expand All @@ -20,6 +21,8 @@ var tokenStore Repository
var svc *dynamodb.DynamoDB

var listenPort = os.Getenv("PORT")
var AppVersion string
var Sha string

const defaultPort = "1123"

Expand Down Expand Up @@ -56,7 +59,7 @@ var (

var tubeService TflService = TubeService{tfl.NewCachedClient(120)}

func init() {
func initialise() {

if listenPort == "" {
listenPort = defaultPort
Expand All @@ -65,9 +68,9 @@ func init() {
err := dbInit()
if err != nil {
log.Fatal("Couldn't initialise DB", err)
} else {
fmt.Printf("BoltDB initiliased (%v), bucket created!\n", tokenStore)
return
}
fmt.Printf("BoltDB initiliased (%v), bucket created!\n", tokenStore)

// DynamoDB
sess := session.Must(session.NewSession())
Expand All @@ -81,6 +84,14 @@ func init() {

func main() {

printVersion := flag.Bool("version", false, "Prints the version of this application")
flag.Parse()
if *printVersion {
fmt.Printf("Current version is: %s\nGit commit: %s", AppVersion, Sha)
return
}

initialise()
defer tokenStore.Close()

_, authorisedTokenSet = tokenStore.RetrieveAllTokens()
Expand Down
10 changes: 6 additions & 4 deletions mkbin.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash
BUILD_VERSION=$(git describe --tags --always)
CID=$(git log --format="%H" -n 1)
if [ "$1" = "linux" ] || [ "$1" = "" ]; then
echo "Generating Linux binary"
env GOOS=linux GOARCH=amd64 go build -o bin/slack-tube-service-linux-amd64
env GOOS=linux GOARCH=amd64 go build -ldflags "-X main.AppVersion=$BUILD_VERSION -X main.Sha=$CID" -o dist/slack-tube-service-$BUILD_VERSION-linux-amd64
fi
if [ "$1" = "windows" ] || [ "$1" = "" ]; then
echo "Generating Windows binary"
env GOOS=windows GOARCH=amd64 go build -o bin/slack-tube-service.exe
env GOOS=windows GOARCH=amd64 go build -ldflags "-X main.AppVersion=$BUILD_VERSION -X main.Sha=$CID" -o dist/slack-tube-service-$BUILD_VERSION-windows-amd64.exe
fi
if [ "$1" = "mac" ] || [ "$1" = "" ]; then
echo "Generating MacOS binary"
env GOOS=darwin GOARCH=amd64 go build -o bin/slack-tube-service-darwin
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.AppVersion=$BUILD_VERSION -X main.Sha=$CID" -o dist/slack-tube-service-$BUILD_VERSION-darwin-amd64
fi
echo "Done!"
ls -al bin/
ls -al dist/
8 changes: 4 additions & 4 deletions tfl-service.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/thoeni/go-tfl"
"strings"
"time"

"github.com/thoeni/go-tfl"
)

type TflService interface {
Expand All @@ -28,10 +29,9 @@ func (s TubeService) GetStatusFor(lines []string) (map[string]tfl.Report, error)
reportsMap := tfl.ReportArrayToMap(reports)
if len(lines) == 0 {
return reportsMap, nil
} else {
filteredReportsMap := filter(reportsMap, lines)
return filteredReportsMap, nil
}
filteredReportsMap := filter(reportsMap, lines)
return filteredReportsMap, nil
}

func filter(reportsMap map[string]tfl.Report, lines []string) map[string]tfl.Report {
Expand Down

0 comments on commit 21ed38c

Please sign in to comment.