33import string
44
55import click
6+ from galaxy .tool_util .deps .mulled .mulled_build import (
7+ base_image_for_targets ,
8+ DEFAULT_BASE_IMAGE ,
9+ )
610from galaxy .tool_util .deps .mulled .util import (
711 conda_build_target_str ,
812 quay_repository ,
2327REGISTERY_TARGET_NAME = "multi-package-containers"
2428REGISTERY_TARGET_PATH = "combinations"
2529REGISTERY_REPOSITORY = "BioContainers/multi-package-containers"
26- DEFAULT_MESSAGE = "Add container $hash.\n **Hash**: $hash\n \n **Packages**:\n $packages\n \n **For** :\n $tools\n \n Generated with Planemo."
30+ DEFAULT_MESSAGE = "Add container $hash.\n **Hash**: $hash\n \n **Packages**:\n $packages\n Base Image:$base_image\n \n "
31+ DEFAULT_MESSAGE += "**For** :\n $tools\n \n Generated with Planemo."
32+ CONTENTS = "#targets\t base_image\t image_build\n $targets\t $base_image\t $image_build\n "
33+ BIOCONTAINERS_PLATFORM = 'linux-64'
2734
2835
2936@click .command ('container_register' )
@@ -80,7 +87,7 @@ def cli(ctx, paths, **kwds):
8087 mulled_targets_str = "- " + "\n - " .join (map (conda_build_target_str , mulled_targets ))
8188 best_practice_requirements = True
8289 for conda_target in conda_targets :
83- best_hit , exact = best_practice_search (conda_target , conda_context = conda_context )
90+ best_hit , exact = best_practice_search (conda_target , conda_context = conda_context , platform = BIOCONTAINERS_PLATFORM )
8491 if not best_hit :
8592 ctx .log ("Target [%s] is not available in best practice channels - skipping" % conda_target )
8693 best_practice_requirements = False
@@ -92,6 +99,13 @@ def cli(ctx, paths, **kwds):
9299 if not best_practice_requirements :
93100 continue
94101
102+ base_image = DEFAULT_BASE_IMAGE
103+ for conda_target in conda_targets :
104+ base_image = base_image_for_targets ([conda_target ], conda_context = conda_context )
105+ if base_image != DEFAULT_BASE_IMAGE :
106+ ctx .log ("%s requires '%s' as base image" % (conda_target , base_image ))
107+ break
108+
95109 if len (mulled_targets ) < 1 :
96110 ctx .log ("Skipping registration, no targets discovered." )
97111 continue
@@ -114,14 +128,14 @@ def cli(ctx, paths, **kwds):
114128 ctx .vlog ("Found matching open pull request for [%s], skipping" % name )
115129 continue
116130
117- registry_target .write_targets (ctx , target_filename , mulled_targets )
131+ registry_target .write_targets (ctx , target_filename , mulled_targets , tag , base_image )
118132 tools_str = "\n " .join (map (lambda p : "- " + os .path .basename (p ), tool_paths ))
119- registry_target .handle_pull_request (ctx , name , target_filename , mulled_targets_str , tools_str , ** kwds )
133+ registry_target .handle_pull_request (ctx , name , target_filename , mulled_targets_str , tools_str , base_image , ** kwds )
120134 combinations_added += 1
121135
122136
123137class RegistryTarget (object ):
124- """Abstraction around mulled container registery (both directory and Github repo)."""
138+ """Abstraction around mulled container registry (both directory and Github repo)."""
125139
126140 def __init__ (self , ctx , ** kwds ):
127141 output_directory = kwds ["output_directory" ]
@@ -152,13 +166,14 @@ def has_pull_request_for(self, name):
152166
153167 return has_pr
154168
155- def handle_pull_request (self , ctx , name , target_filename , packages_str , tools_str , ** kwds ):
169+ def handle_pull_request (self , ctx , name , target_filename , packages_str , tools_str , base_image , ** kwds ):
156170 if self .do_pull_request :
157171 message = kwds ["message" ]
158172 message = string .Template (message ).safe_substitute ({
159173 "hash" : name ,
160174 "packages" : packages_str ,
161175 "tools" : tools_str ,
176+ "base_image" : base_image ,
162177 })
163178 branch_name = name .replace (":" , "-" )
164179 branch (ctx , self .target_repository , branch_name , from_branch = "master" )
@@ -168,11 +183,16 @@ def handle_pull_request(self, ctx, name, target_filename, packages_str, tools_st
168183 push (ctx , self .target_repository , os .environ .get ("GITHUB_USER" ), branch_name , force = force_push )
169184 pull_request (ctx , self .target_repository , message = message )
170185
171- def write_targets (self , ctx , target_filename , mulled_targets ):
186+ def write_targets (self , ctx , target_filename , mulled_targets , tag , base_image ):
172187 with open (target_filename , "w" ) as f :
173- contents = to_target_str (mulled_targets )
174- f .write ("%s\n " % contents )
175- ctx .log ("Wrote requirements [%s] to file [%s]" % (contents , target_filename ))
188+ targets = to_target_str (mulled_targets )
189+ f .write (string .Template (CONTENTS ).safe_substitute (
190+ targets = targets ,
191+ base_image = base_image ,
192+ image_build = tag
193+ )
194+ )
195+ ctx .log ("Wrote requirements [%s] to file [%s]" % (targets , target_filename ))
176196
177197
178198def to_target_str (targets ):
0 commit comments