Skip to content

Commit 5efb826

Browse files
author
Gunther Klessinger
committed
1 parent 9b0bf95 commit 5efb826

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

justfile

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ port-forward:
5454

5555

5656
install-flux:
57+
just p flux prepare_repo 'gh:/fluxcd/flux2-kustomize-helm-example'
5758
just p flux install
5859

5960

src/pyhk3/cli.py

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def create_partial(funcs, args, argv, x):
6565
l = l[-1]
6666
kw, varg = {}, ()
6767
for _, p in sig(l[-1]).parameters.items():
68+
if not args:
69+
break
6870
if int(p.kind) == 1: # positional_or_keyword
6971
varg += (args.pop(0),)
7072
elif int(p.kind) == 2: # vararg

src/pyhk3/flux.py

+34
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,39 @@ def install():
5555
add_to_pass(s, priv)
5656

5757

58+
def clone(url, into):
59+
sh.rm('-rf', into)
60+
sh.git.clone(url, into)
61+
log.info('Cloned', url=url, into=into)
62+
63+
64+
def prepare_repo(tmpl_url, into_repo=None):
65+
"""Prepare the repository for flux."""
66+
sh.mkdir('-p', './tmp')
67+
if not into_repo:
68+
into_repo = f'git@{E("GITOPS_HOST")}:{E("GITOPS_OWNER")}/{E("GITOPS_REPO")}'
69+
di = './tmp/into.git'
70+
clone(into_repo, di)
71+
72+
if tmpl_url.startswith('gh:'):
73+
tmpl_url = f'https://github.com{tmpl_url[3:]}'
74+
d_src = './tmp/tmpl.git'
75+
clone(tmpl_url, d_src)
76+
77+
for r in ['README.md', 'LICENSE', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', '.git']:
78+
sh.rm('-rf', d_src + '/' + r)
79+
80+
tar_command = sh.tar('cf', '-', '.', _cwd=d_src, _piped=True)
81+
sh.tar('xf', '-', '-C', di, _in=tar_command)
82+
log.info('copied', src=d_src, into=di)
83+
84+
with sh.pushd(d_src):
85+
breakpoint() # FIXME BREAKPOINT
86+
sh.git('add', '.')
87+
sh.git('commit', '-am', f'flux: initial commit\n\n{tmpl_url}\n->\n{into_repo}')
88+
sh.git('push')
89+
90+
5891
class flux:
92+
prepare_repo = prepare_repo
5993
install = install

0 commit comments

Comments
 (0)