doc
This commit is contained in:
+13
-14
@@ -1,9 +1,12 @@
|
||||
##
|
||||
# target .env:
|
||||
# update .env file when .env.dist file is newer
|
||||
# ENV
|
||||
|
||||
# target .env: Update .env
|
||||
## it updates .env file when .env.dist file is newer
|
||||
.env: .env.dist
|
||||
$(call .env,,,$(wildcard $(PARAMETERS)/$(ENV)/$(APP)/.env .env.$(ENV)))
|
||||
|
||||
# target .env-clean: Remove .env
|
||||
.PHONY: .env-clean
|
||||
.env-clean:
|
||||
rm -f .env || true
|
||||
@@ -20,20 +23,19 @@ env.docker = $(env.docker.args) $(env.docker.dist) $(env.docker.file)
|
||||
|
||||
env.args = $(foreach var,$(ENV_VARS),$(if $($(var)),$(var)='$($(var))'))
|
||||
env.dist = $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A)' .env.dist - 2>/dev/null)
|
||||
env.file = $(shell cat $(wildcard $(ENV_FILE)) 2>/dev/null |sed '/^[ \t]*$$/d;/^[ \t]*\#/d;')
|
||||
env.file = $(shell cat $(ENV_FILE) 2>/dev/null |sed '/^[ \t]*$$/d;/^[ \t]*\#/d;')
|
||||
env.docker.args = $(foreach var,$(ENV_VARS),$(if $($(var)),-e $(var)='$($(var))'))
|
||||
env.docker.dist = $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A) {print "-e "$$0}' .env.dist - 2>/dev/null)
|
||||
env.docker.file = $(patsubst %,--env-file %,$(wildcard $(ENV_FILE)))
|
||||
|
||||
SHELL:=/bin/bash
|
||||
|
||||
##
|
||||
# function .env
|
||||
## set .env file path and call .env_update function if .env.dist file exists
|
||||
# function .env: Call .env_update function
|
||||
## it sets .env, .env.dist and .env.ENV files paths
|
||||
## it calls .env_update function if .env.dist file exists
|
||||
# 1st arg: path to .env file to update, default to .env
|
||||
# 2nd arg: path to .env.dist file, default to .env.dist
|
||||
# 3rd arg: path to .env override files, default to .env.$(ENV)
|
||||
# if .env.dist exists then call .env_update function
|
||||
define .env
|
||||
$(eval env_file:=$(or $(1),.env))
|
||||
$(eval env_dist:=$(or $(2),$(env_file).dist))
|
||||
@@ -41,9 +43,7 @@ define .env
|
||||
$(if $(wildcard $(env_dist)), $(call .env_update))
|
||||
endef
|
||||
|
||||
##
|
||||
# function .env_update
|
||||
## update .env file with vars from .env.dist not set in environment.
|
||||
# function .env_update: Update .env file with values from .env.dist
|
||||
## this function adds variables from the .env.dist to the .env file
|
||||
## and does substitution to replace variables with their value when
|
||||
## adding it to the .env. It reads variables first from environment,
|
||||
@@ -53,14 +53,13 @@ endef
|
||||
# create the .env file
|
||||
# read environment variables
|
||||
# keep variables from .env.dist that does not exist in environment
|
||||
# add variables definition from .env override files at the beginning of the list
|
||||
# add variables definition from make command line at the beginning of the list
|
||||
# add variables definition from .env override files at the beginning
|
||||
# add variables definition from make command line at the beginning
|
||||
# remove duplicate variables
|
||||
# keep variables that exists in .env.dist
|
||||
# keep variables that does not exist in .env
|
||||
# read variables definition in a subshell with multiline support
|
||||
# create a new environment (empty if $(ENV_RESET) is true) with
|
||||
# $(env.args)
|
||||
# create a new (empty if ENV_RESET is true) environment with env.args
|
||||
# read environment variables and keep only those existing in .env.dist
|
||||
# add .env overrides variables definition
|
||||
# add .env.dist variables definition
|
||||
|
||||
Reference in New Issue
Block a user