Tool to generate the config from the templates.
This commit is contained in:
parent
91ea826060
commit
b74ffebeb2
4 changed files with 69 additions and 4 deletions
|
|
@ -36,13 +36,13 @@ test_openshift_config:
|
|||
- cd ./app-config/openshift
|
||||
- oc login openshift-dev.cern.ch --token="${OPENSHIFT_CONFIG_CHECKER_TOKEN_TEST_CARA}"
|
||||
- python ./fetch-config.py test-cara --output-directory ./test-cara/actual
|
||||
# - python ./build_config.py test-cara
|
||||
- python ./generate-config.py test-cara --output-directory ./test-cara/expected
|
||||
|
||||
# - pytest ./test_config.py --arg test-cara
|
||||
artifacts:
|
||||
paths:
|
||||
- ./app-config/openshift/test-cara/actual
|
||||
# - ./app-config/openshift/test-cara/expected
|
||||
- ./app-config/openshift/test-cara/expected
|
||||
|
||||
|
||||
# A development installation of CARA tested with pytest.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ def configure_parser(parser: argparse.ArgumentParser) -> None:
|
|||
parser.set_defaults(handler=handler)
|
||||
parser.add_argument(
|
||||
"instance", choices=['cara', 'test-cara'],
|
||||
help="Pick the instance for which you want to generated the config",
|
||||
help="Pick the instance for which you want to fetch the config",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-directory", default='config',
|
||||
|
|
@ -39,7 +39,7 @@ def fetch_config(output_directory: pathlib.Path):
|
|||
with (output_directory / f'{component}.json').open('wt') as fh:
|
||||
cmd = ['oc', 'get', '--export', '-o', 'json', component]
|
||||
print(f'Running: {" ".join(cmd)}')
|
||||
subprocess.run(['oc', 'get', '--export', '-o', 'json', component], stdout=fh, check=True)
|
||||
subprocess.run(cmd, stdout=fh, check=True)
|
||||
print(f'Config in: {output_directory.absolute()}')
|
||||
|
||||
|
||||
|
|
|
|||
65
app-config/openshift/generate-config.py
Normal file
65
app-config/openshift/generate-config.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import typing
|
||||
|
||||
|
||||
def configure_parser(parser: argparse.ArgumentParser) -> None:
|
||||
parser.description = "Generate the config files which can be later submitted to openshift"
|
||||
parser.set_defaults(handler=handler)
|
||||
parser.add_argument(
|
||||
"instance", choices=['cara', 'test-cara'],
|
||||
help="Pick the instance for which you want to generate the config",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-directory", default='config',
|
||||
help="Location to put the config files",
|
||||
)
|
||||
|
||||
|
||||
def generate_config(output_directory: pathlib.Path, project_name: str, hostname: str, branch: str):
|
||||
output_directory.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
def oc_process(component_name: str, context: typing.Optional[dict] = None):
|
||||
cmd = ['oc', 'process', '--local', '-f', f'{component_name}.yaml']
|
||||
for ctx_name, ctx_value in (context or {}).items():
|
||||
cmd.extend(['--param', f'{ctx_name}={ctx_value}'])
|
||||
with (output_directory / f'{component_name}.json').open('wt') as fh:
|
||||
print(f'Running: {" ".join(cmd)}')
|
||||
subprocess.run(cmd, stdout=fh, check=True)
|
||||
|
||||
# oc_process('route', oc_process + ['route.yaml', '--param', f'HOST={hostname}'])
|
||||
oc_process('routes', context={'HOST': hostname})
|
||||
oc_process('configmap')
|
||||
oc_process('services')
|
||||
oc_process('imagestreams')
|
||||
oc_process('buildconfig', context={'GIT_BRANCH': branch})
|
||||
oc_process('deploymentconfig', context={'PROJECT_NAME': project_name})
|
||||
|
||||
print(f'Config in: {output_directory.absolute()}')
|
||||
|
||||
|
||||
def handler(args: argparse.ArgumentParser) -> None:
|
||||
if args.instance == 'cara':
|
||||
project_name = 'cara'
|
||||
branch = 'master'
|
||||
hostname = 'cara.web.cern.ch'
|
||||
elif args.instance == 'test-cara':
|
||||
branch = 'live/test-cara'
|
||||
project_name = 'test-cara'
|
||||
hostname = 'test-cara.web.cern.ch'
|
||||
|
||||
generate_config(pathlib.Path(args.output_directory), project_name, hostname, branch)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
configure_parser(parser)
|
||||
args = parser.parse_args()
|
||||
args.handler(args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Loading…
Reference in a new issue