github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/starlib/rules/container.star (about) 1 #load("rule.star", "actions", "attr", "rule") 2 load("rule.star", "ContainerInfo", "DefaultInfo", "attr", "attrs", "rule") 3 4 def _container_pull_impl(ctx): 5 print("pulling", ctx) 6 file = ctx.actions.container.pull( 7 name = ctx.attrs.name, 8 reference = ctx.attrs.reference, 9 ) 10 print("RETURNING", file) 11 return [ 12 DefaultInfo(files = [file]), 13 ContainerInfo(src = file, reference = ctx.attrs.reference), 14 ] 15 16 container_pull = rule( 17 impl = _container_pull_impl, 18 attrs = attrs( 19 reference = attr.string(mandatory = True), 20 ), 21 provides = [DefaultInfo, ContainerInfo], 22 ) 23 24 def _container_impl(ctx): 25 base = None 26 if ctx.attrs.base: 27 base = ctx.attrs.base[ContainerInfo] 28 29 tar = ctx.attrs.tar[DefaultInfo].files 30 31 file = ctx.actions.container.build( 32 name = ctx.attrs.name, 33 base = base, 34 entrypoint = ctx.attrs.entrypoint, 35 prioritized_files = ctx.attrs.prioritized_files, 36 tar = tar, 37 ) 38 return [ 39 DefaultInfo(files = [file]), 40 ContainerInfo(src = file, reference = ctx.attrs.reference), 41 ] 42 43 container_build = rule( 44 impl = _container_impl, 45 attrs = attrs( 46 base = attr.label(), # TODO: provider image 47 entrypoint = attr.string_list(), 48 prioritized_files = attr.string_list(), 49 tar = attr.label(mandatory = True), 50 reference = attr.string(mandatory = True), 51 ), 52 provides = [DefaultInfo, ContainerInfo], 53 ) 54 55 def _container_push_impl(ctx): 56 file = ctx.actions.container.push( 57 name = ctx.attrs.name, 58 image = ctx.attrs.image, 59 reference = ctx.attrs.reference, 60 ) 61 return [ 62 DefaultInfo(files = [file]), 63 ContainerInfo(src = file, reference = ctx.attrs.reference), 64 ] 65 66 container_push = rule( 67 impl = _container_push_impl, 68 attrs = attrs( 69 image = attr.label(mandatory = True), # TODO: providers... 70 reference = attr.string(), 71 ), 72 provides = [DefaultInfo, ContainerInfo], 73 )