Skip to content

Commit

Permalink
Refs docker#565. Adds minimal implementation of env_file client-side …
Browse files Browse the repository at this point in the history
…support.
  • Loading branch information
vpetersson committed Jul 28, 2015
1 parent 70dd654 commit 2898389
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import os.path
import json
import csv
import shlex
import tarfile
import tempfile
Expand Down Expand Up @@ -524,16 +525,35 @@ def create_container_config(
dns=None, volumes=None, volumes_from=None, network_disabled=False,
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None, mac_address=None,
labels=None, volume_driver=None
labels=None, volume_driver=None, env_file=None
):
if isinstance(command, six.string_types):
command = shlex.split(str(command))

if isinstance(environment, dict):
environment = [
six.text_type('{0}={1}').format(k, v)
for k, v in six.iteritems(environment)
]

if isinstance(env_file, str):
if os.path.isfile(env_file):

# Re-classify None to list if needed
if isinstance(environment, type(None)):
environment = []

# Re-classify string to List if needed
if isinstance(environment, str):
environment = environment.split(',')

with open(env_file, 'r') as f:
for line in csv.reader(f, delimiter='='):
if len(line) == 2:
k = line[0].strip()
v = line[1].strip()
environment.append('{0}={1}'.format(k, v))

if labels is not None and compare_version('1.18', version) < 0:
raise errors.InvalidVersion(
'labels were only introduced in API version 1.18'
Expand Down
5 changes: 5 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ where unit = b, k, m, or g)
* ports (list of ints): A list of port numbers
* environment (dict or list): A dictionary or a list of strings in the
following format `["PASSWORD=xxx"]` or `{"PASSWORD": "xxx"}`.
* env_file (file): A line-separated list of environment variables, such as:
```
USERNAME=jdoe
PASSWORD=secret
```
* dns (list): DNS name servers
* volumes (str or list):
* volumes_from (str or list): List of container names or Ids to get volumes
Expand Down

0 comments on commit 2898389

Please sign in to comment.