Skip to content

Commit b802f8d

Browse files
authored
Merge pull request #251 from platform9/dg/makefile-idempotent
2 parents 290b1a0 + db5bc16 commit b802f8d

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

Makefile

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ controller-test: $(GINKGO) ## Run controller tests
258258
webhook-test: $(GINKGO) ## Run webhook tests
259259
source ./scripts/fetch_ext_bins.sh; fetch_tools; setup_envs; $(GINKGO) --coverprofile cover.out apis/infrastructure/v1beta1
260260

261-
test-e2e: take-user-input docker-build prepare-byoh-docker-host-image $(GINKGO) cluster-templates-e2e ## Run the end-to-end tests
262-
$(GINKGO) -v -trace -tags=e2e -focus="$(GINKGO_FOCUS)" $(_SKIP_ARGS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) $(GINKGO_ARGS) test/e2e -- \
261+
# CI will download the agent bundle from the saved artifacts if SKIP_BUILD is set.
262+
ifdef SKIP_BUILD
263+
BUILD_HOST_AGENT_DEB_PREREQ :=
264+
else
265+
BUILD_HOST_AGENT_DEB_PREREQ := build-host-agent-deb
266+
endif
267+
268+
test-e2e: take-user-input docker-build prepare-byoh-docker-host-image $(GINKGO) cluster-templates-e2e $(BUILD_HOST_AGENT_DEB_PREREQ) ## Run the end-to-end tests
269+
$(GINKGO) -vv -trace -tags=e2e -focus="$(GINKGO_FOCUS)" $(_SKIP_ARGS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) $(GINKGO_ARGS) test/e2e -- \
263270
-e2e.artifacts-folder="$(ARTIFACTS)" \
264271
-e2e.config="$(E2E_CONF_FILE)" \
265272
-e2e.skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP) -e2e.use-existing-cluster=$(USE_EXISTING_CLUSTER) \
@@ -320,8 +327,6 @@ take-user-input:
320327
@echo "$$WARNING"
321328
@read -p "Do you want to proceed [Y/n]?" REPLY; \
322329
if [[ $$REPLY = "Y" || $$REPLY = "y" ]]; then echo starting e2e test; exit 0 ; else echo aborting; exit 1; fi
323-
324-
325330

326331
$(GINKGO): # Build ginkgo from tools folder.
327332
cd $(TOOLS_DIR); GOBIN=$(TOOLS_BIN_DIR) go install $(GINKGO_PKG)
@@ -436,15 +441,24 @@ DEB_SRC_ROOT := $(PF9_BYOHOST_SRCDIR)/debsrc
436441
# HELM_ARCH rather than a hardcoded amd64.
437442
PACKAGE_GOARCH ?= $(HELM_ARCH)
438443
COMMON_SRC_ROOT := $(PF9_BYOHOST_SRCDIR)/common
444+
# COMMON_SRC_ROOT/DEB_SRC_ROOT/RPM_SRC_ROOT are directories. Make treats a directory as up to
445+
# date the moment it exists, even half-populated by a crashed prior run. The stamp gives each
446+
# one a real mtime to check, so the recipe can rm -rf and repopulate instead of trusting
447+
# whatever's already sitting there.
448+
COMMON_SRC_STAMP := $(COMMON_SRC_ROOT)/.stamp
449+
DEB_SRC_STAMP := $(DEB_SRC_ROOT)/.stamp
450+
RPM_SRC_STAMP := $(RPM_SRC_ROOT)/.stamp
439451
PF9_BYOHOST_DEB_FILE := $(PF9_BYOHOST_SRCDIR)/debsrc/pf9-byohost-agent.deb
440452
RPMBUILD_DIR := $(PF9_BYOHOST_SRCDIR)/rpmbuild
441453
PF9_BYOHOST_RPM_FILE := $(RPMBUILD_DIR)/RPMS/$(HELM_ARCH_RAW)/pf9-byohost-1.0-$(BUILDNUM).git$(GITHASH).$(HELM_ARCH_RAW).rpm
442454

