Makefile: add direnv-check to verify it is loaded

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2024-10-16 19:50:39 +02:00
parent 201a1856da
commit 9d403471d6
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
2 changed files with 37 additions and 12 deletions

View File

@ -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

View File

@ -42,8 +42,7 @@
];
shellHook = ''
./ansible/roles.py --check || \
echo -e '\nWARNING: Your role versions appear to be incorrect!' >&2
make checks
'';
};
});