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

Update multiple base images #34461

Merged
merged 9 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 21 additions & 19 deletions utils/auto_dockerfile_update/get_dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_docker_files(base_path="docker/", devonly=False, external=False, interna
internal (bool):whether or not to get dockerfiles with internal base images

Returns:
list of relevant files: [{'name','path,'content','base_image}]
list of relevant files: [{'name','path','content','base_image'}]
"""
dockerfiles_paths = glob(f"{base_path}/**/Dockerfile", recursive=True)
files_list = []
Expand All @@ -148,27 +148,29 @@ def get_docker_files(base_path="docker/", devonly=False, external=False, interna

with open(path) as f:
docker_file_content = f.read()
base_image = re.search(BASE_IMAGE_REGEX, docker_file_content)
base_images_in_docker_file = re.findall(BASE_IMAGE_REGEX, docker_file_content)

if not base_image:
if not base_images_in_docker_file:
# The dockerfile doesn't contain base image
print(f"Couldn't find base images for docker file {path.split('/')[-2]}")
continue

base_image = base_image.group(0)
base_image = base_image.replace("FROM ", "")
is_internal = re.search(INTERNAL_BASE_IMAGES, base_image)
if (is_internal and internal) or (not is_internal and external):
repo, image_name, tag = parse_base_image(base_image)
last_modified = get_last_modified(docker_file_content)
curr_dockerfile = {"path": path,
"repo": repo,
"image_name": image_name,
"tag": tag,
"last_modified": last_modified,
"content": docker_file_content,
"name": dockerfile_dir_path.split('/')[1],
}

files_list.append(curr_dockerfile)
print(f"Found base images for docker file {path.split('/')[-2]}: {base_images_in_docker_file}")
for base_image in base_images_in_docker_file:
base_image = base_image.replace("FROM ", "")
is_internal = re.search(INTERNAL_BASE_IMAGES, base_image)
if (is_internal and internal) or (not is_internal and external):
repo, image_name, tag = parse_base_image(base_image)
last_modified = get_last_modified(docker_file_content)
curr_dockerfile = {
"path": path,
"repo": repo,
"image_name": image_name,
"tag": tag,
"last_modified": last_modified,
"content": docker_file_content,
"name": dockerfile_dir_path.split('/')[1],
}
files_list.append(curr_dockerfile)

return filter_ignored_files(files_list)
27 changes: 27 additions & 0 deletions utils/auto_dockerfile_update/tests/get_dockerfiles_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from utils.auto_dockerfile_update.get_dockerfiles import get_docker_files


def test_get_docker_files_multiple_from_internal():
"""
Given
- Docker file with multiple FROM statements
When
- running get_docker_files
Then
- Verify length of output list is as expected
"""
files_list = get_docker_files(base_path="utils/auto_dockerfile_update/tests/test_data/", internal=True)
assert len(files_list) == 2


def test_get_docker_files_multiple_from_external():
"""
Given
- Docker file with multiple FROM statements
When
- running get_docker_files
Then
- Verify length of output list is as expected
"""
files_list = get_docker_files(base_path="utils/auto_dockerfile_update/tests/test_data/", external=True)
assert len(files_list) == 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:3.17.10 as files-src
COPY weights /yolo-coco

FROM demisto/opencv:1.0.0.114711

COPY requirements.txt .
COPY yolo-coco /yolo-coco/.
COPY --from=files-src /yolo-coco/yolov3.weights /yolo-coco/.

FROM demisto/python3:3.11.10.115186
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=1.0.0
Loading