From 9d403471d60169fc360ab59489d70cc5013b2954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 16 Oct 2024 19:50:39 +0200 Subject: [PATCH] Makefile: add direnv-check to verify it is loaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 46 ++++++++++++++++++++++++++++++++++++---------- flake.nix | 3 +-- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index e8113de..e9769b6 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ +# Colors +YLW = \033[1;33m +RED = \033[0;31m +GRN = \033[0;32m +BLU = \033[0;34m +BLD = \033[1m +RST = \033[0m + OS = $(shell uname -s | tr A-Z a-z) ARCH = "${OS}-$(shell uname -m)" @@ -15,17 +23,18 @@ PROVISIONER_ARCHIVE = $(PROVISIONER_NAME)-$(ARCH)-$(PROVISIONER_VERSION) PROVISIONER_URL = https://github.com/status-im/terraform-provisioner-ansible/releases/download/$(PROVISIONER_VERSION)/$(PROVISIONER_ARCHIVE) PROVISIONER_PATH = $(TF_PLUGINS_DIR)/$(PROVISIONER_NAME) -all: roles-install install-provisioner secrets init-terraform +all: roles-install install-provisioner secrets init-terraform checks @echo "Success!" roles-install: - ansible/roles.py --install + @ansible/roles.py --install roles-check: - ansible/roles.py --check + @ansible/roles.py --check || \ + echo -e '\n$(YLW)WARNING: Local role versions appear to be incorrect.$(RST)' >&2 roles-update: - ansible/roles.py --update + @ansible/roles.py --update roles: roles-install roles-check @@ -46,13 +55,30 @@ secrets: pass services/vault/certs/client-user/cert > ansible/files/vault-client-user.crt pass services/vault/certs/client-user/privkey > ansible/files/vault-client-user.key -consul-token-check: -ifndef CONSUL_HTTP_TOKEN - $(error No CONSUL_HTTP_TOKEN env variable set!) -endif - -init-terraform: consul-token-check +init-terraform: consul-check terraform init -upgrade=true cleanup: rm -r $(TF_PLUGINS_DIR)/$(ARCHIVE) + +consul-check: +ifndef CONSUL_HTTP_TOKEN + @echo -e "$(RED)$(BLD)ERROR: No CONSUL_HTTP_TOKEN env variable set!$(RST)"; exit 1 +endif + +vault-check: +ifndef VAULT_TOKEN + @echo -e "$(RED)$(BLD)ERROR: No VAULT_TOKEN env variable set!$(RST)"; exit 1 +endif + +DIRENV_LOADED ?= $(shell direnv status --json | jq .state.loadedRC.allowed) +direnv-check: + @if [[ "$(DIRENV_LOADED)" -ne 0 ]] && [[ -z "$${DIRENV_IN_ENVRC}" ]]; then \ + echo -e "$(YLW)WARNING: This repo assumes use of Direnv:$(RST)" \ + "$(BLD)"'eval "$$(direnv hook zsh)"; direnv allow'"$(RST)"; \ + fi + +checks: roles-check direnv-check consul-check vault-check + @echo -e "\n$(GRN)$(BLD)WELCOME BACK, COMMANDER$(RST)" + +.PHONY = checks roles-check direnv-check consul-check vault-check diff --git a/flake.nix b/flake.nix index 484fff6..f6c1ea9 100644 --- a/flake.nix +++ b/flake.nix @@ -42,8 +42,7 @@ ]; shellHook = '' - ./ansible/roles.py --check || \ - echo -e '\nWARNING: Your role versions appear to be incorrect!' >&2 + make checks ''; }; });