aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnis Armus <ragnis@armus.ee>2020-02-26 22:58:04 +0200
committerRagnis Armus <ragnis@armus.ee>2020-07-18 15:00:57 +0300
commit9b62ff3aadec369a698b85e574129a2be748a32e (patch)
tree2e65d80228f67b121b4e6ab7d0bd5bde5ab882ac
parentc838466dfeee77e80f2c68c87e779f07feca3cc0 (diff)
Allow setting custom ports via .dpmrc
-rwxr-xr-xdpm26
1 files changed, 20 insertions, 6 deletions
diff --git a/dpm b/dpm
index 7e73191..2a242ac 100755
--- a/dpm
+++ b/dpm
@@ -86,6 +86,13 @@ def read_dict(filename, mapper):
return rv
+def read_dict_or_none(filename, mapper):
+ try:
+ return read_dict(filename, mapper)
+ except FileNotFoundError:
+ pass
+
+
def npmrc_parse_line(line):
m = re.match(r'(.+?)=(.*)$', line)
if m is None:
@@ -265,17 +272,24 @@ def run_container(name, image, bg, cmd):
if bg:
args.append('-d')
- try:
- dotenv = read_dict('.env', dotenv_parse_line)
- except FileNotFoundError:
- dotenv = None
+ dotenv = read_dict_or_none('.env', dotenv_parse_line)
+ dpmrc = read_dict_or_none('.dpmrc', dotenv_parse_line)
+ ports = None
+
+ if dpmrc and 'ports' in dpmrc:
+ ports = []
+ for port in dpmrc['ports'].split(','):
+ ports.append(port)
if dotenv:
for k, v in dotenv.items():
args.extend(('-e', k + '=' + v))
- if 'PORT' in dotenv:
- port = dotenv['PORT']
+ if ports is None and 'PORT' in dotenv:
+ ports = [dotenv['PORT']]
+
+ if ports is not None:
+ for port in ports:
args.extend(('-p', port + ':' + port))
if image['workdir']: