Skip to content

Instantly share code, notes, and snippets.

@tseho
Last active January 1, 2022 16:40
Show Gist options
  • Save tseho/66a852e6a515a85cbb35b8ab5ec1ec0f to your computer and use it in GitHub Desktop.
Save tseho/66a852e6a515a85cbb35b8ab5ec1ec0f to your computer and use it in GitHub Desktop.
DOTENV in Makefile
# If there is a .env file, create a temporary copy of it, in a format supported by Makefile
# where every variable become a fallback. "FOO=bar" becomes "FOO?=bar"
ifneq (,$(wildcard ./.env))
DOTENV_PATH=/tmp/$(shell echo $$(pwd) | base64)
include $(shell cat .env | grep -v --perl-regexp '^('$$(env | sed 's/=.*//'g | tr '\n' '|')')\=' | sed 's/=/?=/g' > $(DOTENV_PATH); echo '$(DOTENV_PATH)')
endif
# Expose all defined variables to subprocesses.
export
# Then, other targets
.PHONY: up
up:
docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment