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

chore: add --pull and --platform to run #647

Merged
merged 5 commits into from
Jun 26, 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
4 changes: 4 additions & 0 deletions client/gefyra/api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def run(
namespace: str = "",
env: Optional[List] = None,
env_from: str = "",
pull: str = "missing",
platform: str = "linux/amd64",
) -> bool:
from kubernetes.client import ApiException
from docker.errors import APIError
Expand Down Expand Up @@ -116,6 +118,8 @@ def run(
dns_search=dns_search,
auto_remove=auto_remove,
volumes=volumes,
pull=pull,
platform=platform,
)
except APIError as e:
if e.status_code == 409:
Expand Down
18 changes: 18 additions & 0 deletions client/gefyra/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
@click.option(
"-i", "--image", help="The docker image to run in Gefyra", type=str, required=True
)
@click.option(
"--pull",
type=click.Choice(["always", "missing"], case_sensitive=False),
help="Define whether image should always be pulled",
required=False,
default="missing",
)
@click.option(
"--platform",
type=str,
help="Define platform for image pull. Default: linux/amd64",
required=False,
default="linux/amd64",
)
@click.option(
"--connection-name", type=str, callback=check_connection_name, required=False
)
Expand All @@ -94,6 +108,8 @@ def run(
command,
name,
image,
pull,
platform,
connection_name,
):
from gefyra import api
Expand All @@ -111,5 +127,7 @@ def run(
auto_remove=auto_remove,
volumes=volume,
detach=detach,
pull=pull,
platform=platform,
connection_name=connection_name,
)
12 changes: 12 additions & 0 deletions client/gefyra/local/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from docker.models.containers import Container

from gefyra.cli import console
from gefyra.configuration import ClientConfiguration
from gefyra.local.cargo import get_cargo_ip_from_netaddress
from gefyra.types import GefyraLocalContainer
Expand Down Expand Up @@ -140,9 +141,20 @@ def deploy_app_container(
env: Optional[Dict] = None,
auto_remove: bool = False,
dns_search: Optional[List[str]] = None,
pull: Optional[str] = "missing",
platform: Optional[str] = "linux/amd64",
) -> Container:
import docker

if pull == "always":
console.info(f"Pulling image {image}...")
if ":" in image:
repo, tag = image.split(":")
else:
repo, tag = image, "latest"
config.DOCKER.images.pull(repository=repo, tag=tag, platform=platform)
console.info(f"Pulling image {image} done.")

if not dns_search:
dns_search = ["default"]

Expand Down
38 changes: 36 additions & 2 deletions client/tests/e2e/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ def test_h_run_gefyra_unbridge_with_name(self):
["unbridge", "mypyserver-to-default.deploy.hello-nginxdemo"],
catch_exceptions=False,
)
print(res.output)
self.assertEqual(res.exit_code, 0)
pod_container_dict = get_pods_and_containers_for_workload(
default_configuration, "hello-nginxdemo", "default", "deployment"
Expand Down Expand Up @@ -980,7 +979,6 @@ def test_r_reconnect(self):
["connections", "connect", "-n", CONNECTION_NAME],
catch_exceptions=False,
)
print(res.output)
self.assertEqual(res.exit_code, 0)
self.assert_cargo_running()

Expand Down Expand Up @@ -1029,6 +1027,42 @@ def test_s_run_via_cli(self):
self.assert_namespace_not_found("gefyra")
self.assert_cargo_not_running()

def test_s_run_via_cli_with_pull(self):
res = self.gefyra_up()
self.assertTrue(res)
self.assert_cargo_running()
self.assert_gefyra_connected()
runner = CliRunner()
res = runner.invoke(
cli,
[
"run",
"--image",
"quay.io/gefyra/pyserver",
"--name",
"mypyserver",
"--namespace",
"default",
"--expose",
"8000:8000",
"--detach",
"--rm",
"--command",
"python3 local.py",
"--connection-name",
CONNECTION_NAME,
"--pull",
"always",
],
catch_exceptions=False,
)
self.assertEqual(res.exit_code, 0)
self.assertIn("Pulling image", res.output)
self.assert_http_service_available("localhost", 8000)
self.gefyra_down()
self.assert_namespace_not_found("gefyra")
self.assert_cargo_not_running()

def test_s_run_via_cli_without_connection_name(self):
res = self.gefyra_up()
self.assertTrue(res)
Expand Down
Loading