-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TravisCI integration: Build and Push, both Executable and Docker Image
* Added docker build, executable build, docker push, executable push. * Ensured push only happened for tagged builds or personal machine builds. * Ensured Fork PRs do not get pushed. Rebased and Modified from work of @rtluckie - #69 - add docker-login make target - add docker-build-clean make target - use cache image for docker-build make target - add docker-push make target - add build-dist-push make target - split compilation steps in Dockerfile into discrete layers
- Loading branch information
1 parent
35885b9
commit f618831
Showing
3 changed files
with
169 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
sudo: required | ||
language: go | ||
go: '1.10.3' | ||
go_import_path: github.com/cisco-sso/kdk | ||
services: | ||
- docker | ||
script: | ||
- make ci | ||
deploy: | ||
- provider: script | ||
skip_cleanup: true | ||
script: make ci | ||
on: | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
checks() { | ||
if ! which git &>/dev/null; then | ||
echo "You must install Git" | ||
return 1 | ||
fi | ||
if ! which go &>/dev/null; then | ||
echo "You must install Go" | ||
return 1 | ||
fi | ||
if ! which docker &>/dev/null; then | ||
echo "You must install Docker" | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
deps() { | ||
if ! which dep &>/dev/null; then | ||
go get -u github.com/golang/dep/cmd/dep | ||
fi | ||
if ! which gox &>/dev/null; then | ||
go get -u github.com/mitchellh/gox | ||
fi | ||
if ! which goreleaser &>/dev/null; then | ||
go get -u github.com/goreleaser/goreleaser | ||
fi | ||
|
||
dep ensure | ||
} | ||
|
||
publish?() { | ||
# Figure out whether to release the docker image and executable binary | ||
# The lack of setting PUBLISH to anything means its undefined | ||
|
||
tag_of_current_commit="$(git describe --exact-match --tags HEAD || true)" | ||
latest_tag_in_repo="$(git describe --tags | cut -d '-' -f1)" | ||
if [ "$tag_of_current_commit" != "$latest_tag_in_repo" ]; then | ||
echo "Not publishing because current HEAD is not equal to the latest tag" >&2 | ||
echo false | ||
return 1 | ||
fi | ||
if [[ -z ${DOCKER_USERNAME+x} ]]; then | ||
echo "Not publishing because DOCKER_USERNAME is unset" >&2 | ||
echo false | ||
return 1 | ||
fi | ||
if [[ -z ${DOCKER_PASSWORD+x} ]]; then | ||
echo "Not publishing because DOCKER_USERNAME is unset" >&2 | ||
echo false | ||
return 1 | ||
fi | ||
if [[ ! -z ${TRAVIS_TAG+x} ]]; then | ||
echo "Publish because we are building a Tag on TravisCI" >&2 | ||
echo true | ||
return 0 | ||
fi | ||
if [[ -z ${CI+x} ]]; then | ||
echo "Publish because we are building on a local machine" >&2 | ||
echo true | ||
return 0 | ||
fi | ||
|
||
echo "Not publishing because of unmet conditions" >&2 | ||
echo false | ||
return 1 | ||
} | ||
|
||
version() { | ||
echo $(git describe --tags --long --dirty | sed 's/-0-........$$//;') | ||
} | ||
|
||
case "$1" in | ||
checks) | ||
checks | ||
;; | ||
deps) | ||
deps | ||
;; | ||
publish?) | ||
publish? | ||
;; | ||
version) | ||
version | ||
;; | ||
*) | ||
echo $"Usage: $0 {checks|deps|publish?|version}" | ||
exit 1 | ||
esac |