@@ -239,6 +239,21 @@ def init(
239
239
type = click .Path (exists = True , dir_okay = False , path_type = Path ),
240
240
help = "Path to a direnv file (.env) containing environment variables to inject into the container." ,
241
241
)
242
+ @click .option (
243
+ "--output" ,
244
+ "-o" ,
245
+ type = click .Path (path_type = Path ),
246
+ help = "Where to write the result Dockerfile. Default is Dockerfile in the root of the workflow directory." ,
247
+ )
248
+ @click .option (
249
+ "--config-path" ,
250
+ type = click .Path (path_type = Path ),
251
+ help = (
252
+ "Where to read the config to use for generating the Dockerfile. If a config is not found either at"
253
+ " `config_path` or `config_path / .latch / config`, one will be generated at "
254
+ "`config_path / .latch / config`. If not provided, it will default to the parent of the output Dockerfile"
255
+ ),
256
+ )
242
257
def dockerfile (
243
258
pkg_root : Path ,
244
259
snakemake : bool = False ,
@@ -250,8 +265,10 @@ def dockerfile(
250
265
pyproject : Optional [Path ] = None ,
251
266
pip_requirements : Optional [Path ] = None ,
252
267
direnv : Optional [Path ] = None ,
268
+ output : Optional [Path ] = None ,
269
+ config_path : Optional [Path ] = None ,
253
270
):
254
- """Generates a user editable dockerfile for a workflow and saves under `pkg_root/Dockerfile` .
271
+ """Generates a user editable dockerfile for a workflow.
255
272
256
273
Visit docs.latch.bio to learn more.
257
274
"""
@@ -275,10 +292,32 @@ def dockerfile(
275
292
workflow_type = WorkflowType .nextflow
276
293
base_image = BaseImageOptions .nextflow
277
294
278
- config = get_or_create_workflow_config (
279
- pkg_root = pkg_root , base_image_type = base_image
295
+ if output is None :
296
+ output = pkg_root / "Dockerfile"
297
+ if output .name != "Dockerfile" :
298
+ output /= "Dockerfile"
299
+
300
+ ignore_path = output .with_name (".dockerignore" )
301
+
302
+ if config_path is None :
303
+ config_path = output .parent / ".latch" / "config"
304
+ if config_path .name != "config" :
305
+ config_path /= ".latch/config"
306
+
307
+ click .secho (
308
+ dedent (f"""\
309
+ The following files will be generated:
310
+ { click .style ("Dockerfile:" , fg = "bright_blue" )} { output }
311
+ { click .style ("Ignore File:" , fg = "bright_blue" )} { ignore_path }
312
+ { click .style ("Latch Config:" , fg = "bright_blue" )} { config_path }
313
+ """ )
280
314
)
281
315
316
+ output .parent .mkdir (exist_ok = True , parents = True )
317
+
318
+ # todo(ayush): make overwriting this easier
319
+ config = get_or_create_workflow_config (config_path , base_image_type = base_image )
320
+
282
321
builder = DockerfileBuilder (
283
322
pkg_root ,
284
323
wf_type = workflow_type ,
@@ -290,12 +329,9 @@ def dockerfile(
290
329
pip_requirements = pip_requirements ,
291
330
direnv = direnv ,
292
331
)
293
- builder .generate (overwrite = force )
332
+ builder .generate (dest = output , overwrite = force )
294
333
295
- if not click .confirm ("Generate a .dockerignore?" ):
296
- return
297
-
298
- generate_dockerignore (pkg_root , wf_type = workflow_type , overwrite = force )
334
+ generate_dockerignore (ignore_path , wf_type = workflow_type , overwrite = force )
299
335
300
336
301
337
@main .command ("generate-metadata" )
@@ -1086,8 +1122,8 @@ def version(pkg_root: Path):
1086
1122
help = "Set execution profile for Nextflow workflow" ,
1087
1123
)
1088
1124
@click .option (
1089
- "--destination " ,
1090
- "-d " ,
1125
+ "--output " ,
1126
+ "-o " ,
1091
1127
type = click .Path (path_type = Path ),
1092
1128
default = None ,
1093
1129
help = (
@@ -1101,7 +1137,7 @@ def generate_entrypoint(
1101
1137
metadata_root : Optional [Path ],
1102
1138
nf_script : Path ,
1103
1139
execution_profile : Optional [str ],
1104
- destination : Optional [Path ],
1140
+ output : Optional [Path ],
1105
1141
yes : bool ,
1106
1142
):
1107
1143
"""Generate a `wf/entrypoint.py` file from a Nextflow workflow"""
@@ -1110,23 +1146,23 @@ def generate_entrypoint(
1110
1146
from latch_cli .nextflow .workflow import generate_nextflow_workflow
1111
1147
from latch_cli .services .register .utils import import_module_by_path
1112
1148
1113
- if destination is None :
1114
- destination = pkg_root / "wf" / "custom_entrypoint.py"
1149
+ if output is None :
1150
+ output = pkg_root / "wf" / "custom_entrypoint.py"
1115
1151
1116
- destination = destination .with_suffix (".py" )
1152
+ output = output .with_suffix (".py" )
1117
1153
1118
1154
if not yes and not click .confirm (
1119
- f"Will generate an entrypoint at { destination } . Proceed?"
1155
+ f"Will generate an entrypoint at { output } . Proceed?"
1120
1156
):
1121
1157
raise click .exceptions .Abort
1122
1158
1123
- destination .parent .mkdir (exist_ok = True )
1159
+ output .parent .mkdir (exist_ok = True )
1124
1160
1125
1161
if (
1126
1162
not yes
1127
- and destination .exists ()
1163
+ and output .exists ()
1128
1164
and not click .confirm (
1129
- f"Nextflow entrypoint already exists at `{ destination } `. Overwrite?"
1165
+ f"Nextflow entrypoint already exists at `{ output } `. Overwrite?"
1130
1166
)
1131
1167
):
1132
1168
return
@@ -1151,11 +1187,7 @@ def generate_entrypoint(
1151
1187
raise click .exceptions .Exit (1 )
1152
1188
1153
1189
generate_nextflow_workflow (
1154
- pkg_root ,
1155
- metadata_root ,
1156
- nf_script ,
1157
- destination ,
1158
- execution_profile = execution_profile ,
1190
+ pkg_root , metadata_root , nf_script , output , execution_profile = execution_profile
1159
1191
)
1160
1192
1161
1193
0 commit comments