Skip to content

Commit

Permalink
Adding release binary upload to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
thoeni committed Sep 3, 2017
1 parent dc0688e commit c638870
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage.out
/bin
*.db
tags
.vscode
.vscode
dist
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ 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
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/hmrc-lib-upgrade-{{.OS}}-{{.Arch}}"
- 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
Expand All @@ -22,6 +22,12 @@ deploy:
file: dist/*
skip_cleanup: true
on:
repo: thoeni/hmrc-lib-upgrade
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
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/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/

0 comments on commit c638870

Please sign in to comment.