diff --git a/dev_scripts/env.py b/dev_scripts/env.py index f75cc5016..8f21ddacd 100755 --- a/dev_scripts/env.py +++ b/dev_scripts/env.py @@ -317,15 +317,28 @@ def get_current_date(): return date.today().strftime("%Y-%m-%d") +def get_build_dir_sources(distro, version): + """Return the files needed to build an image.""" + sources = [ + git_root() / "pyproject.toml", + git_root() / "poetry.lock", + git_root() / "dev_scripts" / "storage.conf", + git_root() / "dev_scripts" / "containers.conf", + ] + + if distro == "ubuntu" and version in ("22.04", "jammy"): + sources.extend( + [ + git_root() / "dev_scripts" / "apt-tools-prod.pref", + git_root() / "dev_scripts" / "apt-tools-prod.sources", + ] + ) + return sources + + def image_name_build_dev(distro, version): """Get the container image for the dev variant of a Dangerzone environment.""" - hash = hash_files( - get_files_in("dev_scripts") - + [ - git_root() / "pyproject.toml", - git_root() / "poetry.lock", - ] - ) + hash = hash_files(get_build_dir_sources(distro, version)) return IMAGE_NAME_BUILD_DEV_FMT.format( distro=distro, version=version, hash=hash, date=get_current_date() @@ -695,15 +708,9 @@ def build_dev(self, show_dockerfile=DEFAULT_SHOW_DOCKERFILE, sync=False): os.makedirs(build_dir, exist_ok=True) # Populate the build context. - shutil.copy(git_root() / "pyproject.toml", build_dir) - shutil.copy(git_root() / "poetry.lock", build_dir) - shutil.copy(git_root() / "dev_scripts" / "storage.conf", build_dir) - shutil.copy(git_root() / "dev_scripts" / "containers.conf", build_dir) - if self.distro == "ubuntu" and self.version in ("22.04", "jammy"): - shutil.copy(git_root() / "dev_scripts" / "apt-tools-prod.pref", build_dir) - shutil.copy( - git_root() / "dev_scripts" / "apt-tools-prod.sources", build_dir - ) + for source in get_build_dir_sources(self.distro, self.version): + shutil.copy(source, build_dir) + with open(build_dir / "Dockerfile", mode="w") as f: f.write(dockerfile)