From b6735c62e6f1288cdc6a5e46750cc4e9512cec21 Mon Sep 17 00:00:00 2001 From: Sam Salisbury Date: Thu, 24 Sep 2020 13:49:34 +0100 Subject: [PATCH] packagespec init --- .gitattributes | 2 ++ Makefile | 2 ++ packagespec.mk | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 .gitattributes create mode 100755 packagespec.mk diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000000..266c085dc3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/packagespec.mk linguist-generated +/packagespec.mk linguist-generated \ No newline at end of file diff --git a/Makefile b/Makefile index f3c03f4f2b..9f3f20a0d8 100644 --- a/Makefile +++ b/Makefile @@ -114,3 +114,5 @@ install-go: .PHONY: api tools gen migrations proto website .NOTPARALLEL: + +-include packagespec.mk \ No newline at end of file diff --git a/packagespec.mk b/packagespec.mk new file mode 100755 index 0000000000..f1b1fe0860 --- /dev/null +++ b/packagespec.mk @@ -0,0 +1,82 @@ +# *** +# WARNING: Do not EDIT or MERGE this file, it is generated by packagespec. +# *** +# packagespec.mk should be included at the end of your main Makefile, +# it provides hooks into packagespec targets, so you can run them +# from the root of your product repository. +# +# All packagespec-generated make targets assume they are invoked by +# targets in this file, which provides the necessary context for those +# other targets. Therefore, this file is not just for conveninence but +# is currently necessary to the correct functioning of Packagespec. + +# Since this file is included in other Makefiles, which may or may not want +# to use bash with these options, we explicitly set the shell for specific +# targets, in this file, rather than setting the global SHELL variable. +PACKAGESPEC_SHELL := /usr/bin/env bash -euo pipefail -c + +# The RUN macro is used in place of the shell builtin in this file, so that +# we can use the PACKAGESPEC_SHELL rather than the default from the Makefile +# that includes this one. +RUN = $(shell $(PACKAGESPEC_SHELL) '$1') + +# This can be overridden by the calling Makefile to write config to a different path. +PACKAGESPEC_CIRCLECI_CONFIG ?= .circleci/config.yml +PACKAGESPEC_HOOK_POST_CI_CONFIG ?= echo > /dev/null + +SPEC_FILE_PATTERN := packages*.yml +# SPEC is the human-managed description of which packages we are able to build. +SPEC := $(call RUN,find . -mindepth 1 -maxdepth 1 -name '$(SPEC_FILE_PATTERN)') +ifneq ($(words $(SPEC)),1) +$(error Found $(words $(SPEC)) $(SPEC_FILE_PATTERN) files, need exactly 1: $(SPEC)) +endif +SPEC_FILENAME := $(notdir $(SPEC)) +SPEC_MODIFIER := $(SPEC_FILENAME:packages%.yml=%) +# LOCKDIR contains the lockfile and layer files. +LOCKDIR := packages$(SPEC_MODIFIER).lock +LOCKFILE := $(LOCKDIR)/pkgs.yml + +export PACKAGE_SPEC_ID LAYER_SPEC_ID PRODUCT_REVISION PRODUCT_VERSION + +# PASSTHROUGH_TARGETS are convenience aliases for targets defined in $(LOCKDIR)/Makefile +PASSTHROUGH_TARGETS := \ + build package-contents copy-package-contents build-all \ + aliases meta package package-meta \ + build-ci watch-ci \ + stage-config stage \ + list-staged-builds \ + publish-config publish + +.PHONY: $(PASSTHROUGH_TARGETS) + +LOCAL_TARGETS := packages packagespec-circleci-config $(PACKAGESPEC_CIRCLECI_CONFIG) + +# Set the shell for all packagespec targets. +$(PASSTHROUGH_TARGETS) $(LOCAL_TARGETS): SHELL := $(PACKAGESPEC_SHELL) + +$(PASSTHROUGH_TARGETS): + @PRODUCT_REPO_ROOT="$(call RUN,git rev-parse --show-toplevel)" $(MAKE) -C $(LOCKDIR) $@ + +# packages regenerates $(LOCKDIR) from $(SPEC) using packagespec. This is only for +# internal HashiCorp use, as it has dependencies not available externally. +.PHONY: packages +packages: + @command -v packagespec > /dev/null 2>&1 || { \ + echo "Please install packagespec."; \ + echo "Note: packagespec is only available to HashiCorp employees at present."; \ + exit 1; \ + } + @packagespec lock -specfile $(SPEC) -lockdir $(LOCKDIR) + @$(MAKE) $(PACKAGESPEC_CIRCLECI_CONFIG) + +CIRCLECI_PRIMARY_TPL := .packagespec/templates/circleci-primary.yml.tpl + +$(PACKAGESPEC_CIRCLECI_CONFIG): $(LOCKFILE) $(CIRCLECI_PRIMARY_TPL) + @\ + echo "==> Updating $(PACKAGESPEC_CIRCLECI_CONFIG)..."; \ + mkdir -p "$(dir $@)"; \ + cat $< | gomplate -f $(CIRCLECI_PRIMARY_TPL) -d 'lock-file=stdin://?type=application/yaml' > $@; \ + $(PACKAGESPEC_HOOK_POST_CI_CONFIG) + +# This target is needed by packagespec, do not remove. +packagespec-circleci-config: $(PACKAGESPEC_CIRCLECI_CONFIG)