
import argparse
import os, subprocess
import json
from pprint import pprint


## Parse command line args
parser = argparse.ArgumentParser()
parser.add_argument('--stage', '-s', type=str, default=None)
args = parser.parse_args()


## assert stage argument is set
assert args.stage is not None, '--stage argument expected'


## Load config
local_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(f"{local_dir}/../../config/")
process = subprocess.run(
    ['make','print', f'stage={args.stage}'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)
if process.stderr:
    raise RuntimeError(f'In config/bin/generate.py:\n\n{process.stderr.decode()}')
if process.stdout.decode()[:4] == 'make':
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')[1:-1]))
else:
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')))


## Init docker image
process = subprocess.run(
    [   'sudo', 'docker', 'rm',
        f"{config['project']['domain']}-postgres-{args.stage}"
    ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)
if process.stderr:
    raise RuntimeError(
        f'Error starting docker in start_image.py:\n\n{process.stderr.decode()}'
    )

92236290e45c627a77ef7c0a4bcc4a9c92e08537
<mask token>

<mask token>
parser.add_argument('--stage', '-s', type=str, default=None)
<mask token>
assert args.stage is not None, '--stage argument expected'
<mask token>
os.chdir(f'{local_dir}/../../config/')
<mask token>
if process.stderr:
    raise RuntimeError(
        f'In config/bin/generate.py:\n\n{process.stderr.decode()}')
if process.stdout.decode()[:4] == 'make':
    config = json.loads('\n'.join(process.stdout.decode().strip().split(
        '\n')[1:-1]))
else:
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')))
<mask token>
if process.stderr:
    raise RuntimeError(
        f'Error starting docker in start_image.py:\n\n{process.stderr.decode()}'
        )

<mask token>
parser = argparse.ArgumentParser()
parser.add_argument('--stage', '-s', type=str, default=None)
args = parser.parse_args()
assert args.stage is not None, '--stage argument expected'
local_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(f'{local_dir}/../../config/')
process = subprocess.run(['make', 'print', f'stage={args.stage}'], stdout=
    subprocess.PIPE, stderr=subprocess.PIPE)
if process.stderr:
    raise RuntimeError(
        f'In config/bin/generate.py:\n\n{process.stderr.decode()}')
if process.stdout.decode()[:4] == 'make':
    config = json.loads('\n'.join(process.stdout.decode().strip().split(
        '\n')[1:-1]))
else:
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')))
process = subprocess.run(['sudo', 'docker', 'rm',
    f"{config['project']['domain']}-postgres-{args.stage}"], stdout=
    subprocess.PIPE, stderr=subprocess.PIPE)
if process.stderr:
    raise RuntimeError(
        f'Error starting docker in start_image.py:\n\n{process.stderr.decode()}'
        )

import argparse
import os, subprocess
import json
from pprint import pprint
parser = argparse.ArgumentParser()
parser.add_argument('--stage', '-s', type=str, default=None)
args = parser.parse_args()
assert args.stage is not None, '--stage argument expected'
local_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(f'{local_dir}/../../config/')
process = subprocess.run(['make', 'print', f'stage={args.stage}'], stdout=
    subprocess.PIPE, stderr=subprocess.PIPE)
if process.stderr:
    raise RuntimeError(
        f'In config/bin/generate.py:\n\n{process.stderr.decode()}')
if process.stdout.decode()[:4] == 'make':
    config = json.loads('\n'.join(process.stdout.decode().strip().split(
        '\n')[1:-1]))
else:
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')))
process = subprocess.run(['sudo', 'docker', 'rm',
    f"{config['project']['domain']}-postgres-{args.stage}"], stdout=
    subprocess.PIPE, stderr=subprocess.PIPE)
if process.stderr:
    raise RuntimeError(
        f'Error starting docker in start_image.py:\n\n{process.stderr.decode()}'
        )


import argparse
import os, subprocess
import json
from pprint import pprint


## Parse command line args
parser = argparse.ArgumentParser()
parser.add_argument('--stage', '-s', type=str, default=None)
args = parser.parse_args()


## assert stage argument is set
assert args.stage is not None, '--stage argument expected'


## Load config
local_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(f"{local_dir}/../../config/")
process = subprocess.run(
    ['make','print', f'stage={args.stage}'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)
if process.stderr:
    raise RuntimeError(f'In config/bin/generate.py:\n\n{process.stderr.decode()}')
if process.stdout.decode()[:4] == 'make':
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')[1:-1]))
else:
    config = json.loads('\n'.join(process.stdout.decode().strip().split('\n')))


## Init docker image
process = subprocess.run(
    [   'sudo', 'docker', 'rm',
        f"{config['project']['domain']}-postgres-{args.stage}"
    ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)
if process.stderr:
    raise RuntimeError(
        f'Error starting docker in start_image.py:\n\n{process.stderr.decode()}'
    )
