Add an env_file_path input, and document how values reach the stack file - #26
Merged
Conversation
The env_file input takes the variables as content, but "env_file" in docker-compose is a path -- so people reasonably supply a path, and it fails. That is what #3 reported, and #7 was an attempt to fix it by swapping printf for cat, which would have broken every caller passing content. Rather than change what env_file means, add a second input. env_file_path names a file to read; env_file keeps its current meaning and its verbatim `docker --env-file` semantics, so nothing existing breaks. Supplying both is an error, since the precedence between them would otherwise be arbitrary. The parsing is now a load_env_file helper shared by both paths, so the two inputs cannot drift apart in how they treat quotes, spaces or a trailing newline. The internal destination for the env_file content is renamed to ENV_FILE_DEST, freeing ENV_FILE_PATH for the input. Relative paths resolve against the workspace, the same way stack_file already does. Closes #3
#2 asked for usage examples of stack_param and env_file. Neither was really documented: the inputs table described env_file as "additional environment variables" without saying whether that meant content or a path -- the same ambiguity behind #3 -- and the stack_param example set the input without ever showing anything consuming the value, so it demonstrated nothing. Adds a "Passing values into the stack file" section that explains the actual mechanism: docker stack deploy substitutes environment variables as it reads the file, and all three inputs are just ways of setting them. Each one gets a worked example with the matching stack file. It also says the thing worth saying about stack_param: env_file variables are exported before deploy runs, so they reach the stack file by exactly the same route. stack_param is a one-variable special case with a name the caller cannot choose. Documented as supported but discouraged rather than deprecated -- it costs nothing to keep. While in there, the examples pinned kitconcept/docker-stack-deploy@v1.0.1, which predates the docker 29 base image, and actions/checkout@v2. Both now match what this repository actually uses. Closes #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves the
env_filepath-vs-content confusion by adding an input rather than changing what the existing one means, and documents the mechanism both issues were really missing.Closes #2
Closes #3
#3 —
env_filedoesn't workThe input takes the variables as content. But
env_filein docker-compose is a path, so people reasonably supply a path — and it fails. Two people hit this independently (#3, and @Jamesking56 in #7), which makes it a design signal rather than user error.#22 already made the failure legible (
'.env' is not in NAME=VALUE formatinstead of an opaqueexport: not a valid identifier), but the mistake was still just as easy to make.Why a new input instead of changing
env_filePR #7 fixed #3 by swapping
printf '%s' "$ENV_FILE"forcat "$ENV_FILE". That is the right capability, but as a silent breaking change: every caller currently passing content would start failing, becausecatwould try to open that content as a filename.So
env_file_pathis additive:env_filekeeps its meaning and its verbatimdocker --env-filesemantics.stack_filealready does.env_varswould be a better name for the content input, and not worth breaking every existing workflow over.Parsing is now a shared
load_env_filehelper, so the two inputs cannot drift apart in how they handle quotes, spaces, or a trailing newline. The internal destination forenv_filecontent is renamed toENV_FILE_DEST, which freesENV_FILE_PATHfor the input.Rejected alternative
Auto-detecting — "if the value is one line and names an existing file, read it as a file" — was rejected because it makes the semantics depend on the filesystem, so a typo'd path silently changes behaviour instead of failing.
#2 — document
stack_paramandenv_file@luchidalgo asked for examples of both. Neither was properly documented, and the answer for one of them is more interesting than the question.
stack_paramdoes nothing on its own.STACK_PARAMis never read by the entrypoint — grep it. It is exported into the container environment, anddocker stack deploysubstitutes${STACK_PARAM}when it parses the stack file. The old README example setstack_param: "foo"and never showed anything consuming it, so it demonstrated nothing at all.And
env_filesupersedes it entirely. Those variables areexported beforedeployruns, so they reach the stack file by exactly the same route — except you get as many as you like, with names you choose.stack_paramis a one-variable special case with a name the caller cannot pick.The new "Passing values into the stack file" section explains the substitution mechanism once, then gives each input a worked example with its matching stack file.
stack_paramis documented as supported but discouraged rather than deprecated — it costs nothing to keep, and breaking existing callers for tidiness isn't worth it.Also fixed while in there: the examples pinned
kitconcept/docker-stack-deploy@v1.0.1(which predates the docker 29 base image) andactions/checkout@v2. Both now match what this repository actually uses.Verification
make lintclean,make test55 passing / 0 skipped (43 before, 12 new forenv_file_path).Mutation-tested: disabling the
env_file_pathdispatch fails exactly the two tests that assert the wiring, and nothing else.Two things the new tests deliberately pin down:
env_file_pathhas its own verbatim-quotes and value-with-spaces tests, so a future change to one path cannot quietly change only one of them.env_fileinput — hence a test that the last entry of a file is not dropped, which is the failure mode the|| [ -n "$line" ]guard exists for.Value assertions print inside brackets (
[%s]) because bats strips trailing newlines from$output, which would otherwise mask a value that wrongly kept one.Note on merge order
This branches off
main, and #1's PR touches the README immediately after the same inputs table, so whichever merges second will need a small conflict resolution. Happy to rebase this one once that lands.