Skip to content

Instantly share code, notes, and snippets.

@tcarrio
Created October 2, 2022 04:45
Show Gist options
  • Save tcarrio/91b7d09c0a0b8f9f1a97fba7fa0a9893 to your computer and use it in GitHub Desktop.
Save tcarrio/91b7d09c0a0b8f9f1a97fba7fa0a9893 to your computer and use it in GitHub Desktop.
Makefile with .env
EXAMPLE=deadbeef

Makefiles with .env

Using a .env file is pretty standard practice for many developers. It allows you to configure your local environment and use good security practices.

With Make, like many things, we can utilize a .env file all the same with a few lines of code, and start exporting those secrets to tasks in the Makefile.

.PHONY: env_test
# export the local .env file if found
ifneq (,$(wildcard ./.env))
include .env
export
endif
# re-export the .env var to the commands
env_test: export EXAMPLE = ${EXAMPLE}
env_test:
sh -c 'echo $$EXAMPLE'
[@] > make env_test
sh -c 'echo $EXAMPLE'
deadbeef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment