Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: use --build-arg to invalidate cache #244

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions dockerfiles/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import hashlib

from invoke import task

Expand All @@ -14,8 +15,32 @@
})
def build(c, cache=False):
"""Build docker image for servers."""
cache_opt = '' if cache else '--no-cache'
c.run(f'{DOCKER_COMPOSE_COMMAND} build {cache_opt}', pty=True)
cache_opt = '--no-cache'
cache_hash = ""
build_arg = ""
if cache:
cache_opt = ""
files_to_cache = [
# Community
"requirements/docker.txt",

# Corporate
"../readthedocs.org/requirements/docker.txt",
"setup.cfg",

# Both
"../ext-theme/setup.cfg",
"../readthedocs-ext/setup.cfg",
]

for f in files_to_cache:
if os.path.exists(f):
cache_hash += hashlib.md5(open(f, mode="rb").read()).hexdigest()
humitos marked this conversation as resolved.
Show resolved Hide resolved

if cache_hash:
build_arg = f"--build-arg PRUNE_PACKAGE_CACHE={cache_hash}"
humitos marked this conversation as resolved.
Show resolved Hide resolved

c.run(f'{DOCKER_COMPOSE_COMMAND} build {cache_opt} {build_arg}', echo=True, pty=True)

@task(help={
'command': 'Command to pass directly to "docker compose"',
Expand Down