9090
9191{% if build_script_files -%}
9292# If scripts required during build are present, copy them
93- {% for src, dst in build_script_files.items() %}
93+ {% for src, dst in build_script_files|dictsort %}
9494COPY {{ src }} {{ dst }}
9595{% endfor -%}
9696{% endif -%}
125125# of the repository but don't access any files in the repository. By executing
126126# them before copying the repository itself we can cache these steps. For
127127# example installing APT packages.
128- {% for sd in pre_assemble_script_directives -%}
128+ {% if preassemble_script_files -%}
129+ # If scripts required during build are present, copy them
130+ {% for src, dst in preassemble_script_files|dictsort %}
131+ COPY src/{{ src }} ${REPO_DIR}/{{ dst }}
132+ {% endfor -%}
133+ {% endif -%}
134+
135+ {% for sd in preassemble_script_directives -%}
129136{{ sd }}
130137{% endfor %}
131138
144151# Container image Labels!
145152# Put these at the end, since we don't want to rebuild everything
146153# when these change! Did I mention I hate Dockerfile cache semantics?
147- {% for k, v in labels.items() %}
154+ {% for k, v in labels|dictsort %}
148155LABEL {{k}}="{{v}}"
149156{%- endfor %}
150157
@@ -379,6 +386,19 @@ def get_build_scripts(self):
379386
380387 return []
381388
389+ def get_preassemble_script_files (self ):
390+ """
391+ Dict of files to be copied to the container image for use in preassembly.
392+
393+ This is copied before the `build_scripts`, `preassemble_scripts` and
394+ `assemble_scripts` are run, so can be executed from either of them.
395+
396+ It's a dictionary where the key is the source file path in the
397+ repository and the value is the destination file path inside the
398+ repository in the container.
399+ """
400+ return {}
401+
382402 def get_preassemble_scripts (self ):
383403 """
384404 Ordered list of shell snippets to build an image for this repository.
@@ -499,13 +519,13 @@ def render(self):
499519 "RUN {}" .format (textwrap .dedent (script .strip ("\n " )))
500520 )
501521
502- pre_assemble_script_directives = []
522+ preassemble_script_directives = []
503523 last_user = "root"
504524 for user , script in self .get_preassemble_scripts ():
505525 if last_user != user :
506- pre_assemble_script_directives .append ("USER {}" .format (user ))
526+ preassemble_script_directives .append ("USER {}" .format (user ))
507527 last_user = user
508- pre_assemble_script_directives .append (
528+ preassemble_script_directives .append (
509529 "RUN {}" .format (textwrap .dedent (script .strip ("\n " )))
510530 )
511531
@@ -516,7 +536,8 @@ def render(self):
516536 env = self .get_env (),
517537 labels = self .get_labels (),
518538 build_script_directives = build_script_directives ,
519- pre_assemble_script_directives = pre_assemble_script_directives ,
539+ preassemble_script_files = self .get_preassemble_script_files (),
540+ preassemble_script_directives = preassemble_script_directives ,
520541 assemble_script_directives = assemble_script_directives ,
521542 build_script_files = self .get_build_script_files (),
522543 base_packages = sorted (self .get_base_packages ()),
0 commit comments