mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
fix(kb/make): clarify inclusion of env files
This commit is contained in:
@@ -13,6 +13,12 @@
|
||||
override override_me ?= default_value
|
||||
|
||||
|
||||
# Load env files.
|
||||
# If prefixed with '-' it does not error should any of the files not exist.
|
||||
include .env
|
||||
-include .env.local .env.extra
|
||||
|
||||
|
||||
# export variables for all programs to see
|
||||
# only exported in the commands' sub-shells
|
||||
export
|
||||
@@ -39,11 +45,6 @@ previous_target:
|
||||
next_target:
|
||||
|
||||
|
||||
# load env files
|
||||
-include .env
|
||||
-include .env.local
|
||||
|
||||
|
||||
# conditionals
|
||||
ifeq "${shell uname}" "Darwin"
|
||||
expiration_date = ${shell date -v "+365d" "+%FT%TZ"}
|
||||
@@ -82,7 +83,12 @@ apply: plan ${tf_plan_file}
|
||||
|
||||
## Load .env files in the Makefile
|
||||
|
||||
Use this at top of a Makefile to export all variables in `.env`:
|
||||
Use one of those at the top of a Makefile to include and make available all variables in `.env`:
|
||||
|
||||
```makefile
|
||||
include .env
|
||||
-include .env.local .env.extra
|
||||
```
|
||||
|
||||
```makefile
|
||||
ifneq (,$(wildcard ./.env))
|
||||
@@ -91,15 +97,17 @@ ifneq (,$(wildcard ./.env))
|
||||
endif
|
||||
```
|
||||
|
||||
`ifneq` + `wildcard` is a typical way to check a file exists.<br/>
|
||||
`ifneq` + `wildcard` is a typical way to check a file exists.
|
||||
|
||||
`include .env` imports `.env` into the Makefile variables.<br/>
|
||||
If prefixed with '-' (`-include`), it does not error nor warning should any of the included files not exist.
|
||||
|
||||
`export` without parameters exports all variables set until now.
|
||||
|
||||
|
||||
|
||||
## Further readings
|
||||
|
||||
- [Conditional syntax]
|
||||
- [Include]
|
||||
|
||||
### Sources
|
||||
|
||||
@@ -112,6 +120,7 @@ endif
|
||||
|
||||
<!-- Upstream -->
|
||||
[conditional syntax]: https://www.gnu.org/software/make/manual/html_node/Conditional-Syntax.html
|
||||
[include]: https://www.gnu.org/software/make/manual/html_node/Include.html
|
||||
|
||||
<!-- Others -->
|
||||
[how to load and export variables from an .env file in makefile?]: https://stackoverflow.com/questions/44628206/how-to-load-and-export-variables-from-an-env-file-in-makefile#70663753
|
||||
|
||||
Reference in New Issue
Block a user