7
7
8
8
from jinja2 import Environment , FileSystemLoader
9
9
10
- SRCDIR = ' ../src'
11
- DISTDIR = ' ../_dist'
12
- ARTIFACT_PREFIX = ' kubestack-starter-'
10
+ SRCDIR = " ../src"
11
+ DISTDIR = " ../_dist"
12
+ ARTIFACT_PREFIX = " kubestack-starter-"
13
13
14
14
15
15
def replace_template (dist_path , file_name , context ):
16
16
jinja = Environment (loader = FileSystemLoader (dist_path ))
17
17
template = jinja .get_template (file_name )
18
18
data = template .render (context )
19
19
20
- with open (f' { dist_path } /{ file_name } ' , 'w' ) as f :
20
+ with open (f" { dist_path } /{ file_name } " , "w" ) as f :
21
21
f .write (data )
22
22
# always include newline at end of file
23
- f .write (' \n ' )
23
+ f .write (" \n " )
24
24
25
25
26
26
def 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"
31
31
32
32
# Clean DISTDIR
33
33
if isdir (configuration_dist ):
@@ -38,46 +38,47 @@ def dist(version, image_name, configuration):
38
38
copytree (manifests_src , manifests_dist )
39
39
40
40
# 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 })
45
43
46
44
# Replace templated variables in Dockerfiles
47
- dockerfiles = [' Dockerfile' , ' Dockerfile.loc' ]
45
+ dockerfiles = [" Dockerfile" , " Dockerfile.loc" ]
48
46
for dockerfile in dockerfiles :
49
47
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
+ )
53
53
54
54
55
55
def 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 )
59
59
60
60
61
61
if __name__ == "__main__" :
62
62
# Use tag as version, fallback to commit sha
63
- version = environ .get (' GIT_SHA' )
63
+ version = environ .get (" GIT_SHA" )
64
64
# Non tagged images go to a different image repository
65
- image_name = 'kubestack/framework- dev'
65
+ image_name = "ghcr.io/kbst/terraform-kubestack/ dev"
66
66
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/" , "" )
70
70
# Tagged releases go to main image repository
71
- image_name = ' kubestack/framework'
71
+ image_name = " kubestack/framework"
72
72
73
73
try :
74
74
target = argv [1 ]
75
75
except IndexError :
76
76
print ("positional arg: 'target' missing:" )
77
77
exit ("usage dist.py [dist | compress]" )
78
78
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
+ ]
81
82
82
83
if target not in ["dist" , "compress" ]:
83
84
exit ("usage dist.py [dist | compress]" )
0 commit comments