443-
$(RPM_SRC_ROOT): | $(COMMON_SRC_ROOT)
455+
$(RPM_SRC_STAMP): $(COMMON_SRC_STAMP)
444456
echo "make RPM_SRC_ROOT: $(RPM_SRC_ROOT)"
457+
rm -rf $(RPM_SRC_ROOT)
445458
cp -a $(COMMON_SRC_ROOT) $(RPM_SRC_ROOT)
459+
touch $@
446460

447-
$(PF9_BYOHOST_RPM_FILE): |$(RPM_SRC_ROOT)
461+
$(PF9_BYOHOST_RPM_FILE): $(RPM_SRC_STAMP)
448462
echo "make PF9_BYOHOST_RPM_FILE $(PF9_BYOHOST_RPM_FILE) "
449463
rpmbuild -bb \
450464
--define "_topdir $(RPMBUILD_DIR)" \
@@ -464,26 +478,30 @@ build-host-agent-rpm: $(PF9_BYOHOST_RPM_FILE)
464478
build-byohctl-binary:
465479
$(MAKE) -C $(BYOHCTL_DIR) build GOARCH=$(PACKAGE_GOARCH)
466480

467-
$(COMMON_SRC_ROOT): build-byohctl-binary
481+
$(COMMON_SRC_STAMP): build-byohctl-binary
468482
echo "Building COMMON_SRC_ROOT"
483+
rm -rf $(COMMON_SRC_ROOT)
469484
mkdir -p $(COMMON_SRC_ROOT)
470485
echo "BUILDING COMMON_SRC_ROOT/binary for GOARCH=$(PACKAGE_GOARCH)"
471486
RELEASE_BINARY=./byoh-hostagent GOOS=linux GOARCH=$(PACKAGE_GOARCH) GOLDFLAGS="$(LDFLAGS) $(STATIC)" \
472487
HOST_AGENT_DIR=./$(HOST_AGENT_DIR) $(MAKE) host-agent-binary
473488
mkdir -p $(COMMON_SRC_ROOT)/binary
474489
cp bin/byoh-hostagent-linux-$(PACKAGE_GOARCH) $(COMMON_SRC_ROOT)/binary/pf9-byoh-hostagent
475-
echo "BUILDING dir for pf9-byohost-service , COPING service pf9-byoh-agent.service "
490+
echo "BUILDING dir for pf9-byohost-service, COPYING service pf9-byoh-agent.service"
476491
mkdir -p $(COMMON_SRC_ROOT)/etc/systemd/system/
477492
cp $(AGENT_SRC_DIR)/service/pf9-byohostagent.service $(COMMON_SRC_ROOT)/etc/systemd/system/pf9-byohost-agent.service
478-
echo "BUILDING COMMON_SRC_ROOT/usr/bin COPING binary byohctl"
493+
echo "BUILDING COMMON_SRC_ROOT/usr/bin COPYING binary byohctl"
479494
mkdir -p $(COMMON_SRC_ROOT)/usr/bin
480495
cp $(BYOHCTL_DIR)/bin/byohctl $(COMMON_SRC_ROOT)/usr/bin/byohctl
481496
chmod +x $(COMMON_SRC_ROOT)/usr/bin/byohctl
497+
touch $@
482498

483-
$(DEB_SRC_ROOT): | $(COMMON_SRC_ROOT)
484-
cp -a $(COMMON_SRC_ROOT) $(DEB_SRC_ROOT)
499+
$(DEB_SRC_STAMP): $(COMMON_SRC_STAMP)
500+
rm -rf $(DEB_SRC_ROOT)
501+
cp -a $(COMMON_SRC_ROOT) $(DEB_SRC_ROOT)
502+
touch $@
485503

486-
$(PF9_BYOHOST_DEB_FILE): $(DEB_SRC_ROOT)
504+
$(PF9_BYOHOST_DEB_FILE): $(DEB_SRC_STAMP)
487505
fpm -t deb -s dir -n pf9-byohost-agent \
488506
--description "Platform9 Bring Your Own Host deb package" \
489507
--license "Commercial" --architecture $(PACKAGE_GOARCH) --url "http://www.platform9.net" --vendor Platform9 \

0 commit comments

Comments
 (0)