Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 5b94a72

Browse files
committed
Defaulting image_tag to "latest".
Removed old unused test. Fixed missing pytest-mock package.
1 parent 705bd20 commit 5b94a72

5 files changed

Lines changed: 11 additions & 33 deletions

File tree

gcip/addons/container/jobs/crane.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def pull(
124124
*,
125125
src_registry: Union[Registry, str],
126126
image_name: str,
127+
image_tag: str = "latest",
127128
tar_path: Optional[str] = None,
128-
image_tag: Optional[str] = None,
129129
docker_client_config: Optional[DockerClientConfig] = None,
130130
crane_image: Optional[Union[Image, str]] = None,
131131
) -> Job:
@@ -135,9 +135,7 @@ def pull(
135135
Args:
136136
src_registry (str): Registry URL to pull container image from.
137137
image_name (str): Container image with namespace to pull from `src_registry`.
138-
If `None` it defaults internally to `PredefinedVariables.CI_PROJECT_NAME`.
139-
image_tag (str): Tag of the image which will be pulled. If `None` it defaults internally to `PredefinedVariables.CI_COMMIT_TAG`
140-
or `PredefinedVariables.CI_COMMIT_REF_SLUG` in order.
138+
image_tag (str): Tag of the image which will be pulled. Defaults to "latest".
141139
tar_path (Optional[str], optional): Path where to save the container image tarball.
142140
If `None` it defaults internally to `PredefinedVariables.CI_PROJECT_DIR`. Defaults to None.
143141
docker_client_config (Optional[DockerClientConfig], optional): Creates the Docker configuration file base on objects settings,
@@ -162,12 +160,6 @@ def pull(
162160
docker_client_config = DockerClientConfig()
163161
docker_client_config.add_auth(registry=Registry.DOCKER)
164162

165-
if not image_tag:
166-
if PredefinedVariables.CI_COMMIT_TAG:
167-
image_tag = PredefinedVariables.CI_COMMIT_TAG
168-
else:
169-
image_tag = PredefinedVariables.CI_COMMIT_REF_SLUG
170-
171163
job = Job(
172164
script=[
173165
f"crane pull {src_registry}/{image_name}:{image_tag} {tar_path}/{image_path}.tar",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ isort
33
flake8
44
pytest
55
pytest-cov
6+
pytest-mock
67
mypy
78
black
89
boto3~=1.17

tests/unit/comparison_files/test_addons_container_crane_test_crane_simple_pull.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ pull:
1010
- mkdir -p $HOME/.docker
1111
- 'echo "{\"auths\": {\"https://index.docker.io/v1/\": {\"username\": \"$REGISTRY_USERNAME\",
1212
\"password\": \"$REGISTRY_PASSWORD\"}}}" > $HOME/.docker/config.json'
13-
- crane pull gcr.io/gitlab-ci-project:11.22.33 /path/to/project/gitlab-ci-project.tar
13+
- crane pull gcr.io/awsome/image:latest /path/to/project/awsome_image.tar

tests/unit/comparison_files/test_addons_container_crane_test_crane_simple_pull_with_ref.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/unit/test_addons_container_crane.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,20 @@ def test_addons_container_jobs_crane_push_registry(gitlab_ci_environment_variabl
8383

8484
def test_crane_simple_pull(gitlab_ci_environment_variables):
8585
pipeline = Pipeline()
86-
pipeline.add_children(crane.pull(Registry.GCR))
87-
conftest.check(pipeline.render())
88-
89-
90-
def test_crane_simple_pull_with_ref(monkeypatch, gitlab_ci_environment_variables):
91-
monkeypatch.delenv("CI_COMMIT_TAG")
92-
pipeline = Pipeline()
93-
pipeline.add_children(crane.pull(Registry.GCR))
86+
pipeline.add_children(
87+
crane.pull(
88+
src_registry=Registry.GCR,
89+
image_name="awsome/image",
90+
)
91+
)
9492
conftest.check(pipeline.render())
9593

9694

9795
def test_crane_advanced_pull(gitlab_ci_environment_variables, docker_client_config):
9896
pipeline = Pipeline()
9997
pipeline.add_children(
10098
crane.pull(
101-
Registry.GCR,
99+
src_registry=Registry.GCR,
102100
docker_client_config=docker_client_config,
103101
image_name="thomass/gcip",
104102
image_tag="main",

0 commit comments

Comments
 (0)