Skip to content
Merged
Changes from all commits
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
15 changes: 13 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def upload_source_code(cmd, client,
def _pack_source_code(source_location, tar_file_path, docker_file_path, docker_file_in_tar):
logger.warning("Packing source code into tar to upload...")

ignore_list, ignore_list_size = _load_dockerignore_file(source_location)
original_docker_file_name = os.path.basename(docker_file_path.replace("\\", os.sep))
ignore_list, ignore_list_size = _load_dockerignore_file(source_location, original_docker_file_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is ignore_list_size used? do you think its redundant to return that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shahzzzam, thanks for your comment. It looks like it's used in:

https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py#L107

I am not sure if it would be appropriate to refactor that, but I personally see that as out of scope for this PR. Please let me know if you have suggestions in that sense.

common_vcs_ignore_list = {'.git', '.gitignore', '.bzr', 'bzrignore', '.hg', '.hgignore', '.svn'}

def _ignore_check(tarinfo, parent_ignored, parent_matching_rule_index):
Expand Down Expand Up @@ -144,9 +145,17 @@ def __init__(self, rule):
self.pattern += "$"


def _load_dockerignore_file(source_location):
def _load_dockerignore_file(source_location, original_docker_file_name):
# reference: https://docs.docker.com/engine/reference/builder/#dockerignore-file
docker_ignore_file = os.path.join(source_location, ".dockerignore")
docker_ignore_file_override = None
if original_docker_file_name != "Dockerfile":
docker_ignore_file_override = os.path.join(
source_location, "{}.dockerignore".format(original_docker_file_name))
if os.path.exists(docker_ignore_file_override):
logger.warning("Overriding .dockerignore with %s", docker_ignore_file_override)
docker_ignore_file = docker_ignore_file_override

if not os.path.exists(docker_ignore_file):
return None, 0

Expand All @@ -156,6 +165,8 @@ def _load_dockerignore_file(source_location):
encoding = "utf-8-sig"

ignore_list = []
if docker_ignore_file == docker_ignore_file_override:
ignore_list.append(IgnoreRule(".dockerignore"))

for line in open(docker_ignore_file, 'r', encoding=encoding).readlines():
rule = line.rstrip()
Expand Down