diff --git a/Makefile b/Makefile index 660a5fb279..c30ccc31fe 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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 @@ -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}' diff --git a/hack/go-fmt.sh b/hack/go-fmt.sh index 04c82bf1e4..22a92bb3c9 100755 --- a/hack/go-fmt.sh +++ b/hack/go-fmt.sh @@ -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 diff --git a/hack/go-lint.sh b/hack/go-lint.sh index 20d5470933..0ae8f77459 100755 --- a/hack/go-lint.sh +++ b/hack/go-lint.sh @@ -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 diff --git a/hack/go-vet.sh b/hack/go-vet.sh index c854533e8c..a2fb34552b 100755 --- a/hack/go-vet.sh +++ b/hack/go-vet.sh @@ -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;