Skip to content

Commit

Permalink
add switches to prevent .env and .env.dist files
Browse files Browse the repository at this point in the history
there is a flaw w/ docker run - or at least it could be seen as one - as
while following the docs for --env-file automatic handling on .env.dist
and .env files in the pipelines project it came to the attention that
the .env.dist file not setting any values will not as documented only set
the variable if it is exported but also - and that came by surprise - not
exported variables are set to an empty string despite of the lack of the
equality sign.

refs:

- docker/for-linux#284
  • Loading branch information
ktomk committed Apr 19, 2018
1 parent 86b91a9 commit 9d812ad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to Pipelines will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [unreleased]
### Added
- Add `--no-dot-env-files` and `--no-dot-env-dot-dist` flags to
not pass `.env.dist` and `.env` files to docker as
`--env-file` arguments

## [0.0.14] - 2018-04-18
### Added
- Tag script to make releases
Expand Down Expand Up @@ -78,7 +84,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.0.5] - 2018-01-29
### Added
- Docker environment variables options: `-e`, `--env` for
- Docker environment variables options: `-e`, `--env` for
variables and `--env-file` for files
- Composer "ci" script to integrate continuously
- `--no-keep` option to never keep containers, even on error
Expand Down
6 changes: 6 additions & 0 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ pipelines:
script:
- lib/pipelines/environment.sh
- env
printenv:
- step:
image: busybox
name: print environemnt variables
script:
- printenv
18 changes: 13 additions & 5 deletions src/Utility/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ktomk\Pipelines\Utility;

use Exception;
use InvalidArgumentException;
use Ktomk\Pipelines\Cli\Args;
use Ktomk\Pipelines\Cli\ArgsException;
Expand Down Expand Up @@ -219,10 +218,19 @@ private function parseEnv(array $inherit, $reference, $workingDir)

$env = Env::create($inherit);
$env->addReference($reference);
$env->collectFiles(array(
$workingDir . '/.env.dist',
$workingDir . '/.env',
));

$noDotEnvFiles = $args->hasOption('no-dot-env-files');
$noDotEnvDotDist = $args->hasOption('no-dot-env-dot-dist');

if (false === $noDotEnvFiles) {
$filesToCollect = array();
if (false === $noDotEnvDotDist) {
$filesToCollect[] = $workingDir . '/.env.dist';
}
$filesToCollect[] = $workingDir . '/.env';
$env->collectFiles($filesToCollect);
}

$env->collect($args, array('e', 'env', 'env-file'));

return $env;
Expand Down
5 changes: 5 additions & 0 deletions src/Utility/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function showUsage()
[--[no-|error-]keep] [--prefix <prefix>]
[--basename <basename>]
[[-e | --env] <variable>] [--env-file <path>]
[--no-dot-env-files] [--no-dot-env-dot-dist]
[--file <path>] [--dry-run] [--no-run] [--list]
[--deploy mount | copy ] [--show] [--images]
[--pipeline <id>] [--trigger <ref>] [--verbatim]
Expand Down Expand Up @@ -80,6 +81,10 @@ public function showHelp()
for the docker container
--env-file <path> pass variables from environment file
to the docker container
--no-dot-env-files do not pass .env.dist and .env files
as environment files to docker
--no-dot-env-dot-dist dot not pass .env.dist as environment
file to docker
--file <path> path to the pipelines file, overrides
looking up the <basename> file from
the current working directory
Expand Down

0 comments on commit 9d812ad

Please sign in to comment.