Add stack-deploy.sh + envparse.py: safe env loading via Python for all stacks
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import sys, re
|
||||
|
||||
def parse_env(path):
|
||||
pairs = []
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#') or '=' not in line:
|
||||
continue
|
||||
k, _, v = line.partition('=')
|
||||
k = k.strip(); v = v.strip()
|
||||
if (v.startswith("'") and v.endswith("'")) or \
|
||||
(v.startswith('"') and v.endswith('"')):
|
||||
v = v[1:-1]
|
||||
pairs.append((k, v))
|
||||
return pairs
|
||||
|
||||
mode = sys.argv[1]
|
||||
if mode == 'export':
|
||||
for k, v in parse_env(sys.argv[2]):
|
||||
print('export {}={}'.format(k, repr(v)))
|
||||
elif mode == 'vars':
|
||||
print(' '.join('$' + k for k, v in parse_env(sys.argv[2])))
|
||||
elif mode == 'strip':
|
||||
t = sys.stdin.read()
|
||||
t = re.sub(r'[ \t]*env_file:[ \t]*\n([ \t]+-[^\n]*\n)+', '', t)
|
||||
sys.stdout.write(t)
|
||||
Reference in New Issue
Block a user