github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/Makefile (about)

     1  #
     2  # Makefile for juju-core.
     3  #
     4  ifndef GOPATH
     5  $(warning You need to set up a GOPATH.  See the README file.)
     6  endif
     7  
     8  PROJECT := github.com/juju/juju
     9  PROJECT_DIR := $(shell go list -e -f '{{.Dir}}' $(PROJECT))
    10  PROJECT_PACKAGES := $(shell go list $(PROJECT)/... | grep -v /vendor/)
    11  
    12  # Allow the tests to take longer on arm platforms.
    13  ifeq ($(shell uname -p | sed -E 's/.*(armel|armhf|aarch64).*/golang/'), golang)
    14  	TEST_TIMEOUT := 2400s
    15  else
    16  	TEST_TIMEOUT := 1500s
    17  endif
    18  
    19  # Enable verbose testing for reporting.
    20  ifeq ($(VERBOSE_CHECK), 1)
    21  	CHECK_ARGS = -v
    22  else
    23  	CHECK_ARGS =
    24  endif
    25  
    26  define DEPENDENCIES
    27    ca-certificates
    28    bzip2
    29    distro-info-data
    30    git
    31    zip
    32  endef
    33  
    34  default: build
    35  
    36  # Start of GOPATH-dependent targets. Some targets only make sense -
    37  # and will only work - when this tree is found on the GOPATH.
    38  ifeq ($(CURDIR),$(PROJECT_DIR))
    39  
    40  ifeq ($(JUJU_SKIP_DEP),true)
    41  dep:
    42  	@echo "skipping dep"
    43  else
    44  $(GOPATH)/bin/dep:
    45  	go get -u github.com/golang/dep/cmd/dep
    46  
    47  # populate vendor/ from Gopkg.lock without updating it first (lock file is the single source of truth for machine).
    48  dep: $(GOPATH)/bin/dep
    49  	$(GOPATH)/bin/dep ensure -vendor-only $(verbose)
    50  endif
    51  
    52  build: dep go-build
    53  
    54  release-build: dep go-build
    55  
    56  release-install: dep go-install
    57  
    58  pre-check:
    59  	@echo running pre-test checks
    60  	@$(PROJECT_DIR)/scripts/verify.bash
    61  
    62  check: dep pre-check
    63  	go test $(CHECK_ARGS) -test.timeout=$(TEST_TIMEOUT) $(PROJECT_PACKAGES) -check.v
    64  
    65  install: dep go-install
    66  
    67  clean:
    68  	go clean -n -r --cache --testcache $(PROJECT_PACKAGES)
    69  
    70  go-install:
    71  	@echo 'go install -ldflags "-s -w" -v $$PROJECT_PACKAGES'
    72  	@go install -ldflags "-s -w" -v $(PROJECT_PACKAGES)
    73  
    74  go-build:
    75  	@go build $(PROJECT_PACKAGES)
    76  
    77  else # --------------------------------
    78  
    79  build:
    80  	$(error Cannot $@; $(CURDIR) is not on GOPATH)
    81  
    82  check:
    83  	$(error Cannot $@; $(CURDIR) is not on GOPATH)
    84  
    85  install:
    86  	$(error Cannot $@; $(CURDIR) is not on GOPATH)
    87  
    88  clean:
    89  	$(error Cannot $@; $(CURDIR) is not on GOPATH)
    90  
    91  endif
    92  # End of GOPATH-dependent targets.
    93  
    94  # Reformat source files.
    95  format:
    96  	gofmt -w -l .
    97  
    98  # Reformat and simplify source files.
    99  simplify:
   100  	gofmt -w -l -s .
   101  
   102  # update Gopkg.lock (if needed), but do not update `vendor/`.
   103  rebuild-dependencies:
   104  	dep ensure -v -no-vendor $(dep-update)
   105  
   106  # Install packages required to develop Juju and run tests. The stable
   107  # PPA includes the required mongodb-server binaries.
   108  install-dependencies:
   109  	@echo Installing go-1.11 snap
   110  	@sudo snap install go --channel=1.11/stable --classic
   111  	@echo Adding juju PPA for mongodb
   112  	@sudo apt-add-repository --yes ppa:juju/stable
   113  	@sudo apt-get update
   114  	@echo Installing dependencies
   115  	@sudo apt-get --yes install  \
   116  	$(strip $(DEPENDENCIES)) \
   117  	$(shell apt-cache madison mongodb-server-core juju-mongodb3.2 juju-mongodb mongodb-server | head -1 | cut -d '|' -f1)
   118  
   119  # Install bash_completion
   120  install-etc:
   121  	@echo Installing bash completion
   122  	@sudo install -o root -g root -m 644 etc/bash_completion.d/juju /usr/share/bash-completion/completions
   123  	@sudo install -o root -g root -m 644 etc/bash_completion.d/juju-version /usr/share/bash-completion/completions
   124  
   125  setup-lxd:
   126  ifeq ($(shell ifconfig lxdbr0 2>&1 | grep -q "inet addr" && echo true),true)
   127  	@echo IPv4 networking is already setup for LXD.
   128  	@echo run "sudo scripts/setup-lxd.sh" to reconfigure IPv4 networking
   129  else
   130  	@echo Setting up IPv4 networking for LXD
   131  	@sudo scripts/setup-lxd.sh || true
   132  endif
   133  
   134  
   135  GOCHECK_COUNT="$(shell go list -f '{{join .Deps "\n"}}' github.com/juju/juju/... | grep -c "gopkg.in/check.v*")"
   136  check-deps:
   137  	@echo "$(GOCHECK_COUNT) instances of gocheck not in test code"
   138  
   139  # CAAS related targets
   140  DOCKER_USERNAME?=jujusolutions
   141  JUJUD_STAGING_DIR?=/tmp/jujud-operator
   142  JUJUD_BIN_DIR=${GOPATH}/bin
   143  OPERATOR_IMAGE_TAG = $(shell jujud version | rev | cut -d- -f3- | rev)
   144  
   145  operator-image: install caas/jujud-operator-dockerfile caas/jujud-operator-requirements.txt
   146  	rm -rf ${JUJUD_STAGING_DIR}
   147  	mkdir ${JUJUD_STAGING_DIR}
   148  	cp ${JUJUD_BIN_DIR}/jujud ${JUJUD_STAGING_DIR}
   149  	cp caas/jujud-operator-dockerfile ${JUJUD_STAGING_DIR}
   150  	cp caas/jujud-operator-requirements.txt ${JUJUD_STAGING_DIR}
   151  	docker build -f ${JUJUD_STAGING_DIR}/jujud-operator-dockerfile -t ${DOCKER_USERNAME}/caas-jujud-operator:${OPERATOR_IMAGE_TAG} ${JUJUD_STAGING_DIR}
   152  	rm -rf ${JUJUD_STAGING_DIR}
   153  
   154  push-operator-image: operator-image
   155  	docker push ${DOCKER_USERNAME}/caas-jujud-operator
   156  
   157  check-k8s-model:
   158  	@:$(if $(value JUJU_K8S_MODEL),, $(error Undefined JUJU_K8S_MODEL))
   159  	@juju show-model ${JUJU_K8S_MODEL} > /dev/null
   160  
   161  local-operator-update: check-k8s-model operator-image
   162  	$(eval kubeworkers != juju status -m ${JUJU_K8S_MODEL} kubernetes-worker --format json | jq -c '.machines | keys' | tr  -c '[:digit:]' ' ' 2>&1)
   163  	docker save ${DOCKER_USERNAME}/caas-jujud-operator | gzip > /tmp/caas-jujud-operator-image.tar.gz
   164  	$(foreach wm,$(kubeworkers), juju scp -m ${JUJU_K8S_MODEL} /tmp/caas-jujud-operator-image.tar.gz $(wm):/tmp/caas-jujud-operator-image.tar.gz ; )
   165  	$(foreach wm,$(kubeworkers), juju ssh -m ${JUJU_K8S_MODEL} $(wm) -- "zcat /tmp/caas-jujud-operator-image.tar.gz | docker load" ; )
   166  
   167  .PHONY: build check install release-install release-build go-build go-install
   168  .PHONY: clean format simplify
   169  .PHONY: install-dependencies
   170  .PHONY: rebuild-dependencies
   171  .PHONY: dep check-deps