Skip to content

Commit

Permalink
Use TravisCI publish/deploy decision mechanism
Browse files Browse the repository at this point in the history
* And thus remove the one that we coded
  • Loading branch information
dcwangmit01 authored and Joshua Dotson committed Sep 20, 2018
1 parent 195c85a commit cf30b5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
19 changes: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ LDFLAGS += -extldflags "-static"
# Required for globs to work correctly
SHELL=/bin/bash

PUBLISH := $(shell ./scripts/cicd.sh publish?)

#####################################################################

.PHONY: checks check-go check-docker deps gofmt \
.PHONY: checks check-go check-docker check-publish deps gofmt \
ci build build-cross \
docker-build docker-push \
bin-build bin-push \
Expand All @@ -42,6 +40,9 @@ check-go: ## Check the system for go builds
check-docker: ## Check the system for docker builds
./scripts/cicd.sh check-docker

check-publish: ## Check ENV vars set for push to docker and github
./scripts/cicd.sh check-publish

deps: ## Ensure dependencies are installed
./scripts/cicd.sh deps

Expand Down Expand Up @@ -104,8 +105,7 @@ docker-build: check-docker ## Build the docker image



docker-push: check-docker ## Publish the docker image
ifeq ($(PUBLISH),true)
docker-push: check-publish check-docker ## Publish the docker image
@echo "Executing docker push for build"
echo "$${DOCKER_PASSWORD}" | docker login -u "$${DOCKER_USERNAME}" --password-stdin

Expand All @@ -115,21 +115,14 @@ ifeq ($(PUBLISH),true)
docker push $(BASE_IMAGE):build-cache-multistage-goinstall
docker push $(BASE_IMAGE):latest
docker push $(NEW_IMAGE_TAG)
else
@echo "Skipping docker push"
endif

bin-build: build-cross ## Build the binary executable

bin-push: check-go deps # Publish the binary executable
ifeq ($(PUBLISH),true)
bin-push: check-publish check-go deps # Publish the binary executable
@echo "Executing bin push for build"
git status
git reset --hard HEAD
goreleaser --rm-dist --debug
else
@echo "Skipping bin push"
endif

clean: ## Clean up the build dirs
@rm -rf $(BINDIR) ./_dist ./bin vendor .vendor-new .venv
Expand Down
38 changes: 19 additions & 19 deletions scripts/cicd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@ check-docker() {
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?() {
check-publish() {
# Figure out whether to release the docker image and executable binary
# The lack of setting PUBLISH to anything means its undefined

Expand Down Expand Up @@ -71,6 +57,20 @@ publish?() {
return 1
}

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
}

version() {
echo $(git describe --tags --long --dirty | sed 's/-0-........$//;')
}
Expand All @@ -86,16 +86,16 @@ case "$1" in
check-docker)
check-docker
;;
check-publish)
check-publish
;;
deps)
deps
;;
publish?)
publish?
;;
version)
version
;;
*)
echo $"Usage: $0 {checks|check-go|check-docker|deps|publish?|version}"
echo $"Usage: $0 {checks|check-go|check-docker|check-publish|deps|version}"
exit 1
esac

0 comments on commit cf30b5d

Please sign in to comment.