environment.mk 1.1 KB

123456789101112131415161718192021222324252627282930
  1. stage ?= default
  2. .PHONY: environment
  3. environment: ${stage}.env ##- Define environment variables
  4. @test ${stage} || (echo 'stage not set'; exit 1)
  5. @$(eval ENV_FILE?=./${stage}.env)
  6. @$(eval load_env=set -a;. ${ENV_FILE};set +a)
  7. %.env: env.sh
  8. @echo "Env file $@ is not found or obsolete"
  9. @echo "Please update it (review and touch, or call make [-e stage=${stage}] generate-env)"; exit 1
  10. .PHONY: generate-env
  11. generate-env: env.sh ##- Generate environment file ${stage}.env
  12. @test ${stage} || (echo 'stage not set'; exit 1)
  13. @./env.sh ${stage} > ${stage}.env
  14. @$(eval OVERRIDE_ENV_FILE?=./override.env)
  15. @[ -f "${OVERRIDE_ENV_FILE}" ] && echo "Appending environment override"; true
  16. @(([ -x "${OVERRIDE_ENV_FILE}" ] && "${OVERRIDE_ENV_FILE}") || \
  17. ([ -r "${OVERRIDE_ENV_FILE}" ] && cat "${OVERRIDE_ENV_FILE}") || true) | tee -a ${stage}.env
  18. @echo "Environment file ${stage}.env generated"
  19. .PHONY: dump-env
  20. dump-env: environment ##- Dump environment
  21. @echo "dump ENV_FILE: ${ENV_FILE}"
  22. $(load_env); env
  23. .PHONY: shell-env
  24. shell-env: environment ##- Start a local shell with environment
  25. @$(load_env); PS1='env$$ ' ${SHELL}