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

Adapt Docker Proxy #3975

Merged
merged 20 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/3975.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added support for DOCKER_REGISTRY_URL environment variable.
type: internal
pr_number: 3975
1 change: 1 addition & 0 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"CI_PROJECT_ID", "1061"
) # Default value is the ID of the content repo on GitLab
ENV_SDK_WORKING_OFFLINE = "DEMISTO_SDK_OFFLINE_ENV"
DOCKER_REGISTRY_URL = os.getenv("DOCKER_IO", "docker-io.art.code.pan.run")
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to docker.io

michal-dagan marked this conversation as resolved.
Show resolved Hide resolved


# Authentication
Expand Down
16 changes: 9 additions & 7 deletions demisto_sdk/commands/common/docker_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from demisto_sdk.commands.common.constants import (
DEFAULT_PYTHON2_VERSION,
DEFAULT_PYTHON_VERSION,
DOCKER_REGISTRY_URL,
DOCKERFILES_INFO_REPO,
TYPE_PWSH,
TYPE_PYTHON,
Expand Down Expand Up @@ -53,6 +54,8 @@ class DockerException(Exception):

def init_global_docker_client(timeout: int = 60, log_prompt: str = ""):
global DOCKER_CLIENT
registry = os.getenv("DOCKER_IO_DOMAIN", "https://index.docker.io/v1")
michal-dagan marked this conversation as resolved.
Show resolved Hide resolved

michal-dagan marked this conversation as resolved.
Show resolved Hide resolved
if DOCKER_CLIENT is None:
if log_prompt:
logger.debug(f"{log_prompt} - init and login the docker client")
Expand Down Expand Up @@ -95,6 +98,7 @@ def docker_login(docker_client) -> bool:
Returns:
bool: True if logged in successfully.
"""

michal-dagan marked this conversation as resolved.
Show resolved Hide resolved
docker_user = os.getenv("DOCKERHUB_USER")
docker_pass = os.getenv("DOCKERHUB_PASSWORD")
if docker_user and docker_pass:
Expand Down Expand Up @@ -253,9 +257,7 @@ def push_image(self, image: str, log_prompt: str = ""):
for _ in range(2):
try:

test_image_name_to_push = image.replace(
"docker-io.art.code.pan.run/", ""
)
test_image_name_to_push = image.replace(f"{DOCKER_REGISTRY_URL}/", "")
docker_push_output = init_global_docker_client().images.push(
test_image_name_to_push
)
Expand Down Expand Up @@ -319,7 +321,7 @@ def create_image(
)
if os.getenv("CONTENT_GITLAB_CI"):
container.commit(
repository=repository.replace("docker-io.art.code.pan.run/", ""),
repository=repository.replace(f"{DOCKER_REGISTRY_URL}/", ""),
tag=tag,
changes=self.changes[container_type],
)
Expand All @@ -329,8 +331,8 @@ def create_image(

@staticmethod
def get_image_registry(image: str) -> str:
if os.getenv("CONTENT_GITLAB_CI") and "code.pan.run" not in image:
return f"docker-io.art.code.pan.run/{image}"
if os.getenv("CONTENT_GITLAB_CI") and DOCKER_REGISTRY_URL not in image:
return f"{DOCKER_REGISTRY_URL}/{image}"
return image

def get_or_create_test_image(
Expand Down Expand Up @@ -638,7 +640,7 @@ def _get_python_version_from_dockerhub_api(image: str) -> Version:
repo, tag = image.split(":")
if os.getenv("CONTENT_GITLAB_CI"):
# we need to remove the gitlab prefix, as we query the API
repo = repo.replace("docker-io.art.code.pan.run/", "")
repo = repo.replace(f"{DOCKER_REGISTRY_URL}/", "")
try:
token = _get_docker_hub_token(repo)
digest = _get_image_digest(repo, tag, token)
Expand Down
5 changes: 3 additions & 2 deletions demisto_sdk/commands/lint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from demisto_sdk.commands.common.constants import (
API_MODULE_FILE_SUFFIX,
DOCKER_REGISTRY_URL,
FORMATTING_SCRIPT,
INTEGRATIONS_DIR,
NATIVE_IMAGE_FILE_NAME,
Expand Down Expand Up @@ -365,10 +366,10 @@ def _gather_facts(self, modules: dict) -> bool:
return True
self._facts["images"] = [[image, -1] for image in images]

# we want to use the docker-io.art.code.pan.run only if we run in content build (and not CI/CD for example)
# we want to use DOCKER_REGISTRY_URL only if we run in content build (and not CI/CD for example)
if os.getenv("CONTENT_GITLAB_CI", False):
self._facts["images"] = [
[f"docker-io.art.code.pan.run/{image[0]}", -1]
[f"{DOCKER_REGISTRY_URL}/{image[0]}", -1]
for image in self._facts["images"]
]
# Gather environment variables for docker execution
Expand Down