From a3122d169d8f33349e0abab63d6a669ac585b96f Mon Sep 17 00:00:00 2001 From: hunterlong Date: Sun, 29 Dec 2019 13:01:53 -0800 Subject: [PATCH] travis --- .travis.yml | 4 ++-- Makefile | 14 +++++++++++++- utils/log.go | 35 ++++++++++++++++++++++------------- utils/utils.go | 8 ++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2423e0d4..bd8fa78c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,14 +16,13 @@ services: - mongodb env: global: - - PATH=/snap/bin:$PATH + - PATH=$HOME/.local/bin:$PATH - DB_HOST=localhost - DB_USER=travis - DB_PASS= - DB_DATABASE=test - GO_ENV=test - STATPING_DIR=$GOPATH/src/github.com/hunterlong/statping - - secure: CAVxMvW04wS/APA6QGjlWjLfTx5hc+TWwCKuBkMV2MioZSQGOTQBC4nITySUwepAFY25mI8zNV5oROOKzG0FxYvr2iIqKDkTTdVF1+XS2uyHfEKlsWMPErcqkGjRksDil75Pckz15uvvOYPndetK2QiamQkSf9U8dUJgzrPuV+UOFj6RO/kkEWhzmoyTdVdwIRKmiL8jINkvvFOWCAfg3WlBmucgYHHqjqeTn1kSeUJ+DV9lF8+ENq+74GZrnsq26UtskJexywDeFhhUYjWEvOFXQ19txB/JrvdZ2KSkYeuhHr1ZxlENSpQ/rySQqBvg7+XAl1RhQlL5V7/feXA+I/COqNYG5KqbDgeSUwGkZIumz1ITi24Lz4xATG5hnuRQkOIaO8/FGHAeQxU0JcdWlzS8M5RpvpN9tT12XSFDPYswFmkO+gGSEpu+2gSEbiaX7qocLLvZiMpkQxfOmItaUW5ZMXRvTWijhQTb2nyPOQ9JEabuAtAUrCwe7Enmc8P8ZasNZaJLJO53iQ8FyzrNFyAFwY5F87OQ/v3Hnjv0ADG8fDc4VUxlj8TweuRzETT8U2hchxqnK4BON2WMSj4d1V96pDuzb5fArtq5PTbI4VB7mZPriXYZEiKdfLEIufOYhg7uKdNRekMLkuJRr+ttH0Gyb+lILzSiHMHwxOH5bfM= matrix: allow_failures: - go: master @@ -36,6 +35,7 @@ branches: install: - npm install -g sass - npm install -g newman +- pip install --user awscli - go mod vendor - make dev-deps - make install diff --git a/Makefile b/Makefile index e6b5aeff..863c1dde 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ release: dev-deps wget -O statping.gpg $(SIGN_URL) gpg --import statping.gpg make build-all + make upload_to_s3 # build and push the images to docker hub docker: docker-build-all docker-publish-all @@ -322,8 +323,18 @@ cypress-install: cypress-test: clean cypress-install cd dev/test && npm test +upload_to_s3: + aws s3 cp ./source/css $(ASSETS_BKT) --recursive --exclude "*" --include "*.css" + aws s3 cp ./source/js $(ASSETS_BKT) --recursive --exclude "*" --include "*.js" + aws s3 cp ./source/font $(ASSETS_BKT) --recursive --exclude "*" --include "*.eot" --include "*.svg" --include "*.woff" --include "*.woff2" --include "*.ttf" --include "*.css" + aws s3 cp ./source/scss $(ASSETS_BKT) --recursive --exclude "*" --include "*.scss" + +travis_s3_creds: + mkdir -p ~/.aws + echo "[default]\naws_access_key_id = ${AWS_ACCESS_KEY_ID}\naws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}" > ~/.aws/credentials + # build Statping using a travis ci trigger -travis-build: +travis-build: travis_s3_creds upload_to_s3 curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token $(TRAVIS_API)" -d $(TRAVIS_BUILD_CMD) https://api.travis-ci.com/repo/hunterlong%2Fstatping/requests curl -H "Content-Type: application/json" --data '{"docker_tag": "latest"}' -X POST $(DOCKER) @@ -365,3 +376,4 @@ heroku: heroku container:release web .PHONY: all build build-all build-alpine test-all test test-api docker +.SILENT: travis_s3_creds diff --git a/utils/log.go b/utils/log.go index 986e84ac..fa81e764 100644 --- a/utils/log.go +++ b/utils/log.go @@ -181,24 +181,33 @@ func InitLogs() error { ForceColors: true, DisableColors: false, }) - Log.AddHook(new(hook)) - Log.SetNoLock() - - if VerboseMode == 1 { - Log.SetLevel(Logger.WarnLevel) - } else if VerboseMode == 2 { - Log.SetLevel(Logger.InfoLevel) - } else if VerboseMode == 3 { - Log.SetLevel(Logger.DebugLevel) - } else { - Log.SetReportCaller(true) - Log.SetLevel(Logger.TraceLevel) - } + checkVerboseMode() LastLines = make([]*LogRow, 0) return err } +// checkVerboseMode will reset the Logging verbose setting +// statping -v 1 (only Warnings) +// statping -v 2 (Info and Warnings) +// statping -v 3 (Info, Warnings and Debug) +// statping -v 4 (Info, Warnings, Debug and Traces (SQL queries)) +func checkVerboseMode() { + switch VerboseMode { + case 1: + Log.SetLevel(Logger.WarnLevel) + case 2: + Log.SetLevel(Logger.InfoLevel) + case 3: + Log.SetLevel(Logger.DebugLevel) + case 4: + Log.SetReportCaller(true) + Log.SetLevel(Logger.TraceLevel) + default: + Log.SetLevel(Logger.InfoLevel) + } +} + // CloseLogs will close the log file correctly on shutdown func CloseLogs() { ljLogger.Rotate() diff --git a/utils/utils.go b/utils/utils.go index dd2af3f9..f628ed16 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -54,8 +54,16 @@ func init() { } Directory = dir } + // check if logs are disabled logger := os.Getenv("DISABLE_LOGS") disableLogs, _ = strconv.ParseBool(logger) + if disableLogs { + Log.Out = ioutil.Discard + return + } + Log.AddHook(new(hook)) + Log.SetNoLock() + checkVerboseMode() } // ToInt converts a int to a string