MCPcopy Create free account
hub / github.com/ForgeRock/forgeops / configure_platform_images

Function configure_platform_images

lib/python/utils.py:368–421  ·  view source on GitHub ↗

Clone platform images and checkout branch to the given path. Raise exception if not succesful.

(clone_path,
                              ref='',
                              repo='https://github.com/ping-rocks/platform-images.git')

Source from the content-addressed store, hash-verified

366 _runwithtimeout(_install_certmanager_issuer, [], 180)
367
368def configure_platform_images(clone_path,
369 ref='',
370 repo='https://github.com/ping-rocks/platform-images.git'):
371 """
372 Clone platform images and checkout branch to the given path.
373 Raise exception if not succesful.
374 """
375 log = logger()
376 path = pathlib.Path(clone_path)
377
378 def grun(*args, **kwargs):
379 run('git', '-C', str(path), *args, cstdout=True, cstderr=True)
380
381 git_dir = path.joinpath('.git')
382 # handle existing config directory
383 if git_dir.is_dir() and ref != '':
384 log.info('Found existing files, attempting to not clone.')
385 try:
386 # capture stdout and stderr so git doesn't write to log
387 run('git', '-C', str(path), 'checkout',
388 ref, cstdout=True, cstderr=True)
389 return
390 except:
391 log.error('Couldn\'t find reference. Getting fresh clone.')
392 shutil.rmtree(str(path))
393 elif git_dir.is_dir():
394 log.info('Using existing repo, remove it to get a fresh clone.')
395 return
396 # some path that's not a git repo so don't do anything.
397 elif any(path.glob('*')) and not git_dir.is_dir():
398 raise Exception('Found existing directory that is not a git repo.')
399 try:
400 if ref != '':
401 # initialize repo
402 run('git', 'init', str(path), cstdout=True, cstderr=True)
403 # add remote
404 grun('remote', 'add', 'origin', repo)
405 grun('config', '--add', 'remote.origin.fetch',
406 # TODO GitHub migration: once migration to GitHub is done we can inline if block (i.e. consider as always true)
407 '+refs/pull/*/head:refs/pr/*' if 'github' in repo.lower() else
408 '+refs/pull-requests/*/from:refs/remotes/origin/pr/*')
409 # checkout
410 grun('fetch', 'origin')
411 grun('checkout', ref)
412 else:
413 # shallow setup
414 run('git', 'clone', '--depth', '1', repo,
415 str(path), cstdout=True, cstderr=True)
416 except RunError as e:
417 log.error(f'Couldn\'t configure repo running {e.cmd} {e.output}.')
418 raise e
419 except Exception as e:
420 log.error(f'Couldn\t configure repo {e}.')
421 raise e
422
423def sort_dir_json(base):
424 """

Callers

nothing calls this directly

Calls 3

loggerFunction · 0.85
grunFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected