Skip to content

Commit

Permalink
Merge pull request Backblaze#983 from reef-technologies/fix_mkdir_fai…
Browse files Browse the repository at this point in the history
…l_under_docker

Fix mkdir fail under docker
  • Loading branch information
mjurbanski-reef authored Jan 11, 2024
2 parents 610cdc2 + 750e1da commit 418561d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ LABEL build-date-iso8601="${build_date}"

WORKDIR /root

# due https://github.com/moby/moby/issues/47021 we cannot have /root/.cache leftover as it causes random errors in CI
RUN --mount=type=bind,source=${tar_path}/${tar_name},target=/tmp/${tar_name} \
pip install --no-cache-dir /tmp/${tar_name}[full]
pip install --no-cache-dir /tmp/${tar_name}[full] && rm -rf /root/.cache

ENTRYPOINT ["b2"]
CMD ["--help"]
21 changes: 10 additions & 11 deletions b2/_internal/_cli/autocomplete_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ def current_state_identifier(self) -> str:
class HomeCachePickleStore(PickleStore):
_dir: pathlib.Path

def __init__(self, dir: pathlib.Path | None = None) -> None:
self._dir = dir
def __init__(self, dir_path: pathlib.Path | None = None) -> None:
self._dir = dir_path

def _cache_dir(self) -> pathlib.Path:
if self._dir:
return self._dir
self._dir = pathlib.Path(
platformdirs.user_cache_dir(appname='b2', appauthor='backblaze')
) / 'autocomplete'
if not self._dir:
self._dir = pathlib.Path(
platformdirs.user_cache_dir(appname='b2', appauthor='backblaze')
) / 'autocomplete'
return self._dir

def _fname(self, identifier: str) -> str:
Expand All @@ -74,10 +73,10 @@ def set_pickle(self, identifier: str, data: bytes) -> None:
"""Sets the pickle for identifier if it doesn't exist.
When a new pickle is added, old ones are removed."""

dir = self._cache_dir()
os.makedirs(dir, exist_ok=True)
path = dir / self._fname(identifier)
for file in dir.glob('b2-autocomplete-cache-*.pickle'):
dir_path = self._cache_dir()
dir_path.mkdir(parents=True, exist_ok=True)
path = dir_path / self._fname(identifier)
for file in dir_path.glob('b2-autocomplete-cache-*.pickle'):
file.unlink()
with open(path, 'wb') as f:
f.write(data)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+docker_mkdir_fail.infrastructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix CI failing on `mkdir` when testing docker image.
8 changes: 3 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,11 @@ def generate_dockerfile(session):

def run_docker_tests(session, image_tag):
"""Run unittests against a docker image."""
docker_run_cmd = "docker run -i -v b2:/root/ -v /tmp:/tmp:rw --env-file ENVFILE"
run_integration_test(
session, [
"--sut",
"docker run -i -v b2:/root -v /tmp:/tmp:rw "
f"--env-file ENVFILE {image_tag}",
f"{docker_run_cmd} {image_tag}",
"--env-file-cmd-placeholder",
"ENVFILE",
]
Expand All @@ -622,9 +622,7 @@ def run_docker_tests(session, image_tag):
run_integration_test(
session, [
"--sut",
"docker run -i -v b2:/root -v /tmp:/tmp:rw "
f"--entrypoint {binary_name} "
f"--env-file ENVFILE {image_tag}",
f"{docker_run_cmd} --entrypoint {binary_name} {image_tag}",
"--env-file-cmd-placeholder",
"ENVFILE",
]
Expand Down

0 comments on commit 418561d

Please sign in to comment.