77
88from jinja2 import Environment , FileSystemLoader
99
10- SRCDIR = ' ../src'
11- DISTDIR = ' ../_dist'
12- ARTIFACT_PREFIX = ' kubestack-starter-'
10+ SRCDIR = " ../src"
11+ DISTDIR = " ../_dist"
12+ ARTIFACT_PREFIX = " kubestack-starter-"
1313
1414
1515def replace_template (dist_path , file_name , context ):
1616 jinja = Environment (loader = FileSystemLoader (dist_path ))
1717 template = jinja .get_template (file_name )
1818 data = template .render (context )
1919
20- with open (f' { dist_path } /{ file_name } ' , 'w' ) as f :
20+ with open (f" { dist_path } /{ file_name } " , "w" ) as f :
2121 f .write (data )
2222 # always include newline at end of file
23- f .write (' \n ' )
23+ f .write (" \n " )
2424
2525
2626def dist (version , image_name , configuration ):
27- configuration_src = f' { SRCDIR } /configurations/{ configuration } '
28- configuration_dist = f' { DISTDIR } /{ ARTIFACT_PREFIX } { configuration } '
29- manifests_src = f' { SRCDIR } /manifests'
30- manifests_dist = f' { configuration_dist } /manifests'
27+ configuration_src = f" { SRCDIR } /configurations/{ configuration } "
28+ configuration_dist = f" { DISTDIR } /{ ARTIFACT_PREFIX } { configuration } "
29+ manifests_src = f" { SRCDIR } /manifests"
30+ manifests_dist = f" { configuration_dist } /manifests"
3131
3232 # Clean DISTDIR
3333 if isdir (configuration_dist ):
@@ -38,46 +38,47 @@ def dist(version, image_name, configuration):
3838 copytree (manifests_src , manifests_dist )
3939
4040 # Replace templated version variables in *.tf files
41- for tf_file in [n for n in listdir (configuration_dist )
42- if n .endswith ('.tf' )]:
43- replace_template (configuration_dist , tf_file ,
44- {'version' : version })
41+ for tf_file in [n for n in listdir (configuration_dist ) if n .endswith (".tf" )]:
42+ replace_template (configuration_dist , tf_file , {"version" : version })
4543
4644 # Replace templated variables in Dockerfiles
47- dockerfiles = [' Dockerfile' , ' Dockerfile.loc' ]
45+ dockerfiles = [" Dockerfile" , " Dockerfile.loc" ]
4846 for dockerfile in dockerfiles :
4947 if exists (join (configuration_dist , dockerfile )):
50- replace_template (configuration_dist ,
51- dockerfile ,
52- {'image_name' : image_name , 'image_tag' : version })
48+ replace_template (
49+ configuration_dist ,
50+ dockerfile ,
51+ {"image_name" : image_name , "image_tag" : version },
52+ )
5353
5454
5555def compress (version , configuration ):
56- starter = f' { ARTIFACT_PREFIX } { configuration } '
57- archive = f' { DISTDIR } /{ starter } -{ version } '
58- make_archive (archive , ' zip' , DISTDIR , starter )
56+ starter = f" { ARTIFACT_PREFIX } { configuration } "
57+ archive = f" { DISTDIR } /{ starter } -{ version } "
58+ make_archive (archive , " zip" , DISTDIR , starter )
5959
6060
6161if __name__ == "__main__" :
6262 # Use tag as version, fallback to commit sha
63- version = environ .get (' GIT_SHA' )
63+ version = environ .get (" GIT_SHA" )
6464 # Non tagged images go to a different image repository
65- image_name = 'kubestack/framework- dev'
65+ image_name = "ghcr.io/kbst/terraform-kubestack/ dev"
6666
67- gitref = environ .get (' GIT_REF' )
68- if gitref .startswith (' refs/tags/' ):
69- version = gitref .replace (' refs/tags/' , '' )
67+ gitref = environ .get (" GIT_REF" )
68+ if gitref .startswith (" refs/tags/" ):
69+ version = gitref .replace (" refs/tags/" , "" )
7070 # Tagged releases go to main image repository
71- image_name = ' kubestack/framework'
71+ image_name = " kubestack/framework"
7272
7373 try :
7474 target = argv [1 ]
7575 except IndexError :
7676 print ("positional arg: 'target' missing:" )
7777 exit ("usage dist.py [dist | compress]" )
7878
79- configurations = [n for n in listdir (f'{ SRCDIR } /configurations' )
80- if not n .startswith ('_' )]
79+ configurations = [
80+ n for n in listdir (f"{ SRCDIR } /configurations" ) if not n .startswith ("_" )
81+ ]
8182
8283 if target not in ["dist" , "compress" ]:
8384 exit ("usage dist.py [dist | compress]" )
0 commit comments