Skip to content

Commit

Permalink
tooling unification
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Oct 16, 2018
1 parent 0330adf commit 4a80b8f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
43 changes: 30 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION ?= $(shell git describe --always --abbrev=7)
MUTABLE_TAG ?= latest
IMAGE = origin-libvirt-machine-controllers

.PHONY: all
all: generate build images
all: generate build images check

NO_DOCKER ?= 0
ifeq ($(NO_DOCKER), 1)
DOCKER_CMD =
IMAGE_BUILD_CMD = imagebuilder
CGO_ENABLED = 1
else
DOCKER_CMD := docker run --rm -e CGO_ENABLED=1 -v "$(PWD)":/go/src/sigs.k8s.io/cluster-api-provider-aws:Z -w /go/src/sigs.k8s.io/cluster-api-provider-aws openshift/origin-release:golang-1.10
IMAGE_BUILD_CMD = docker build
endif

.PHONY: depend
depend:
Expand Down Expand Up @@ -46,37 +60,40 @@ generate-mocks:
go build -o $$GOPATH/bin/mockgen sigs.k8s.io/cluster-api-provider-aws/vendor/github.com/golang/mock/mockgen/
go generate ./cloud/aws/client/

build:
CGO_ENABLED=0 go install -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller
CGO_ENABLED=0 go install -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller
bin:
@mkdir $@

.PHONY: build
build: | bin ## build binary
$(DOCKER_CMD) go install -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller
$(DOCKER_CMD) go install -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller

aws-actuator:
go build -o bin/aws-actuator sigs.k8s.io/cluster-api-provider-aws/cmd/aws-actuator
$(DOCKER_CMD) go build -o bin/aws-actuator sigs.k8s.io/cluster-api-provider-aws/cmd/aws-actuator

.PHONY: images
images: ## Create images
#$(MAKE) -C cmd/cluster-controller image
$(MAKE) -C cmd/machine-controller image
$(IMAGE_BUILD_CMD) -t "$(IMAGE):$(VERSION)" -t "$(IMAGE):$(MUTABLE_TAG)" ./

.PHONY: push
push:
$(MAKE) -C cmd/cluster-controller push
$(MAKE) -C cmd/machine-controller push
docker push "$(IMAGE):$(VERSION)"
docker push "$(IMAGE):$(MUTABLE_TAG)"

.PHONY: check
check: fmt vet lint test ## Check your code

.PHONY: unit
unit: # Run unit test
go test -race -cover ./cmd/... ./cloud/...
$(DOCKER_CMD) go test -race -cover ./cmd/... ./cloud/...

.PHONY: integration
integration: ## Run integration test
go test -v sigs.k8s.io/cluster-api-provider-aws/test/integration
$(DOCKER_CMD) go test -v sigs.k8s.io/cluster-api-provider-aws/test/integration

.PHONY: test-e2e
test-e2e: ## Run e2e test
go test -timeout 20m -v sigs.k8s.io/cluster-api-provider-aws/test/machines -kubeconfig $${KUBECONFIG:-~/.kube/config} -ssh-key $${SSH_PK:-~/.ssh/id_rsa} -actuator-image $${ACTUATOR_IMAGE:-gcr.io/k8s-cluster-api/aws-machine-controller:0.0.1} -cluster-id $${ENVIRONMENT_ID:-""} -ginkgo.v
$(DOCKER_CMD) go test -timeout 20m -v sigs.k8s.io/cluster-api-provider-aws/test/machines -kubeconfig $${KUBECONFIG:-~/.kube/config} -ssh-key $${SSH_PK:-~/.ssh/id_rsa} -cluster-id $${ENVIRONMENT_ID:-""} -ginkgo.v

.PHONY: lint
lint: ## Go lint your code
Expand All @@ -92,4 +109,4 @@ vet: ## Apply go vet to all go files

.PHONY: help
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z/0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
8 changes: 5 additions & 3 deletions hack/go-fmt.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/sh

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec gofmt -s -w {} \+
done
git diff --exit-code
else
docker run --rm \
docker run -it --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/cluster-api-provider-aws:z" \
--workdir /go/src/sigs.k8s.io/cluster-api-provider-aws \
--volume "${PWD}:/go/src/github.com/openshift/${REPO_NAME}:z" \
--workdir "/go/src/github.com/openshift/${REPO_NAME}" \
openshift/origin-release:golang-1.10 \
./hack/go-fmt.sh "${@}"
fi
7 changes: 4 additions & 3 deletions hack/go-lint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/sh
# Example: ./hack/go-lint.sh cmd/... pkg/...
# Example: ./hack/go-lint.sh installer/... pkg/... tests/smoke

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
golint -set_exit_status "${@}"
else
docker run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/cluster-api-provider-aws:z" \
--workdir /go/src/sigs.k8s.io/cluster-api-provider-aws \
--volume "${PWD}:/go/src/github.com/openshift/${REPO_NAME}:z" \
--workdir "/go/src/github.com/openshift/${REPO_NAME}" \
openshift/origin-release:golang-1.10 \
./hack/go-lint.sh "${@}"
fi
5 changes: 3 additions & 2 deletions hack/go-vet.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/sh
REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
go vet "${@}"
else
docker run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/cluster-api-provider-aws:z" \
--workdir /go/src/sigs.k8s.io/cluster-api-provider-aws \
--volume "${PWD}:/go/src/github.com/openshift/${REPO_NAME}:z" \
--workdir "/go/src/github.com/openshift/${REPO_NAME}" \
openshift/origin-release:golang-1.10 \
./hack/go-vet.sh "${@}"
fi;

0 comments on commit 4a80b8f

Please sign in to comment.